<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Nix on paradigmatic.systems</title>
    <link>https://paradigmatic.systems/tags/nix/</link>
    <description>Recent content in Nix on paradigmatic.systems</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Wed, 13 Aug 2025 04:30:00 +0000</lastBuildDate><atom:link href="https://paradigmatic.systems/tags/nix/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Nix: the Language, the Tool, the Package Repo, the OS</title>
      <link>https://paradigmatic.systems/posts/nix-nixpkgs-nixos/</link>
      <pubDate>Wed, 13 Aug 2025 04:30:00 +0000</pubDate>
      
      <guid>https://paradigmatic.systems/posts/nix-nixpkgs-nixos/</guid>
      <description>&lt;p&gt;There&amp;rsquo;s a lot going on in the Nix ecosystem. If you haven&amp;rsquo;t slogged through &lt;a href=&#34;https://edolstra.github.io/pubs/phd-thesis.pdf&#34;&gt;the thesis&lt;/a&gt; then it might seem downright opaque. This is my attempt at an easy explainer for newcomers.&lt;/p&gt;
&lt;h2 id=&#34;the-tool-and-the-language&#34;&gt;The Tool and the Language&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s bootstrap ourselves with some circular facts.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Nix is a &lt;em&gt;tool&lt;/em&gt; for building (or &amp;ldquo;packaging&amp;rdquo;) &lt;em&gt;software components&lt;/em&gt; using instructions expressed in the Nix &lt;em&gt;language&lt;/em&gt;.
The Nix language is even able to &lt;a href=&#34;https://github.com/NixOS/nix/blob/master/flake.nix&#34;&gt;package&lt;/a&gt; the Nix tool (which is mostly written in C++), thus closing the epistemological loop.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>There&rsquo;s a lot going on in the Nix ecosystem. If you haven&rsquo;t slogged through <a href="https://edolstra.github.io/pubs/phd-thesis.pdf">the thesis</a> then it might seem downright opaque. This is my attempt at an easy explainer for newcomers.</p>
<h2 id="the-tool-and-the-language">The Tool and the Language</h2>
<p>Let&rsquo;s bootstrap ourselves with some circular facts.</p>
<blockquote>
<p>Nix is a <em>tool</em> for building (or &ldquo;packaging&rdquo;) <em>software components</em> using instructions expressed in the Nix <em>language</em>.
The Nix language is even able to <a href="https://github.com/NixOS/nix/blob/master/flake.nix">package</a> the Nix tool (which is mostly written in C++), thus closing the epistemological loop.</p></blockquote>
<p>The language features first-class treatment of filesystem paths and URLs (to source code and tarballs, for example).
Nix <em>expressions</em> are evaluated in a hermetic environment with no path variables and no files. All outside references get copied into content-addressed folders in the <em>store</em>, and marked as build-time <em>dependencies</em> in any <em>derivation</em> that gets defined. Retained <em>runtime</em> dependencies are calculated by scanning the actual binary for store paths.</p>
<h2 id="the-build">The Build</h2>
<p>The component is the result of <em>realizing</em> the derivation. That means grabbing all the store path contents and combining them in the prescribed way. Imagine you have 3 components that are build-time dependencies:</p>
<ol>
<li>A compiler</li>
<li>Source code</li>
<li>A bash script that uses the compiler to build the source</li>
</ol>
<p>The derivation describes where to find these, and the (obvious) way that they fit together. The result is content-addressed with a hash based on all its dependencies, and placed in the store.</p>
<h2 id="nixpkgs">nixpkgs</h2>
<p>It turns out this scheme is highly flexible and repeatable.
<a href="https://github.com/NixOS/nixpkgs">nixpkgs</a> is a repo full of Nix expressions for over 120,000 packages. You can pull any one of them into an ephemeral shell to try it out, or install it system-wide if you&rsquo;re using:</p>
<h2 id="nixos">NixOS</h2>
<p>Finally, notice that &ldquo;<em>software components</em>&rdquo; could have a very broad definition. So broad, in fact, to include an entire OS with all of the installed programs and services. That&rsquo;s what NixOS is: A Linux distro defined entirely in Nix and built around the <code>/nix/store</code> path model instead of the more usual <a href="https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard">FHS</a>.  I&rsquo;ve written <a href="/posts/first-principles-infrastructure">a bit</a> about how the Nix <em>module</em> system helps encapsulate complex system recipes into simple one-liners.</p>
<p>All my homies use NixOS. To paraphrase from <a href="https://joshblais.com/blog/nixos-is-the-endgame-of-distrohopping/">NixOS is the endgame of distrohopping </a>:</p>
<h3 id="no-more-configuration-drift---solved-">No more configuration drift - solved ✅</h3>
<h3 id="works-on-my-machine---solved-">“Works on my machine!” - solved ✅</h3>
<h3 id="dependency-hell---solved-">Dependency Hell - solved ✅</h3>
<h3 id="virtual-and-development-environments---solved-">Virtual and development environments - solved ✅</h3>
<h3 id="package-management---solved-">package management - solved ✅</h3>
<h2 id="ready-to-go-deeper">Ready to go deeper?</h2>
<p>To get started I highly recommend working through the <a href="https://nix.dev/tutorials/">tutorials at nix.dev</a>!</p>
]]></content:encoded>
    </item>
    
    <item>
      <title>First Principles Infrastructure: Why NixOS Beats Containers and Clouds in 2025</title>
      <link>https://paradigmatic.systems/posts/first-principles-infrastructure/</link>
      <pubDate>Mon, 11 Aug 2025 14:30:00 +0000</pubDate>
      
      <guid>https://paradigmatic.systems/posts/first-principles-infrastructure/</guid>
      <description>&lt;p&gt;In the marketplace of developer skills, there&amp;rsquo;s a certain category that I&amp;rsquo;m long-term bearish on.  They don&amp;rsquo;t warrant investing free time trying to level up. Devs should limit their exposure to the minimum necessary to do their job. I&amp;rsquo;m talking about tools like Docker, Kubernetes, and the intricate managed hosting platforms of Azure and AWS. These are tools that help manage&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;social problems caused by scaling organizations to thousands of engineers&lt;/li&gt;
