binder-nix-flakes/nix-introduction.ipynb

247 lines
12 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Welcome to a quick Nix Introduction!\n",
"\n",
"This is an overview of the nix commands for now. Maybe this will grow into a bigger example.\n",
"\n",
"First notice that the packages that we built are included in the environment.\n",
" - python 3.6 is installed with `numpy`, `scipy`, and `jupyterlab` (along with all dependencies)\n",
" \n",
"Lets quickly inspect what we have"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy\n",
"import scipy\n",
"import jupyterlab"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3.6.6 (default, Jun 27 2018, 05:47:41) \n",
"[GCC 7.3.0]\n"
]
}
],
"source": [
"import sys\n",
"print(sys.version)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['',\n",
" '/nix/store/3aqb8gxmjy4bd98zh01as7nrcyszf3c2-python3.6-numpy-1.15.1/lib/python3.6/site-packages',\n",
" '/nix/store/hy65mn4wjswqih75gfr6g4q3xgqdm325-python3-3.6.6/lib/python3.6/site-packages',\n",
" '/nix/store/2a8lm8w8ihlhnwid4xq6amvi755dbyz7-python3.6-setuptools-40.2.0/lib/python3.6/site-packages',\n",
" '/nix/store/w3424y8ggxky8wjy8axqi024gf7ivbi2-python3.6-scipy-1.1.0/lib/python3.6/site-packages',\n",
" '/nix/store/irnrpx2lkzajhhbwki2rwqvbzmh75as1-python3.6-jupyterlab-0.34.6/lib/python3.6/site-packages',\n",
" '/nix/store/bwi2i35g11a049832g0zzsqhqz45y7xm-python3.6-ipython_genutils-0.2.0/lib/python3.6/site-packages',\n",
" '/nix/store/21lxdak14zn4z4p8pxb4nrsivxfc1xvv-python3.6-jupyterlab_launcher-0.13.1/lib/python3.6/site-packages',\n",
" '/nix/store/vgsbzajx3wdallz9hb0yywzsc3ypypaq-python3.6-jsonschema-2.6.0/lib/python3.6/site-packages',\n",
" '/nix/store/94vqszxlf8basd5s3ni8wf5bq3h8p6x4-python3.6-notebook-5.6.0/lib/python3.6/site-packages',\n",
" '/nix/store/f7vh7y804vqlahfsq1f0f9afdrcbdyq3-python3.6-Jinja2-2.10/lib/python3.6/site-packages',\n",
" '/nix/store/qv1d6n1lwiv7skfz89cnz1xkfk5x8j2q-python3.6-markupsafe-1.0/lib/python3.6/site-packages',\n",
" '/nix/store/j8yd57mbs9fis0dacl5yjwypgvpyv9z4-python3.6-tornado-5.1/lib/python3.6/site-packages',\n",
" '/nix/store/ca86qlq73gbrb9hb3nphxph6cqmrzwac-python3.6-backports_abc-0.5/lib/python3.6/site-packages',\n",
" '/nix/store/qhla67d2vh6xmpksy4lb43rr00qkh5yg-python3.6-certifi-2018.8.24/lib/python3.6/site-packages',\n",
" '/nix/store/q7v4yvj8gzh06mlgap8ca27daldwg3pc-python3.6-singledispatch-3.4.0.3/lib/python3.6/site-packages',\n",
" '/nix/store/xh9mfh0rhd7wi8by6hn57d14qlyqnpph-python3.6-six-1.11.0/lib/python3.6/site-packages',\n",
" '/nix/store/zna268428fij3yrg1vi6l3d1ivl7wqgb-python3.6-traitlets-4.3.2/lib/python3.6/site-packages',\n",
" '/nix/store/i36bzblisbis3pfkn00s1msr809ryhv0-python3.6-decorator-4.3.0/lib/python3.6/site-packages',\n",
" '/nix/store/38cfzhxpvk97kahaz525s8wf87a46cfi-python3.6-jupyter_core-4.4.0/lib/python3.6/site-packages',\n",
" '/nix/store/j8f2cj0axqhvjgm39qpr3calibdc9fzn-python3.6-ipython-6.5.0/lib/python3.6/site-packages',\n",
" '/nix/store/5jwwcflsjpl1zwwxzzvv42x3vh5pyq0l-python3.6-jedi-0.12.1/lib/python3.6/site-packages',\n",
" '/nix/store/0dnaxfngc1za833za1jgsbz70m97b8zq-python3.6-parso-0.3.1/lib/python3.6/site-packages',\n",
" '/nix/store/bj6yhk4zhi2h0qnac3fdznz2k6bpcdjs-python3.6-pickleshare-0.7.4/lib/python3.6/site-packages',\n",
" '/nix/store/kzn4zbw5vk6xqcvyjjsrkz62jlkw6gni-python3.6-path.py-11.0.1/lib/python3.6/site-packages',\n",
" '/nix/store/dw3d7q66b6j27hayv4dxggg0vicbh9gs-python3.6-simplegeneric-0.8.1/lib/python3.6/site-packages',\n",
" '/nix/store/zdn5w039qxalhrpgcqxms1ah7s1hlrgm-python3.6-prompt_toolkit-1.0.15/lib/python3.6/site-packages',\n",
" '/nix/store/w1bsp4r7ndcdjlw6qjj28h89srilpmpd-python3.6-docopt-0.6.2/lib/python3.6/site-packages',\n",
" '/nix/store/im7qrqspgl291dhx8885dismj3s4lx25-python3.6-wcwidth-0.1.7/lib/python3.6/site-packages',\n",
" '/nix/store/fxvb6bczjxnai4aakbfdi452h0y0i246-python3.6-Pygments-2.2.0/lib/python3.6/site-packages',\n",
" '/nix/store/pzvnw72cgd57jmrnr3wqc18g6kd23505-python3.6-docutils-0.14/lib/python3.6/site-packages',\n",
" '/nix/store/6zq887wbbk2zlqd7j0jpkfvap1lc90ln-python3.6-pexpect-4.6.0/lib/python3.6/site-packages',\n",
" '/nix/store/48iw34820bi03qxajqadbkcbffppi9bn-python3.6-ptyprocess-0.6.0/lib/python3.6/site-packages',\n",
" '/nix/store/rnywq4i7zjmr8kxjhkhs7jrbx5r6wrmd-python3.6-backcall-0.1.0/lib/python3.6/site-packages',\n",
" '/nix/store/mjgi2rjn6npw2w4wrkm5l5gzqb2cz8j9-python3.6-Send2Trash-1.4.2/lib/python3.6/site-packages',\n",
" '/nix/store/mldl2xklwa03zc4ppi8ms2p72gyac0r8-python3.6-jupyter_client-5.2.3/lib/python3.6/site-packages',\n",
" '/nix/store/5kk1n0b1sdxqzs56y6galig2p1yvq8nz-python3.6-pyzmq-17.1.2/lib/python3.6/site-packages',\n",
" '/nix/store/bccb8jmszflv9hnwiinqwrdb83bfmr4j-python3.6-py-1.5.4/lib/python3.6/site-packages',\n",
" '/nix/store/k9c78j8z4q20j27vjyjs411w1nla0809-python3.6-python-dateutil-2.7.3/lib/python3.6/site-packages',\n",
" '/nix/store/1sl7znqlhifw81i3da6w8whqgdrv2i8r-python3.6-setuptools_scm-3.1.0/lib/python3.6/site-packages',\n",
" '/nix/store/fqndazrpdiqcms7ivcqxy8gnmbw3xswx-python3.6-nbformat-4.4.0/lib/python3.6/site-packages',\n",
" '/nix/store/pq26z30kkyb8229l8an6l6asq1wi2h9m-python3.6-testpath-0.3/lib/python3.6/site-packages',\n",
" '/nix/store/qdivvcm3cqii4bwf609gdpkpas45iapf-python3.6-nbconvert-5.3.1/lib/python3.6/site-packages',\n",
" '/nix/store/rsdwsww06w728n1bz7cswpj1lvh85xb6-python3.6-entrypoints-0.2.3/lib/python3.6/site-packages',\n",
" '/nix/store/008fss5alrk8wp0f2p2pj1wsk3vcrwdw-python3.6-bleach-2.1.4/lib/python3.6/site-packages',\n",
" '/nix/store/3hqfvm2s3lmai5gw27lxpm02zi0m0xg1-python3.6-html5lib-1.0.1/lib/python3.6/site-packages',\n",
" '/nix/store/kh44p1x4z8cwwhav29csrdig0jskzndr-python3.6-webencodings-0.5.1/lib/python3.6/site-packages',\n",
" '/nix/store/3y6fkpzjfqcalq8z769i7l07cj4fj2cz-python3.6-mistune-0.8.3/lib/python3.6/site-packages',\n",
" '/nix/store/d70vr7s8v2ncj53mbp2v4w6nb5bk8zzz-python3.6-ipykernel-4.8.2/lib/python3.6/site-packages',\n",
" '/nix/store/vky6qk0p6bigzw0xfq6a2myp1dh3vbmh-python3.6-pandocfilters-1.4.1/lib/python3.6/site-packages',\n",
" '/nix/store/ajm635nxfwwag11pxjzgcibk2y4h42qc-python3.6-terminado-0.8.1/lib/python3.6/site-packages',\n",
" '/nix/store/wphh2s31x39mqhb7188zyjv7sp08l5xn-python3.6-urllib3-1.23/lib/python3.6/site-packages',\n",
" '/nix/store/sndz163kpv95n1rw8v11v2xw66vac8xq-python3.6-idna-2.7/lib/python3.6/site-packages',\n",
" '/nix/store/1dn5q7j2ascy368vwdr6q9b0kxzr216l-python3.6-asn1crypto-0.24.0/lib/python3.6/site-packages',\n",
" '/nix/store/4q1wccglx7l7vvhfdr46bfq1a3z9as1r-python3.6-packaging-17.1/lib/python3.6/site-packages',\n",
" '/nix/store/55lagsqjr0yjv491vc7ia3d64iwmfwi8-python3.6-pyparsing-2.2.0/lib/python3.6/site-packages',\n",
" '/nix/store/qq0058w2ydsa0a0gk984z5dk36jc1qjs-python3.6-pycparser-2.18/lib/python3.6/site-packages',\n",
" '/nix/store/x5v2d0mh41yxc146w4p34zf3ka4q0ddn-python3.6-cffi-1.11.5/lib/python3.6/site-packages',\n",
" '/nix/store/fjkrgww4vi05lz5vdpa3wwg4q08h1bmv-python3.6-cryptography-2.3.1/lib/python3.6/site-packages',\n",
" '/nix/store/0g4mvk847nq8r6gq83d90wm8lvvhhr3z-python3.6-pyasn1-0.4.4/lib/python3.6/site-packages',\n",
" '/nix/store/gzrgq8xlxsxnh18v2wm4aq2bh33063g7-python3.6-pyOpenSSL-18.0.0/lib/python3.6/site-packages',\n",
" '/nix/store/hx8njjmhccmh6ngazc4dq4fiqmqkqvn2-python3.6-pysocks-1.6.6/lib/python3.6/site-packages',\n",
" '/nix/store/w98icbhliwcisj6w3r8dragj2b2j5a4b-python3.6-chardet-3.0.4/lib/python3.6/site-packages',\n",
" '/nix/store/66614b4gc9cw1vdyly98ahqdf0aapgb8-python3.6-requests-2.19.1/lib/python3.6/site-packages',\n",
" '/nix/store/nsvi389pycl03hj7m5m6yvzn2b6vss1p-python3.6-prometheus_client-0.3.1/lib/python3.6/site-packages',\n",
" '/nix/store/2a8lm8w8ihlhnwid4xq6amvi755dbyz7-python3.6-setuptools-40.2.0/lib/python3.6/site-packages/setuptools-40.2.0-py3.6.egg',\n",
" '/nix/store/hy65mn4wjswqih75gfr6g4q3xgqdm325-python3-3.6.6/lib/python36.zip',\n",
" '/nix/store/hy65mn4wjswqih75gfr6g4q3xgqdm325-python3-3.6.6/lib/python3.6',\n",
" '/nix/store/hy65mn4wjswqih75gfr6g4q3xgqdm325-python3-3.6.6/lib/python3.6/lib-dynload',\n",
" '/nix/store/j8f2cj0axqhvjgm39qpr3calibdc9fzn-python3.6-ipython-6.5.0/lib/python3.6/site-packages/IPython/extensions',\n",
" '/home/costrouc/.ipython']"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# here we learn the magic that nix does\n",
"# all nix builds are isolated (including network) and only provided the recources they specify as dependencies\n",
"# all nix builds are put in a flat directory `/nix/store/*`\n",
"# by sacrificing POSIX compatibility we get many useful features\n",
"# here nix sets `PYTHONPATH` to all of our python dependencies.\n",
"sys.path"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Searching for nix packages\n",
"\n",
"Repology stats on nixpkgs https://repology.org/repositories/statistics/total\n",
"\n",
"Over 42,000 packages with 87% being the latest version.\n",
"\n",
"![nixpkgs image](https://repology.org/graph/map_repo_size_fresh.svg)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[K\u001b[31;1mwarning:\u001b[0m using cached results; pass '-u' to update the cache\u001b[0m\n",
"\u001b[K* \u001b[0;1mnixpkgs.\u001b[31;1mprometheus-s\u001b[0;1mnmp-exporter\u001b[0m (\u001b[0;2msnmp_exporter-0.13.0\u001b[0m)\n",
" SNMP Exporter for Prometheus\n",
"\n",
"* \u001b[0;1mnixpkgs.\u001b[31;1mprometheus-s\u001b[0;1mtatsd-bridge\u001b[0m (\u001b[0;2mstatsd_exporter-0.4.0\u001b[0m)\n",
" Receives StatsD-style metrics and exports them to Prometheus\n",
"\n",
"* \u001b[0;1mnixpkgs.\u001b[31;1mprometheus-s\u001b[0;1mtatsd-exporter\u001b[0m (\u001b[0;2mstatsd_exporter-0.4.0\u001b[0m)\n",
" Receives StatsD-style metrics and exports them to Prometheus\n",
"\n",
"* \u001b[0;1mnixpkgs.\u001b[31;1mprometheus-s\u001b[0;1murfboard-exporter\u001b[0m (\u001b[0;2msurfboard_exporter-2.0.0\u001b[0m)\n",
" Arris Surfboard signal metrics exporter\n",
"\n",
"\u001b[K"
]
}
],
"source": [
"! nix search prometheus-s"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Nix stores all packages in `/nix/store/*`"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"24G\t/nix/store\n"
]
}
],
"source": [
"# this is the size on my local machine before you run it\n",
"# building many versions of package takes up space!\n",
"! du -sh /nix/store"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# nix allows you to delete unused packages!\n",
"# no usefull in a docker container but when \n",
"# building many packages many times\n",
"# you end up with lots of unused builds\n",
"! nix-collect-garbage -d"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}