{"id":7060,"date":"2026-11-20T22:01:22","date_gmt":"2026-11-20T22:01:22","guid":{"rendered":"https:\/\/www.solutionstreet.com\/blog\/?p=7060"},"modified":"2026-11-20T22:01:25","modified_gmt":"2026-11-20T22:01:25","slug":"learning-nixos-and-its-nix-package-manager","status":"publish","type":"post","link":"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/","title":{"rendered":"Learning NixOS and Its Nix Package Manager"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"372\" src=\"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2026\/11\/Box-title2.png\" alt=\"\" class=\"wp-image-7092\" style=\"width:632px;height:auto\" srcset=\"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2026\/11\/Box-title2.png 700w, https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2026\/11\/Box-title2-300x159.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/figure>\n<\/div>\n\n\n<div class=\"wp-block-group has-cyan-bluish-gray-background-color has-background\" style=\"font-size:8px;background-image:var(--wp--preset--gradient--very-light-gray-to-cyan-bluish-gray);\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"has-text-align-center has-small-font-size wp-block-paragraph\">***Expect words in <strong><em>bold italics<\/em><\/strong> to be defined somewhere in this document. Defining all words before they were used proved to be too much work. So for some definitions, you just need to be patient.***<\/p>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019ve been daily driving <strong><em>NixOS<\/em><\/strong> for over half a year now. I\u2019m still just a beginner, but I\u2019m slowly learning enough to be dangerous. The more I use it, the more I\u2019m convinced that it\u2019s the \u201ccorrect\u201d way to run software.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It reminds me a lot of when I learned Git. My first impression of Git was that it was just a collection of arcane commands posing as an alternative to Subversion. But the more I used it, the more I became convinced that it was the \u201ccorrect\u201d way to version control source files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">My \u201caha\u201d moment for Git was when I realized how cheap branches and tags were, and how they allowed me to easily create checkpoints anytime I wanted. That meant that if I wanted to hack together an experimental feature just to see if it was possible \u2013 I could create a checkpoint and then get to work! If things didn\u2019t work out, I could throw away the changes (or even check them into a branch so I could come back to them later) and go back to where I started \u2013 instantly. In other words: <em>Git made running big experiments cheap and risk free<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">My \u201caha\u201d moment for <strong><em>NixOS<\/em><\/strong> was when I realized that I could put any piece of software on my system, including its <em>entire<\/em> dependency graph, without affecting any other piece of software that\u2019s already on my system. At the moment, I can confidently say that <strong><em>NixOS<\/em><\/strong> <em>makes running big experiments risk free<\/em>, but I still have a bit to learn before I can add the \u201c<em>cheap<\/em>\u201d qualifier. I have no doubt that <strong><em>NixOS<\/em><\/strong> is fully capable of making big experiments \u201c<em>cheap<\/em>\u201d; my current inability to make it do so is due only to my lack of knowledge.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019m still climbing the <strong><em>NixOS<\/em><\/strong> learning curve. To that end, I did a deep dive into <strong><em>NixOS<\/em><\/strong> this weekend, trying to get an idea of how it does what it does. My learnings follow.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Documentation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019ve read some things on the <a href=\"https:\/\/wiki.nixos.org\/wiki\/NixOS_Wiki\" target=\"blank\">NixOS Wiki<\/a> and I\u2019ve read quite a bit of the <a href=\"https:\/\/nixos.org\/guides\/nix-pills\/00-preface.html\" target=\"blank\">Nix Pills<\/a> (and followed along by running their examples).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Both are fine resources\u2026 but they always left me wanting. It always seemed that they were too precise about things I didn\u2019t care about and too imprecise about things I did care about.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Regardless, spend some time on the pills. I did \u2013 so any advice I give with respect to learning <strong><em>NixOS<\/em><\/strong> should be prefixed with \u201ctry doing the pills first.\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That being said, read the first three chapters of Eelco Dolstra\u2019s <a href=\"https:\/\/edolstra.github.io\/pubs\/phd-thesis.pdf\" target=\"blank\">PhD thesis<\/a>. Trust me.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What the Nix Package Manager Can Do<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong><em>Nix Package Manager<\/em><\/strong> is extraordinarily good at managing dependencies for software. When you install a Package on <strong><em>NixOS<\/em><\/strong>, you can be certain that the components that it depends on will never change as long as it remains installed on your system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong><em>Nix Package Manager<\/em><\/strong> will allow you to upgrade any component to a new version while leaving the current version untouched. If you don\u2019t like the new version, you can instantly roll back.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong><em>Nix Package Manager<\/em><\/strong> is also extraordinarily good at letting any component depend on any version of any other component. And by version, I don\u2019t mean in the sense of \u20181.0.1\u2019; I mean something far more granular. You can have one program use version \u20181.0.1\u2019 of a library that was compiled with optimizations turned on\u2026 and another program depend on version \u20181.0.1\u2019 of the same library compiled with optimizations turned off! Both \u20181.0.1\u2019 versions of the same library can exist on your machine, and either can be used to build any program that depends on them. Because building software is an interesting use case for me, this is the feature that I wanted to explore.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C Libs and Executables<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you\u2019ve been using Linux for a while, there\u2019s a good chance that you\u2019ve built some program and\/or library from C source code. Over the decades, the process of doing so has become remarkably similar across projects. Tools like <a href=\"https:\/\/www.gnu.org\/software\/autoconf\/\" target=\"blank\">Autoconf<\/a>, <a href=\"https:\/\/www.gnu.org\/software\/automake\/\" target=\"blank\">Automake<\/a>, and <a href=\"https:\/\/www.gnu.org\/software\/libtool\/\" target=\"blank\">Libtool<\/a> have helped make this possible.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you\u2019ve ever opened up a Makefile that ships with the C source for a program you\u2019ve built, you probably noticed that you can change the build process by specifying environment variables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">INCLUDES, LDFLAGS, and CFLAGS allow you to control compiler and linker flags. You can use these to specify build time options (where to look for header files; where to look for libraries). You can also use them for things like adding debug symbols or choosing the compiler optimization level \u2013 in which case, given the exact same source, the values passed to these environment variables can result in significantly different binaries.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">DESTDIR and PREFIX are two environment variables that let you determine where a given piece of software is installed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using these five variables, you can control where your project looks for its build-time dependencies and where it installs to. The <strong><em>Nix Package Manager<\/em><\/strong> can also use them to ensure that software is installed in the <strong><em>Nix Store<\/em><\/strong> and that it looks for its dependencies in the <strong><em>Nix Store<\/em><\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">My Experiment<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After months of using <strong><em>NixOS<\/em><\/strong> as my primary Linux distro, reading about <strong><em>NixOS<\/em><\/strong>, and asking Claude lots of questions\u2026 I had finally arrived at what I thought would be a useful experiment to learn a little about how <strong><em>NixOS<\/em><\/strong> works.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>I wanted to create a simple library whose build process could be influenced by an environment variable in a way that was easily witnessed by an end user.<\/li>\n\n\n\n<li>I wanted to create a simple program that linked against this library.<\/li>\n\n\n\n<li>I wanted the build processes of both of these projects to follow familiar conventions.<\/li>\n\n\n\n<li>I wanted to show that the <strong><em>Nix Package Manager<\/em><\/strong> could build both of these projects with no changes to their source code or build scripts (Makefiles).<\/li>\n\n\n\n<li>I wanted to show that the <strong><em>Nix Package Manager<\/em><\/strong> could capture the dependency of the program on the library\u2026 and furthermore that it would allow the program to specify bespoke configurations of the library build to depend upon.<\/li>\n\n\n\n<li>Finally, I wanted to show that multiple versions of program and library could exist on the system without conflict.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">The Code<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019ll include some code in this post (I tried to keep the examples small), but all of the code can also be found <a href=\"https:\/\/github.com\/emacdona\/nixdemo\" target=\"blank\">here<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">The Library<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">As mentioned above, I wanted to have a library whose behavior could be changed at build time (via an environment variable) in such a way that was easily witnessed by a user. In other words, I won\u2019t be modifying INCLUDES, LDFLAGS, or CFLAGS<sup data-fn=\"944a06d2-4cd1-4210-8c17-4b7b830fe93f\" class=\"fn\"><a href=\"#944a06d2-4cd1-4210-8c17-4b7b830fe93f\" id=\"944a06d2-4cd1-4210-8c17-4b7b830fe93f-link\">1<\/a><\/sup> \u2013 because such changes are not easily witnessed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Instead, my library will use a preprocessor macro to determine the string its single function returns:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"greeting.h\"<br><br>\/* GREETING_MESSAGE is defined at compile time via -D flag *\/<br>#ifndef GREETING_MESSAGE<br>#define GREETING_MESSAGE \"Hello, World!\"<br>#endif<br><br>const char* get_greeting(void) {<br>&nbsp; &nbsp; return GREETING_MESSAGE;<br>}<br><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The Makefile that builds my library will allow the value of this macro to be overridden via an environment variable \u2013 at <em>build<\/em> time:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># ... code removed, see repo for entire file ...<br><br>GREETING ?= Hello, World!<br><br>CFLAGS += -DGREETING_MESSAGE='\"$(GREETING)\"'<br><br># ... code removed, see repo for entire file ...<br><br>%.o: %.c greeting.h<br>$(CC) $(CFLAGS) -c $&lt; -o $@<br><br># ... code removed, see repo for entire file ...<br><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In other words, different values for the environment variable result in different binaries. The <strong><em>Nix Package Manager<\/em><\/strong> will allow all of these binaries to co-exist, and it will allow for downstream components to choose which binary their build depends on.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">The Program<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The program is even simpler. It just calls the function provided by the library:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h&gt;<br>#include &lt;greeting.h&gt;<br><br>int main(void) {<br>&nbsp; &nbsp; printf(\"%s\\n\", get_greeting());<br>&nbsp; &nbsp; return 0;<br>}<br><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Likewise, the Makefile that builds the program is simpler than the one that builds the library. In fact, there\u2019s nothing really worth pointing out within it. Feel free to look at it in the source repo.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Building and Installing without the Nix Package Manager<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The Makefiles for building the library and the program follow the conventions mentioned earlier. In particular, they install into a directory determined by the DESTDIR and PREFIX environment variables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I don\u2019t recommend it, but if you wanted, you could make &amp;&amp; make install the library and then the program\u2026 and it should work as expected. The reason I don\u2019t recommend this is because it would install both in the \/usr\/local directory tree. This is a blog post about <strong><em>NixOS<\/em><\/strong>\u2026 we want to have things installed in the <strong><em>Nix Store<\/em><\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">NixOS Terms and Definitions<sup data-fn=\"79ebbd15-2a70-4081-a13e-7c00f908af8f\" class=\"fn\"><a href=\"#79ebbd15-2a70-4081-a13e-7c00f908af8f\" id=\"79ebbd15-2a70-4081-a13e-7c00f908af8f-link\">2<\/a><\/sup><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that we have source code for a program and a library that it depends on, we can proceed to see how we can use the <strong><em>Nix Package Manager<\/em><\/strong> to build and install it. But before we do that, we\u2019ll need to define some terms.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These definitions reflect my current mental model of how <strong><em>NixOS<\/em><\/strong> works. I won\u2019t claim they are \u201ccorrect.\u201d One of my problems with the <strong><em>NixOS<\/em><\/strong> ecosystem is that it\u2019s sometimes very hard to pin down what a given word means in a given context. These definitions are my attempt to at least capture my understanding.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u201cNix\u201d<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The word \u201cNix\u201d itself can mean one of three different things. I\u2019ve tried to take care not to use just \u201cNix\u201d in this document. Instead, I try to explicitly use one of the following three terms.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Nix Expression Language<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong><em>Nix Expression Language<\/em><\/strong> is the programming language in which Nix <strong><em>Expressions<\/em><\/strong> are written.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Nix Package Manager<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong><em>Nix Package Manager<\/em><\/strong> is the suite of tools that build <strong><em>Derivations<\/em><\/strong> and manage the <strong><em>Nix Store<\/em><\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <em><strong>Nix Package Manager<\/strong><\/em> can be used to maintain a <strong><em>Nix Store<\/em><\/strong> on distros other than <strong><em>NixOS<\/em><\/strong>.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">NixOS<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">A Linux distro whose entire configuration (not just the applications you install within it) is in the <strong><em>Nix Store<\/em><\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Expression<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Independent of the <strong><em>Nix Expression Language<\/em><\/strong>, an <strong><em>Expression<\/em><\/strong> is a syntactical object (of a programming language) that evaluates to a value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong><em>Nix Expression Language<\/em><\/strong> is functional: \u201cEverything is an <strong><em>Expression<\/em><\/strong>.\u201d This model should be familiar to those who have used functional languages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can compose <strong><em>Expressions<\/em><\/strong> into larger <strong><em>Expressions<\/em><\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Derivation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Some <strong><em>Expressions<\/em><\/strong> evaluate to <strong><em>Derivations<\/em><\/strong>. Though there are no such formal terms, in the <strong><em>Nix Expression Language<\/em><\/strong> it may be helpful to think of such <strong><em>Expressions<\/em><\/strong> as \u201ctop level <strong><em>Expressions<\/em><\/strong>\u201d or \u201cprograms.\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong><em>Derivation<\/em><\/strong> that these <strong><em>Expressions<\/em><\/strong> evaluate to is an in-memory structure.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When one of these \u201cin-memory <strong><em>Derivations<\/em><\/strong>\u201d is Instantiated, a store object is created. This object is ALSO called a <strong><em>Derivation<\/em><\/strong>. You can think of this \u201cstore <strong><em>Derivation<\/em><\/strong>\u201d as a build plan for a set of <strong><em>Outputs<\/em><\/strong>. It can be Realized, resulting in the creation of these <strong><em>Outputs<\/em><\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The key insight here is:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The store <strong><em>Derivation<\/em><\/strong> is completely determined by the inputs to the <strong><em>Expression<\/em><\/strong> whose evaluation yielded the in-memory <strong><em>Derivation<\/em><\/strong> (whose Instantiation resulted in the store <strong><em>Derivation\u2019s<\/em><\/strong> creation). For the store <strong><em>Derivation<\/em><\/strong>, all \u201cvariability\u201d has been removed. It is a fully specified \u201cbuild plan\u201d for a set of <strong><em>Outputs<\/em><\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Outputs<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">A store <strong><em>Derivation<\/em><\/strong> can be Realized to create multiple <strong><em>Outputs<\/em><\/strong>. For example, a <strong><em>Derivation<\/em><\/strong> could have separate <strong><em>Outputs<\/em><\/strong> for its runtime and its documentation. All such <strong><em>Outputs<\/em><\/strong> (once Realized) live in the <strong><em>Nix Store<\/em><\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Nix Store<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong><em>Nix Store<\/em><\/strong> is the <strong><em>Nix Package Manager\u2019s<\/em><\/strong> database. It\u2019s implemented right on the filesystem and is usually located at \/nix\/store.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It\u2019s a flat database: each directory or file in the \/nix\/store\/ directory is a single addressable component in the store \u2013 and these directories and files are the only components of the store. Most of them are <strong><em>Derivations<\/em><\/strong> and <strong><em>Outputs<\/em><\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Store Path<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">A <strong><em>Store Path<\/em><\/strong> is the coordinate (in the <strong><em>Nix Store<\/em><\/strong>) of a given store component (<strong><em>Output<\/em><\/strong>, <strong><em>Derivation<\/em><\/strong>).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Package<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">A <strong><em>Package<\/em><\/strong> is really nothing more than a name given to an <strong><em>Expression<\/em><\/strong> that evaluates to a <strong><em>Derivation<\/em><\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It\u2019s easier to explain with an example:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Imagine a function named vim that takes an enableGui argument (whose default value is false) and returns a <strong><em>Derivation<\/em><\/strong>. Imagine that your <strong><em>NixOS<\/em><\/strong> distro, in some global namespace, assigned a name to this <strong><em>Expression<\/em><\/strong>: vim-no-gui = vim {}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That name (vim-no-gui) is a <strong><em>Package<\/em><\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you wanted to create a <strong><em>Derivation<\/em><\/strong> whose Realization would result in a version of vim that <strong>did<\/strong> have a GUI, you could just call that function with enableGui=true, eg: vim {enableGui = true}.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But <strong><em>NixOS<\/em><\/strong> maintainers are also free to create a <strong><em>Package<\/em><\/strong> that does the same by simply assigning a name: vim-gui = vim {enableGui = true}.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Term Summary \/ Relationships<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Putting it all together\u2026<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Some <strong><em>Expressions<\/em><\/strong>, when evaluated, yield in-memory <strong><em>Derivations<\/em><\/strong>. These in-memory <strong><em>Derivations<\/em><\/strong> can be Instantiated to become store <strong><em>Derivations<\/em><\/strong>. These store <strong><em>Derivations<\/em><\/strong> can be Realized as <strong><em>Outputs<\/em><\/strong> in the <strong><em>Nix Store<\/em><\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Expression -&gt;<br>&nbsp; Evaluate(Expression) -&gt;<br>&nbsp; &nbsp; in-memory Derivation -&gt;<br>&nbsp; &nbsp; &nbsp; Instantiate(in-memory Derivation) -&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; store Derivation -&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Realize(store Derivation) -&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Outputs<br><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Building and Installing with the Nix Package Manager<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">Derivation Creating Expressions<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To build our experiment\u2019s library and program with the <strong><em>Nix Package Manager<\/em><\/strong>, we create a default.nix file in each project\u2019s root. This file contains an <strong><em>Expression<\/em><\/strong> that defines a function that returns a <strong><em>Derivation<\/em><\/strong><sup data-fn=\"0354c107-e537-4bfa-8235-86ca7de0ae86\" class=\"fn\"><a href=\"#0354c107-e537-4bfa-8235-86ca7de0ae86\" id=\"0354c107-e537-4bfa-8235-86ca7de0ae86-link\">3<\/a><\/sup>. That <strong><em>Derivation<\/em><\/strong> contains all the information the <strong><em>Nix Package Manager<\/em><\/strong> needs to build the project.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the default.nix that builds the greeter program:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{ stdenv<br>, greeting ? \"Hello, World!\"<br>, libgreeting ? import ..\/lib { inherit stdenv greeting; }<br>}:<br><br>stdenv.mkDerivation {<br>&nbsp; pname = \"greeter\";<br>&nbsp; version = \"1.0.0\";<br><br>&nbsp; src = .\/.;<br><br>&nbsp; buildInputs = &#91; libgreeting ];<br><br>&nbsp; dontConfigure = true;<br><br>&nbsp; buildPhase = ''<br>&nbsp; &nbsp; make INCLUDES=\"-I${libgreeting}\/include\" LDFLAGS=\"-L${libgreeting}\/lib\"<br>&nbsp; '';<br><br>&nbsp; installPhase = ''<br>&nbsp; &nbsp; make install PREFIX= DESTDIR=$out<br>&nbsp; '';<br><br>&nbsp; meta = {<br>&nbsp; &nbsp; description = \"A greeting program (greeting: ${greeting})\";<br>&nbsp; };<br>}<br><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Note that the <strong><em>Derivation<\/em><\/strong> returned by this function includes libgreeting as the only member of its buildInputs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note that libgreeting is passed as a parameter to the function, and its default value is the result of calling the function defined in the lib\u2019s default.nix file with the same greeting parameter passed to this function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Although the type of libgreeting is a <strong><em>Derivation<\/em><\/strong>, when it\u2019s used to construct the buildPhase string, the <strong><em>Nix Expression Language\u2019s<\/em><\/strong> string interpolation turns it into libgreeting\u2019s default <strong><em>Output<\/em><\/strong> path in the <strong><em>Nix Store<\/em><\/strong>. We use this fact to construct a value for the INCLUDES and LDFLAGS variables that will be passed to make when the <strong><em>Nix Package Manager<\/em><\/strong> runs it. This is how the <strong><em>Nix Package Manager<\/em><\/strong> informs greeter\u2019s build process of where it put (or will put) its dependencies.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong><em>Derivation<\/em><\/strong> returned by this function, from the <strong><em>Nix Package Manager\u2019s<\/em><\/strong> point of view, is completely determined by its buildInputs<sup data-fn=\"e57c8fce-4062-4907-ab38-73cbee28bc13\" class=\"fn\"><a href=\"#e57c8fce-4062-4907-ab38-73cbee28bc13\" id=\"e57c8fce-4062-4907-ab38-73cbee28bc13-link\">4<\/a><\/sup>. The key variable input is libgreeting, and that input is a <strong><em>Derivation<\/em><\/strong> that results from calling the function defined in lib\/default.nix with the greeting parameter.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s the default.nix that builds the libgreeting library:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{ stdenv<br>, greeting ? \"Hello, World!\"<br>}:<br><br>stdenv.mkDerivation {<br>&nbsp; pname = \"libgreeting\";<br>&nbsp; version = \"1.0.0\";<br><br>&nbsp; src = .\/.;<br><br>&nbsp; # Pass the greeting to the Makefile via environment variable<br>&nbsp; GREETING = greeting;<br><br>&nbsp; # No configure phase needed for this simple Makefile<br>&nbsp; dontConfigure = true;<br><br>&nbsp; buildPhase = ''<br>&nbsp; &nbsp; make<br>&nbsp; '';<br><br>&nbsp; installPhase = ''<br>&nbsp; &nbsp; make install PREFIX= DESTDIR=$out<br>&nbsp; '';<br><br>&nbsp; meta = {<br>&nbsp; &nbsp; description = \"A simple greeting library (greeting: ${greeting})\";<br>&nbsp; };<br>}<br><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Because the <strong><em>Derivation<\/em><\/strong> returned by this function uses the value of greeting in its definition, that means that this function creates <em>different<\/em> <strong><em>Derivations<\/em><\/strong> for different values of the greeting parameter passed to it. The <strong><em>Derivation<\/em><\/strong> returned by the function defined in program\/default.nix can depend on any one of these <strong><em>Derivations<\/em><\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since a <strong><em>Derivation<\/em><\/strong> is also determined by its inputs, the function defined in program\/default.nix returns a different <strong><em>Derivation<\/em><\/strong> for every different value of libgreeting.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In other words, when building greeter, each value you choose for greeting yields a different <strong><em>Derivation<\/em><\/strong> of libgreeting to be built. libgreeting being the key variable input to greeter, this causes a different <strong><em>Derivation<\/em><\/strong> of greeter to be built. For each value of greeting, you get two <strong><em>Outputs<\/em><\/strong> in the store: one for greeter, one for libgreeting.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It\u2019s easier to see with an example.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Running the Build<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In the source directory, there are two files, demo01.nix and demo02.nix. They differ <em>only<\/em> in the greeting they pass to the function defined in .\/program\/default.nix, so I\u2019ll just show demo01.nix:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let<br>&nbsp; pkgs = import &lt;nixpkgs&gt; {};<br>in<br>pkgs.callPackage .\/program {<br>&nbsp; greeting = \"Hello from Demo 01!\";<br>}<br><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Given those two files, we can run the following two commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nix-build demo01.nix -o demo01<br>nix-build demo02.nix -o demo02<br><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Those commands will (for the single <strong><em>Expression<\/em><\/strong> in each file) go through the whole process starting with <strong><em>Expression<\/em><\/strong> evaluation all the way through to <strong><em>Output<\/em><\/strong> creation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The first time you run them, you\u2019ll see the whole build process (for library <em>and<\/em> program!) followed by the <strong><em>Nix Package Manager<\/em><\/strong> telling you where it placed the program (greeter) in the store. If you run them again, the <strong><em>Nix Package Manager<\/em><\/strong> recognizes that it has already built them\u2026 and just shows you where it put them in the store:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$&gt; nix-build demo01.nix -o demo01<br>\/nix\/store\/32w8g2sjafhj8iag8v2hb1q1s0mmjw56-greeter-1.0.0<br><br>$&gt; nix-build demo02.nix -o demo02<br>\/nix\/store\/hnznyz5p9ymaxx61phsis0q9kh7i1aaw-greeter-1.0.0<br><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Examining the Output<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Because we specified the -o switch to nix-build, it also created two symlinks<sup data-fn=\"62eb955a-11df-4d12-b502-ac776d511381\" class=\"fn\"><a href=\"#62eb955a-11df-4d12-b502-ac776d511381\" id=\"62eb955a-11df-4d12-b502-ac776d511381-link\">5<\/a><\/sup> in the local directory:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$&gt; ls -l demo01 demo02<br>lrwxrwxrwx 1 1024 users 57 Jul&nbsp; 4 19:11 demo01 -&gt; \/nix\/store\/32w8g2sjafhj8iag8v2hb1q1s0mmjw56-greeter-1.0.0<br>lrwxrwxrwx 1 1024 users 57 Jul&nbsp; 4 19:11 demo02 -&gt; \/nix\/store\/hnznyz5p9ymaxx61phsis0q9kh7i1aaw-greeter-1.0.0<br><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We can use these symlinks to run the programs:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$&gt; .\/demo01\/bin\/greeter<br>Hello from Demo 01!<br>$&gt; .\/demo02\/bin\/greeter<br>Hello from Demo 02!<br><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">But what about the libraries? Well, we can ask the <strong><em>Nix Package Manager<\/em><\/strong> to show us the dependency graph for both executables:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$&gt; nix-store -q --tree .\/demo01 | cat<br>\/nix\/store\/32w8g2sjafhj8iag8v2hb1q1s0mmjw56-greeter-1.0.0<br>\u251c\u2500\u2500\u2500\/nix\/store\/vr7ds8vwbl2fz7pr221d5y0f8n9a5wda-glibc-2.40-218<br>\u2502 &nbsp; \u251c\u2500\u2500\u2500\/nix\/store\/2a3izq4hffdd9r9gb2w6q2ibdc86kss6-xgcc-14.3.0-libgcc<br>\u2502 &nbsp; \u251c\u2500\u2500\u2500\/nix\/store\/hxcmad417fd8ql9ylx96xpak7da06yiv-libidn2-2.3.8<br>\u2502 &nbsp; \u2502 &nbsp; \u251c\u2500\u2500\u2500\/nix\/store\/3rkccxj7vi0p2a0d48c4a4z2vv2cni88-libunistring-1.4.1<br>\u2502 &nbsp; \u2502 &nbsp; \u2502 &nbsp; \u2514\u2500\u2500\u2500\/nix\/store\/3rkccxj7vi0p2a0d48c4a4z2vv2cni88-libunistring-1.4.1 &#91;...]<br>\u2502 &nbsp; \u2502 &nbsp; \u2514\u2500\u2500\u2500\/nix\/store\/hxcmad417fd8ql9ylx96xpak7da06yiv-libidn2-2.3.8 &#91;...]<br>\u2502 &nbsp; \u2514\u2500\u2500\u2500\/nix\/store\/vr7ds8vwbl2fz7pr221d5y0f8n9a5wda-glibc-2.40-218 &#91;...]<br>\u2514\u2500\u2500\u2500\/nix\/store\/fhscgmiy6gsjmghbx4nyb9djn68fxjvg-libgreeting-1.0.0<br>&nbsp; &nbsp; \u2514\u2500\u2500\u2500\/nix\/store\/vr7ds8vwbl2fz7pr221d5y0f8n9a5wda-glibc-2.40-218 &#91;...]<br><br>$&gt; nix-store -q --tree .\/demo02 | cat<br>\/nix\/store\/hnznyz5p9ymaxx61phsis0q9kh7i1aaw-greeter-1.0.0<br>\u251c\u2500\u2500\u2500\/nix\/store\/vr7ds8vwbl2fz7pr221d5y0f8n9a5wda-glibc-2.40-218<br>\u2502 &nbsp; \u251c\u2500\u2500\u2500\/nix\/store\/2a3izq4hffdd9r9gb2w6q2ibdc86kss6-xgcc-14.3.0-libgcc<br>\u2502 &nbsp; \u251c\u2500\u2500\u2500\/nix\/store\/hxcmad417fd8ql9ylx96xpak7da06yiv-libidn2-2.3.8<br>\u2502 &nbsp; \u2502 &nbsp; \u251c\u2500\u2500\u2500\/nix\/store\/3rkccxj7vi0p2a0d48c4a4z2vv2cni88-libunistring-1.4.1<br>\u2502 &nbsp; \u2502 &nbsp; \u2502 &nbsp; \u2514\u2500\u2500\u2500\/nix\/store\/3rkccxj7vi0p2a0d48c4a4z2vv2cni88-libunistring-1.4.1 &#91;...]<br>\u2502 &nbsp; \u2502 &nbsp; \u2514\u2500\u2500\u2500\/nix\/store\/hxcmad417fd8ql9ylx96xpak7da06yiv-libidn2-2.3.8 &#91;...]<br>\u2502 &nbsp; \u2514\u2500\u2500\u2500\/nix\/store\/vr7ds8vwbl2fz7pr221d5y0f8n9a5wda-glibc-2.40-218 &#91;...]<br>\u2514\u2500\u2500\u2500\/nix\/store\/sazax1y1k7ab5h5k5m2hbrky7s9dnadb-libgreeting-1.0.0<br>&nbsp; &nbsp; \u2514\u2500\u2500\u2500\/nix\/store\/vr7ds8vwbl2fz7pr221d5y0f8n9a5wda-glibc-2.40-218 &#91;...]<br><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you look closely, you\u2019ll see they depend on two different libgreeting libraries. Perhaps even more surprising, however, is that they <em>share<\/em> the same <strong><em>Outputs<\/em><\/strong> for all other dependencies they have in common. The <strong><em>Nix Package Manager<\/em><\/strong> manages all that for you!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Nix Package Manager Enables This<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s take another look at this diagram:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Expression -&gt;<br>&nbsp; Evaluate(Expression) -&gt;<br>&nbsp; &nbsp; in-memory Derivation -&gt;<br>&nbsp; &nbsp; &nbsp; Instantiate(in-memory Derivation) -&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; store Derivation -&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Realize(store Derivation) -&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Outputs<br><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now let\u2019s justify each step:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Expression<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong><em>Expressions<\/em><\/strong> we created (in the default.nix files) define functions with parameters of our choosing. Each of these functions builds and returns a <strong><em>Derivation<\/em><\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We are free to use the arguments passed into this function when it is called to construct the <strong><em>Derivation<\/em><\/strong> however we see fit. Perhaps most interesting: we can use these arguments to compute the inputs of the <strong><em>Derivation<\/em><\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, given a source code repository (which includes source code along with any scripts and metadata required to convert the source code to an executable artifact), we can create an <strong><em>Expression<\/em><\/strong> (function) whose parameters capture any and all variability in our build process. For example: branch name; version number; compiler flags; upstream dependencies; etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the function body, we can specify how a <strong><em>Derivation<\/em><\/strong> (and even its inputs) are constructed given the values (arguments) we assign to these parameters.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Evaluation of Expression<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Evaluation of the <strong><em>Expression<\/em><\/strong> simply takes the arguments we\u2019ve passed to the function and uses them to compute the in-memory <strong><em>Derivation<\/em><\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">In-Memory Derivation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Assuming we\u2019re using input addressing<sup data-fn=\"f5d18dcd-9f92-4db2-a5b2-ed0d2c9d1e2d\" class=\"fn\"><a href=\"#f5d18dcd-9f92-4db2-a5b2-ed0d2c9d1e2d\" id=\"f5d18dcd-9f92-4db2-a5b2-ed0d2c9d1e2d-link\">6<\/a><\/sup>, at this point the Store Location of every <strong><em>Output<\/em><\/strong> in the entire dependency graph of the <strong><em>Derivation<\/em><\/strong> is known (or can be determined).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The store location of <em>this<\/em> <strong><em>Derivation<\/em><\/strong> is a function of all of its inputs. That is, this <strong><em>Derivation<\/em><\/strong> is specific to the exact combination of inputs that were used to create it. The same is true for every input in this <strong><em>Derivation\u2019s<\/em><\/strong> entire dependency graph.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Instantiate<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Our in-memory <strong><em>Derivation<\/em><\/strong> is serialized to disk at its own address in the <strong><em>Nix Store<\/em><\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Store Derivation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Now that the <strong><em>Derivation<\/em><\/strong> exists in the Store, any <strong><em>Nix Package Manager<\/em><\/strong> process attempting to Realize this <strong><em>Derivation<\/em><\/strong> or any of its downstream <strong><em>Derivations<\/em><\/strong> (those <strong><em>Derivations<\/em><\/strong> that depend on this <strong><em>Derivation\u2019s<\/em><\/strong> <strong><em>Outputs<\/em><\/strong>) now has a template that tells it how to do so.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Realize the Derivation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Okay, now we actually want to run some binaries. So we Realize the <strong><em>Derivation<\/em><\/strong>, which forces it to be built. This will also recursively Realize this <strong><em>Derivation\u2019s<\/em><\/strong> entire dependency graph (skipping any that have already been Realized).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Output<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Now there is an actual (in our case) binary in the store that we can run!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">So, what have we shown here? Well, I\u2019d argue that we\u2019ve shown that the <strong><em>Nix Package Manager<\/em><\/strong> can isolate any component (for example, a program binary) \u2013 and its entire dependency graph \u2013 from any other component (and said component\u2019s dependency graph) on your system. In particular, we\u2019ve shown that you can build as many versions of a binary as you want, where the definition of \u201cversion\u201d takes into account any \u201cversions\u201d of upstream libraries you may also be building from source.<\/p>\n\n\n<ol class=\"wp-block-footnotes\"><li id=\"944a06d2-4cd1-4210-8c17-4b7b830fe93f\">Okay, technically I am modifying CFLAGS, but only because that\u2019s how you define preprocessor macros at compile time. What I mean is that I\u2019m not passing arguments that change how the compiler behaves; e.g.: -O3. <a href=\"#944a06d2-4cd1-4210-8c17-4b7b830fe93f-link\" aria-label=\"Jump to footnote reference 1\">\u21a9\ufe0e<\/a><\/li><li id=\"79ebbd15-2a70-4081-a13e-7c00f908af8f\">I&#8217;ve already used some of these terms before defining them. I apologize for that, but it was hard to structure this document. <a href=\"#79ebbd15-2a70-4081-a13e-7c00f908af8f-link\" aria-label=\"Jump to footnote reference 2\">\u21a9\ufe0e<\/a><\/li><li id=\"0354c107-e537-4bfa-8235-86ca7de0ae86\">This <strong><em>Derivation<\/em><\/strong>-returning function is what is expected by the <strong><em>Nix Expression Language<\/em><\/strong> provided callPackage function, which we will be using in just a bit to kick off the build process. <a href=\"#0354c107-e537-4bfa-8235-86ca7de0ae86-link\" aria-label=\"Jump to footnote reference 3\">\u21a9\ufe0e<\/a><\/li><li id=\"e57c8fce-4062-4907-ab38-73cbee28bc13\">This is known as \u201cinput addressing.\u201d If you want to go down a rabbit hole, contrast this with \u201ccontent addressing\u201d (which is currently being worked on for <strong><em>NixOS<\/em><\/strong>). <a href=\"#e57c8fce-4062-4907-ab38-73cbee28bc13-link\" aria-label=\"Jump to footnote reference 4\">\u21a9\ufe0e<\/a><\/li><li id=\"62eb955a-11df-4d12-b502-ac776d511381\">These symlinks are one instance of what is known as a Garbage Collection (GC) Root. There are different ways in which the <strong><em>Nix Package Manager<\/em><\/strong> creates GC Roots. Here, they are the output of the build process \u2013 a convenience. More interesting are Profiles and Generations\u2026 the tools <strong><em>NixOS<\/em><\/strong> uses to manage a bespoke execution environment for every user on the system. Any <strong><em>Output<\/em><\/strong> reachable via an existing GC Root\u2019s graph will not be garbage collected when you run nix-collect-garbage. I wanted to talk more about GC Roots, Profiles, and Generations\u2026 but this post is too long already! <a href=\"#62eb955a-11df-4d12-b502-ac776d511381-link\" aria-label=\"Jump to footnote reference 5\">\u21a9\ufe0e<\/a><\/li><li id=\"f5d18dcd-9f92-4db2-a5b2-ed0d2c9d1e2d\">This is known as \u201cinput addressing.\u201d If you want to go down a rabbit hole, contrast this with \u201ccontent addressing\u201d (which is currently being worked on for <strong><em>NixOS<\/em><\/strong>). <a href=\"#f5d18dcd-9f92-4db2-a5b2-ed0d2c9d1e2d-link\" aria-label=\"Jump to footnote reference 6\">\u21a9\ufe0e<\/a><\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>***Expect words in bold italics to be defined somewhere in this document. Defining all words before they were used proved to be too much work. So for some definitions, you just need to be patient.*** Introduction I\u2019ve been daily driving NixOS for over half a year now. I\u2019m still just a beginner, but I\u2019m slowly [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"[{\"content\":\"Okay, technically I am modifying CFLAGS, but only because that\u2019s how you define preprocessor macros at compile time. What I mean is that I\u2019m not passing arguments that change how the compiler behaves; e.g.: -O3.\",\"id\":\"944a06d2-4cd1-4210-8c17-4b7b830fe93f\"},{\"content\":\"I've already used some of these terms before defining them. I apologize for that, but it was hard to structure this document.\",\"id\":\"79ebbd15-2a70-4081-a13e-7c00f908af8f\"},{\"content\":\"This <strong><em>Derivation<\/em><\/strong>-returning function is what is expected by the <strong><em>Nix Expression Language<\/em><\/strong> provided callPackage function, which we will be using in just a bit to kick off the build process.\",\"id\":\"0354c107-e537-4bfa-8235-86ca7de0ae86\"},{\"content\":\"This is known as \u201cinput addressing.\u201d If you want to go down a rabbit hole, contrast this with \u201ccontent addressing\u201d (which is currently being worked on for <strong><em>NixOS<\/em><\/strong>).\",\"id\":\"e57c8fce-4062-4907-ab38-73cbee28bc13\"},{\"content\":\"These symlinks are one instance of what is known as a Garbage Collection (GC) Root. There are different ways in which the <strong><em>Nix Package Manager<\/em><\/strong> creates GC Roots. Here, they are the output of the build process \u2013 a convenience. More interesting are Profiles and Generations\u2026 the tools <strong><em>NixOS<\/em><\/strong> uses to manage a bespoke execution environment for every user on the system. Any <strong><em>Output<\/em><\/strong> reachable via an existing GC Root\u2019s graph will not be garbage collected when you run nix-collect-garbage. I wanted to talk more about GC Roots, Profiles, and Generations\u2026 but this post is too long already!\",\"id\":\"62eb955a-11df-4d12-b502-ac776d511381\"},{\"content\":\"This is known as \u201cinput addressing.\u201d If you want to go down a rabbit hole, contrast this with \u201ccontent addressing\u201d (which is currently being worked on for <strong><em>NixOS<\/em><\/strong>).\",\"id\":\"f5d18dcd-9f92-4db2-a5b2-ed0d2c9d1e2d\"}]"},"categories":[1],"tags":[],"class_list":["post-7060","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Learning NixOS and Its Nix Package Manager - Solution Street Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learning NixOS and Its Nix Package Manager - Solution Street Blog\" \/>\n<meta property=\"og:description\" content=\"***Expect words in bold italics to be defined somewhere in this document. Defining all words before they were used proved to be too much work. So for some definitions, you just need to be patient.*** Introduction I\u2019ve been daily driving NixOS for over half a year now. I\u2019m still just a beginner, but I\u2019m slowly [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/\" \/>\n<meta property=\"og:site_name\" content=\"Solution Street Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-20T22:01:22+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-20T22:01:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2026\/11\/Box-title2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"700\" \/>\n\t<meta property=\"og:image:height\" content=\"372\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Peggy Frankel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Peggy Frankel\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2026\\\/11\\\/20\\\/learning-nixos-and-its-nix-package-manager\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2026\\\/11\\\/20\\\/learning-nixos-and-its-nix-package-manager\\\/\"},\"author\":{\"name\":\"Peggy Frankel\",\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/#\\\/schema\\\/person\\\/c4846451eff30e9514b534b2a2e01696\"},\"headline\":\"Learning NixOS and Its Nix Package Manager\",\"datePublished\":\"2026-11-20T22:01:22+00:00\",\"dateModified\":\"2026-11-20T22:01:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2026\\\/11\\\/20\\\/learning-nixos-and-its-nix-package-manager\\\/\"},\"wordCount\":3212,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2026\\\/11\\\/20\\\/learning-nixos-and-its-nix-package-manager\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Box-title2.png\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2026\\\/11\\\/20\\\/learning-nixos-and-its-nix-package-manager\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2026\\\/11\\\/20\\\/learning-nixos-and-its-nix-package-manager\\\/\",\"url\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2026\\\/11\\\/20\\\/learning-nixos-and-its-nix-package-manager\\\/\",\"name\":\"Learning NixOS and Its Nix Package Manager - Solution Street Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2026\\\/11\\\/20\\\/learning-nixos-and-its-nix-package-manager\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2026\\\/11\\\/20\\\/learning-nixos-and-its-nix-package-manager\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Box-title2.png\",\"datePublished\":\"2026-11-20T22:01:22+00:00\",\"dateModified\":\"2026-11-20T22:01:25+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/#\\\/schema\\\/person\\\/c4846451eff30e9514b534b2a2e01696\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2026\\\/11\\\/20\\\/learning-nixos-and-its-nix-package-manager\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2026\\\/11\\\/20\\\/learning-nixos-and-its-nix-package-manager\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2026\\\/11\\\/20\\\/learning-nixos-and-its-nix-package-manager\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Box-title2.png\",\"contentUrl\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Box-title2.png\",\"width\":700,\"height\":372},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/2026\\\/11\\\/20\\\/learning-nixos-and-its-nix-package-manager\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Learning NixOS and Its Nix Package Manager\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/\",\"name\":\"Solution Street Blog\",\"description\":\"Quality Software Engineering - Technology and Consulting Articles\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/#\\\/schema\\\/person\\\/c4846451eff30e9514b534b2a2e01696\",\"name\":\"Peggy Frankel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/af71ceb16f89d32c9bb825a47f8057da9283b4a27a934bf0c47cdef65ad0eb5d?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/af71ceb16f89d32c9bb825a47f8057da9283b4a27a934bf0c47cdef65ad0eb5d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/af71ceb16f89d32c9bb825a47f8057da9283b4a27a934bf0c47cdef65ad0eb5d?s=96&d=mm&r=g\",\"caption\":\"Peggy Frankel\"},\"url\":\"https:\\\/\\\/www.solutionstreet.com\\\/blog\\\/author\\\/pfrankel\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learning NixOS and Its Nix Package Manager - Solution Street Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/","og_locale":"en_US","og_type":"article","og_title":"Learning NixOS and Its Nix Package Manager - Solution Street Blog","og_description":"***Expect words in bold italics to be defined somewhere in this document. Defining all words before they were used proved to be too much work. So for some definitions, you just need to be patient.*** Introduction I\u2019ve been daily driving NixOS for over half a year now. I\u2019m still just a beginner, but I\u2019m slowly [&hellip;]","og_url":"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/","og_site_name":"Solution Street Blog","article_published_time":"2026-11-20T22:01:22+00:00","article_modified_time":"2026-11-20T22:01:25+00:00","og_image":[{"width":700,"height":372,"url":"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2026\/11\/Box-title2.png","type":"image\/png"}],"author":"Peggy Frankel","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Peggy Frankel","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/#article","isPartOf":{"@id":"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/"},"author":{"name":"Peggy Frankel","@id":"https:\/\/www.solutionstreet.com\/blog\/#\/schema\/person\/c4846451eff30e9514b534b2a2e01696"},"headline":"Learning NixOS and Its Nix Package Manager","datePublished":"2026-11-20T22:01:22+00:00","dateModified":"2026-11-20T22:01:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/"},"wordCount":3212,"commentCount":0,"image":{"@id":"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/#primaryimage"},"thumbnailUrl":"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2026\/11\/Box-title2.png","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/","url":"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/","name":"Learning NixOS and Its Nix Package Manager - Solution Street Blog","isPartOf":{"@id":"https:\/\/www.solutionstreet.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/#primaryimage"},"image":{"@id":"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/#primaryimage"},"thumbnailUrl":"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2026\/11\/Box-title2.png","datePublished":"2026-11-20T22:01:22+00:00","dateModified":"2026-11-20T22:01:25+00:00","author":{"@id":"https:\/\/www.solutionstreet.com\/blog\/#\/schema\/person\/c4846451eff30e9514b534b2a2e01696"},"breadcrumb":{"@id":"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/#primaryimage","url":"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2026\/11\/Box-title2.png","contentUrl":"https:\/\/www.solutionstreet.com\/blog\/wp-content\/uploads\/2026\/11\/Box-title2.png","width":700,"height":372},{"@type":"BreadcrumbList","@id":"https:\/\/www.solutionstreet.com\/blog\/2026\/11\/20\/learning-nixos-and-its-nix-package-manager\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.solutionstreet.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Learning NixOS and Its Nix Package Manager"}]},{"@type":"WebSite","@id":"https:\/\/www.solutionstreet.com\/blog\/#website","url":"https:\/\/www.solutionstreet.com\/blog\/","name":"Solution Street Blog","description":"Quality Software Engineering - Technology and Consulting Articles","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.solutionstreet.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.solutionstreet.com\/blog\/#\/schema\/person\/c4846451eff30e9514b534b2a2e01696","name":"Peggy Frankel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/af71ceb16f89d32c9bb825a47f8057da9283b4a27a934bf0c47cdef65ad0eb5d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/af71ceb16f89d32c9bb825a47f8057da9283b4a27a934bf0c47cdef65ad0eb5d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/af71ceb16f89d32c9bb825a47f8057da9283b4a27a934bf0c47cdef65ad0eb5d?s=96&d=mm&r=g","caption":"Peggy Frankel"},"url":"https:\/\/www.solutionstreet.com\/blog\/author\/pfrankel\/"}]}},"_links":{"self":[{"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/posts\/7060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/comments?post=7060"}],"version-history":[{"count":31,"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/posts\/7060\/revisions"}],"predecessor-version":[{"id":7096,"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/posts\/7060\/revisions\/7096"}],"wp:attachment":[{"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/media?parent=7060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/categories?post=7060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.solutionstreet.com\/blog\/wp-json\/wp\/v2\/tags?post=7060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}