&lt;li&gt;existing complexity&lt;/li&gt;
&lt;li&gt;laziness or desire to throw money at a problem rather than solve it&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While they do solve real technical problems, I&amp;rsquo;ll argue here that there&amp;rsquo;s superior tooling for most use cases outside of big tech and legacy systems.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>In the marketplace of developer skills, there&rsquo;s a certain category that I&rsquo;m long-term bearish on.  They don&rsquo;t warrant investing free time trying to level up. Devs should limit their exposure to the minimum necessary to do their job. I&rsquo;m talking about tools like Docker, Kubernetes, and the intricate managed hosting platforms of Azure and AWS. These are tools that help manage</p>
<ul>
<li>social problems caused by scaling organizations to thousands of engineers</li>
<li>existing complexity</li>
<li>laziness or desire to throw money at a problem rather than solve it</li>
</ul>
<p>While they do solve real technical problems, I&rsquo;ll argue here that there&rsquo;s superior tooling for most use cases outside of big tech and legacy systems.</p>
<h1 id="containerize-or-modularize">Containerize or Modularize?</h1>
<blockquote>
<p>We need deployment consistency and environment isolation, and containers solve those!</p></blockquote>
<p>The 2016 essay <a href="https://catern.com/docker.html">Docker Considered Harmful</a> explains how Linux primitives solve the same problems in a more robust way. One valid criticism of this is that Docker can get a junior developer productive more quickly without needing to learn about arcane system settings.</p>
<p>Fine, so we need an abstraction to work with.</p>
<p>Does the abstraction need to expose us to a bloated ecosystem prone to drift? What if it could evaluate to the precise, minimal, and correct system without introducing overhead? What if it&rsquo;s a <a href="https://xeiaso.net/talks/2024/nix-docker-build/">better Docker image builder than Docker&rsquo;s image builder</a>?</p>
<p>Enter Nix with its <a href="https://nix.dev/tutorials/module-system/index.html">module system</a>. Nix approaches the &ldquo;dependency hell&rdquo; problem from first principles. It requires a radically different mental model, which is itself a social organization problem. This model, by the way, is laid out best in Eelco Dolstra&rsquo;s <a href="https://edolstra.github.io/pubs/phd-thesis.pdf">2006 PHD Thesis (PDF)</a>.</p>
<p>When you think about</p>
<ul>
<li>polyglot system with multiple language ecosystems working together</li>
<li>co-existing packages with conflicting dependencies (i.e dfferent versions of python)</li>
</ul>
<p>do you get a headache thinking about all the setup? Well then you should probably swallow some Nix pills. No other tool can encapsulate cross-ecosystem practices and Linux expertise so cleanly. A simple configuration change like</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-nix" data-lang="nix"><span style="display:flex;"><span>services<span style="color:#f92672">.</span>postgres<span style="color:#f92672">.</span>enable <span style="color:#f92672">=</span> <span style="color:#66d9ef">true</span>;
</span></span></code></pre></div><p>is the tip of a carefully crafted reproducible iceberg. This line of code hides a host of system-level changes including</p>
<ul>
<li>User and groups setup with correct isolation and permissions</li>
<li>Directory structure with ownership and permissions</li>
<li>Initialization, default template databases</li>
<li>SystemD service with correct dependencies, start order, lifecycle and recovery
and much more!</li>
</ul>
<p>It&rsquo;s a massive setup process that would normally be done manually, maybe captured in brittle shell scripts, or containerized. But here it&rsquo;s a one-liner, and it&rsquo;s exposed for use as a declarative model that allows completely deterministic and atomic system upgrades!</p>
<p>So while containers provide language-agnostic deployment, Nix achieves the same universality at the package level while maintaining better reproducibility and lower overhead. You can even spit out a Docker image as an afterthought if that&rsquo;s what you really need.</p>
<h1 id="cluster-or-cluster">Cluster or Cluster*@!#?</h1>
<blockquote>
<p>We need service discovery, load balancing, and observability! Kubernetes provides these with a vast ecosystem of battle-tested tools, and its nice declarative operator pattern for nearly every infrastructure need.</p></blockquote>
<p>The infrastructure problem is solved by creating different problems: cognitive overhead, ecosystem lock-in, long development cycles, and significant cost markup. There are compelling reasons to look for a better alternative.</p>
<p>Well, the largest package repo in the world (Nixpkgs) has nice <a href="https://search.nixos.org/options?channel=25.05&amp;from=0&amp;size=50&amp;sort=relevance&amp;type=packages">modules</a> defined for over 20,000 world-class open-source tools. With a 3-line change to your system configuration, you&rsquo;re now building a robust set of tools:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-nix" data-lang="nix"><span style="display:flex;"><span>services <span style="color:#f92672">=</span> {
</span></span><span style="display:flex;"><span>  nginx<span style="color:#f92672">.</span>enable <span style="color:#f92672">=</span> <span style="color:#66d9ef">true</span>;      <span style="color:#75715e">#Load balancing</span>
</span></span><span style="display:flex;"><span>  consul<span style="color:#f92672">.</span>enable <span style="color:#f92672">=</span> <span style="color:#66d9ef">true</span>;     <span style="color:#75715e">#Service discovery</span>
</span></span><span style="display:flex;"><span>  prometheus<span style="color:#f92672">.</span>enable <span style="color:#f92672">=</span> <span style="color:#66d9ef">true</span>; <span style="color:#75715e">#Observability</span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">#You&#39;ll want to configure these, of course.</span>
</span></span></code></pre></div><p>But that&rsquo;s not it. The <a href="https://nix.dev/manual/nix/2.28/command-ref/new-cli/nix3-flake.html#flake-format">Nix flake output schema</a> specifies <code>nixosConfigurations</code> as a key. Note the plural. So you might do something like:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-nix" data-lang="nix"><span style="display:flex;"><span>nixosConfigurations <span style="color:#f92672">=</span> {
</span></span><span style="display:flex;"><span>  web <span style="color:#f92672">=</span> mkNode <span style="color:#e6db74">&#34;web&#34;</span> {
</span></span><span style="display:flex;"><span>    services<span style="color:#f92672">.</span>nginx<span style="color:#f92672">.</span>enable <span style="color:#f92672">=</span> <span style="color:#66d9ef">true</span>;
</span></span><span style="display:flex;"><span>    services<span style="color:#f92672">.</span>nginx<span style="color:#f92672">.</span>virtualHosts<span style="color:#f92672">.</span><span style="color:#e6db74">&#34;web&#34;</span> <span style="color:#f92672">=</span> {
</span></span><span style="display:flex;"><span>      locations<span style="color:#f92672">.</span><span style="color:#e6db74">&#34;/api/&#34;</span> <span style="color:#f92672">=</span> {
</span></span><span style="display:flex;"><span>      proxyPass <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;http://</span><span style="color:#e6db74">${</span>cluster<span style="color:#f92672">.</span>db<span style="color:#f92672">.</span>ip<span style="color:#e6db74">}</span><span style="color:#e6db74">:5000/&#34;</span>;
</span></span><span style="display:flex;"><span>    };
</span></span><span style="display:flex;"><span>    app<span style="color:#f92672">.</span>db_address <span style="color:#f92672">=</span> cluster<span style="color:#f92672">.</span>db<span style="color:#f92672">.</span>ip
</span></span><span style="display:flex;"><span>  };
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  db <span style="color:#f92672">=</span> mkNode <span style="color:#e6db74">&#34;db&#34;</span> {
</span></span><span style="display:flex;"><span>    services<span style="color:#f92672">.</span>postgresql<span style="color:#f92672">.</span>enable <span style="color:#f92672">=</span> <span style="color:#66d9ef">true</span>;
</span></span><span style="display:flex;"><span>    services<span style="color:#f92672">.</span>postgresql<span style="color:#f92672">.</span>enableTCPIP <span style="color:#f92672">=</span> <span style="color:#66d9ef">true</span>;
</span></span><span style="display:flex;"><span>    services<span style="color:#f92672">.</span>postgresql<span style="color:#f92672">.</span>authentication <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;&#39;
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">      host all all </span><span style="color:#e6db74">${</span>cluster<span style="color:#f92672">.</span>web<span style="color:#f92672">.</span>ip<span style="color:#e6db74">}</span><span style="color:#e6db74">/32 trust
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">      &#39;&#39;</span>;
</span></span><span style="display:flex;"><span>    api<span style="color:#f92672">.</span>enable <span style="color:#f92672">=</span> <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>  };
</span></span><span style="display:flex;"><span>};
</span></span></code></pre></div><p>where the 2 nodes configurations make them aware of each other.</p>
<p>The same flake can even include</p>
<ul>
<li>integration tests using the insanely powerful <a href="https://nixcademy.com/posts/nixos-integration-tests/">integration test driver</a></li>
<li>deployment metadata with <a href="/posts/setting-up-deploy-rs">deploy-rs</a> to deploy the whole cluster with 1 command</li>
</ul>
<p>So the question then becomes, do you have a nest of messy legacy code and need to throw money at scaling it up? Or do you have the luxury of using the tools directly and scaling piecewise as needs arise?</p>
<h1 id="summary">Summary</h1>
<p>It&rsquo;s never going to be easy to retrofit legacy enterprise systems. But for designing new systems, the NixOS advantage is massive. Your entire system configuration, from kernel to application dependencies to infrastructure services, is a single, reproducible, version-controlled artifact. It allows for</p>
<ul>
<li>One deployment mechanism</li>
<li>Deterministic deployments</li>
<li>Exact parity between development and production</li>
</ul>
<p>and most importantly, a level of autonomy and sovereignty that you yield when your system is built on unstable abstractions.</p>
]]></content:encoded>
    </item>
    
    <item>
      <title>The Power of Nix: Developing, Building, and Deploying a Phoenix App</title>
      <link>https://paradigmatic.systems/posts/phoenix-in-nix/</link>
      <pubDate>Tue, 05 Aug 2025 04:30:00 +0000</pubDate>
      
      <guid>https://paradigmatic.systems/posts/phoenix-in-nix/</guid>
      <description>&lt;p&gt;The inordinate usefulness of Nix really sinks in when you realize that it allows you to define a single piece of unified infrastructure for handling all the different parts of the software lifecycle. Furthermore, this infrastructure doesn&amp;rsquo;t even need to be project-specific. For a given class of projects, the &amp;ldquo;holy grail&amp;rdquo; Nix flake template defines all the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;All the &lt;strong&gt;dependencies&lt;/strong&gt;, pinned in the &lt;code&gt;flake.lock&lt;/code&gt; and updatable with &lt;code&gt;nix flake update&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;dev environment&lt;/strong&gt; accessible with &lt;code&gt;nix develop&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;package&lt;/strong&gt; derivation that encapsulates the build process in a &lt;code&gt;nix build&lt;/code&gt; command.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;module&lt;/strong&gt; that exposes the app as a configurable system-level service that can be leveraged in integration checks with &lt;code&gt;nix flake check&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;With these things in place, activities that traditionally create overhead for developers (environment and deployment) are abstracted and standardized. And even though other tools solve similar problems, none of them achieve the universality of the Nix model. That&amp;rsquo;s because the most natural and complete description of software packaging is as pure functions over store paths. But in this post I&amp;rsquo;m focusing on convenience. The correctness of Nix, and the fact that correctness leads to convenience, are topics for a different post.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>The inordinate usefulness of Nix really sinks in when you realize that it allows you to define a single piece of unified infrastructure for handling all the different parts of the software lifecycle. Furthermore, this infrastructure doesn&rsquo;t even need to be project-specific. For a given class of projects, the &ldquo;holy grail&rdquo; Nix flake template defines all the following:</p>
<ol>
<li>All the <strong>dependencies</strong>, pinned in the <code>flake.lock</code> and updatable with <code>nix flake update</code>.</li>
<li>A <strong>dev environment</strong> accessible with <code>nix develop</code>.</li>
<li>A <strong>package</strong> derivation that encapsulates the build process in a <code>nix build</code> command.</li>
<li>A <strong>module</strong> that exposes the app as a configurable system-level service that can be leveraged in integration checks with <code>nix flake check</code>.</li>
</ol>
<p>With these things in place, activities that traditionally create overhead for developers (environment and deployment) are abstracted and standardized. And even though other tools solve similar problems, none of them achieve the universality of the Nix model. That&rsquo;s because the most natural and complete description of software packaging is as pure functions over store paths. But in this post I&rsquo;m focusing on convenience. The correctness of Nix, and the fact that correctness leads to convenience, are topics for a different post.</p>
<p>I&rsquo;ve released some Nix infrastructure for Phoenix in a repo called <a href="https://github.com/roriholm/phoeNIX">PhoeNIX</a>. It&rsquo;s constructed, as is tradition, by copy-pasting from someone smarter (shoutout <a href="https://www.zekedou.live/">Zeke Dou</a> and <a href="https://github.com/jurraca">jurraca</a>) and then extending to meet my needs. I haven&rsquo;t seen any other flake templates for Phoenix that hit all 4 of my holy grail elements, so I hope this repo is useful for someone.</p>
<p>If you&rsquo;ve got a <a href="/posts/setting-up-deploy-rs">deploy-rs setup</a> for pushing system closures, then you can achieve a workflow that makes other DevOps, Cloud, and Containerization solutions look somewhat inadequate.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
