<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Binary Strolls</title>
    <subtitle><![CDATA[Blag]]></subtitle>
    <link href="https://blog.dbalan.in/atom.xml" rel="self" />
    <link href="https://blog.dbalan.in" />
    <id>https://blog.dbalan.in/atom.xml</id>
    <author>
        <name>Dhananjay Balan</name>
        
        <email>blog@dbalan.in</email>
        
    </author>
    <updated>2024-03-25T00:00:00Z</updated>
    <entry>
    <title>Bootstrapping a Mac with Nix</title>
    <link href="https://blog.dbalan.in/blog/2024/03/25/boostrap-a-macos-machine-with-nix/index.html" />
    <id>https://blog.dbalan.in/blog/2024/03/25/boostrap-a-macos-machine-with-nix/index.html</id>
    <published>2024-03-25T00:00:00Z</published>
    <updated>2024-03-25T00:00:00Z</updated>
    <summary type="html"><![CDATA[<article class="group">
  <h1><a href="/blog/2024/03/25/boostrap-a-macos-machine-with-nix/index.html">Bootstrapping a Mac with Nix</a></h1>
  <div class="postmeta">
    <div id="date">March 25, 2024</div>
    
    <div id="tags">Posted in <a title="All pages tagged &#39;nix&#39;." href="/tags/nix.html" rel="tag">nix</a>, <a title="All pages tagged &#39;macos&#39;." href="/tags/macos.html" rel="tag">macos</a>, <a title="All pages tagged &#39;apple&#39;." href="/tags/apple.html" rel="tag">apple</a>, <a title="All pages tagged &#39;nix-darwin&#39;." href="/tags/nix-darwin.html" rel="tag">nix-darwin</a>, <a title="All pages tagged &#39;brew&#39;." href="/tags/brew.html" rel="tag">brew</a>, <a title="All pages tagged &#39;homebrew&#39;." href="/tags/homebrew.html" rel="tag">homebrew</a></div>
    
  </div>

  <section><p>With <a href="https://github.com/LnL7/nix-darwin">nix-darwin</a> and
<a href="https://github.com/nix-community/home-manager">home-manager</a> it is possible to
manage almost all of a mac configuration declaratively. So when I got my new
Macbook I was pretty sure this is the way to go. Unfortunately, the bootstrap
is a bit involved. These are my notes from the process, which hopefully
serves as a tutorial.</p>
<h2 id="installing-dependencies">Installing dependencies</h2>
<p>We need to install some software manually before we can go full steam with
configurations stored as nix files, the primary one being <code>nix</code> itself.</p>
<p>Install nix with the <a href="https://install.determinate.systems/">determinate systems nix installer</a>, it comes with sensible defaults and a nicer uninstaller.</p>
<p>Unfortunately, the GUI installer installs <code>x86_64</code> version of nix, so I had to use <code>curl |sh</code> for my <code>aarch64</code> Macbook.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="ex">curl</span> <span class="at">--proto</span> <span class="st">&#39;=https&#39;</span> <span class="at">--tlsv1.2</span> <span class="at">-sSf</span> <span class="at">-L</span> https://install.determinate.systems/nix <span class="kw">|</span> <span class="fu">sh</span> <span class="at">-s</span> <span class="at">--</span> install</span></code></pre></div>
<p><img src="/images/nix-install.png" /></p>
<p>If you haven’t already, also install <code>Xcode tools</code> with <code>xcode-select --install</code></p>
<h2 id="generating-initial-configurations">Generating initial configurations</h2>
<p>We are going to use <code>nix-darwin</code> to keep a system wide configuration, which
would represent packages that are installed, configuration for packages and
configuration like shell aliases, files etc.</p>
<p>nix-darwin has support for both classic <code>configuration.nix</code> tied to a nix-channel
as well as flakes, I chose the latter as it allows more finer control over dependency versions<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a>.</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="ex">%</span> nix flake init <span class="at">-t</span> nix-darwin</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="ex">wrote:</span> /Users/db/code/private/config/flake.nix</span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="co"># replace the hostname</span></span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="ex">%</span> sed <span class="at">-i</span> <span class="st">&#39;&#39;</span> <span class="st">&quot;s/simple/</span><span class="va">$(</span><span class="ex">scutil</span> <span class="at">--get</span> LocalHostName<span class="va">)</span><span class="st">/&quot;</span> flake.nix</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a><span class="co"># Add to revision control</span></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a><span class="fu">git</span> init</span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a><span class="fu">git</span> add flake.nix</span></code></pre></div>
<p>This generates an example flake file, with some boilerplate code to get started.</p>
<p>With some light editing:</p>
<ol type="1">
<li>Moved the configuration to its on own file <code>configuration.nix</code>, and added it to git tree<a href="#fn2" class="footnote-ref" id="fnref2" role="doc-noteref"><sup>2</sup></a>.</li>
<li>The appropriate <code>hostPlatform</code> for your mac. <code>nixpkgs.hostPlatform = "aarch64-darwin";</code></li>
<li>Set the home directory path <code>users.users.dj.home = "/Users/dj";</code></li>
</ol>
<p>We end up with</p>
<h3 id="flake.nix">flake.nix</h3>
<div class="sourceCode" id="cb3"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>  <span class="va">description</span> <span class="op">=</span> <span class="st">&quot;System flake configuration file&quot;</span><span class="op">;</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a>  <span class="va">inputs</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a>    <span class="va">nixpkgs</span>.<span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:NixOS/nixpkgs/nixpkgs-unstable&quot;</span><span class="op">;</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a>    <span class="va">nix-darwin</span>.<span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:LnL7/nix-darwin&quot;</span><span class="op">;</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a>    <span class="va">nix-darwin</span>.<span class="va">inputs</span>.<span class="va">nixpkgs</span>.<span class="va">follows</span> <span class="op">=</span> <span class="st">&quot;nixpkgs&quot;</span><span class="op">;</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a>  <span class="op">};</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a>  <span class="va">outputs</span> <span class="op">=</span> inputs@<span class="op">{</span> <span class="va">self</span><span class="op">,</span> <span class="va">nix-darwin</span><span class="op">,</span> <span class="va">nixpkgs</span> <span class="op">}</span>: <span class="op">{</span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a>    <span class="co"># Build darwin flake using:</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a>    <span class="co"># $ darwin-rebuild build --flake .#MacBook-Pro</span></span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a>    <span class="va">darwinConfigurations</span>.<span class="st">&quot;MacBook-Pro&quot;</span> <span class="op">=</span></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a>      nix<span class="op">-</span>darwin<span class="op">.</span>lib<span class="op">.</span>darwinSystem <span class="op">{</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a>        <span class="va">modules</span> <span class="op">=</span> <span class="op">[</span> <span class="ss">./configuration.nix</span> <span class="op">];</span></span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a>      <span class="op">};</span></span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a>    <span class="co"># Expose the package set, including overlays, for convenience.</span></span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a>    <span class="va">darwinPackages</span> <span class="op">=</span> self<span class="op">.</span>darwinConfigurations<span class="op">.</span><span class="st">&quot;MacBook-Pro&quot;</span><span class="op">.</span>pkgs<span class="op">;</span></span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a>  <span class="op">};</span></span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<h3 id="configuration.nix">configuration.nix</h3>
<div class="sourceCode" id="cb4"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="op">{</span> <span class="va">config</span><span class="op">,</span> <span class="va">lib</span><span class="op">,</span> <span class="va">pkgs</span><span class="op">,</span> <span class="op">...</span> <span class="op">}</span>:</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a>  <span class="co"># List packages installed in system profile. To search by name, run:</span></span>
<span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a>  <span class="co"># $ nix-env -qaP | grep wget</span></span>
<span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a>  <span class="va">environment</span>.<span class="va">systemPackages</span> <span class="op">=</span> <span class="kw">with</span> pkgs<span class="op">;</span> <span class="op">[</span></span>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a>  <span class="op">];</span></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a>  <span class="va">users</span>.<span class="va">users</span>.<span class="va">dj</span>.<span class="va">home</span> <span class="op">=</span> <span class="st">&quot;/Users/dj&quot;</span><span class="op">;</span></span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a>  <span class="co"># Auto upgrade nix package and the daemon service.</span></span>
<span id="cb4-11"><a href="#cb4-11" aria-hidden="true" tabindex="-1"></a>  <span class="va">services</span>.<span class="va">nix-daemon</span>.<span class="va">enable</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb4-12"><a href="#cb4-12" aria-hidden="true" tabindex="-1"></a>  <span class="co"># nix.package = pkgs.nix;</span></span>
<span id="cb4-13"><a href="#cb4-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-14"><a href="#cb4-14" aria-hidden="true" tabindex="-1"></a>  <span class="co"># Necessary for using flakes on this system.</span></span>
<span id="cb4-15"><a href="#cb4-15" aria-hidden="true" tabindex="-1"></a>  <span class="va">nix</span>.<span class="va">settings</span>.<span class="va">experimental-features</span> <span class="op">=</span> <span class="st">&quot;nix-command flakes&quot;</span><span class="op">;</span></span>
<span id="cb4-16"><a href="#cb4-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-17"><a href="#cb4-17" aria-hidden="true" tabindex="-1"></a>  <span class="co"># Create /etc/zshrc that loads the nix-darwin environment.</span></span>
<span id="cb4-18"><a href="#cb4-18" aria-hidden="true" tabindex="-1"></a>  <span class="va">programs</span>.<span class="va">zsh</span>.<span class="va">enable</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span> <span class="co"># default shell on catalina</span></span>
<span id="cb4-19"><a href="#cb4-19" aria-hidden="true" tabindex="-1"></a>  <span class="co"># programs.fish.enable = true;</span></span>
<span id="cb4-20"><a href="#cb4-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-21"><a href="#cb4-21" aria-hidden="true" tabindex="-1"></a>  <span class="co"># Used for backwards compatibility, please read the changelog before changing.</span></span>
<span id="cb4-22"><a href="#cb4-22" aria-hidden="true" tabindex="-1"></a>  <span class="co"># $ darwin-rebuild changelog</span></span>
<span id="cb4-23"><a href="#cb4-23" aria-hidden="true" tabindex="-1"></a>  <span class="va">system</span>.<span class="va">stateVersion</span> <span class="op">=</span> <span class="dv">3</span><span class="op">;</span></span>
<span id="cb4-24"><a href="#cb4-24" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-25"><a href="#cb4-25" aria-hidden="true" tabindex="-1"></a>  <span class="va">nix</span>.<span class="va">configureBuildUsers</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb4-26"><a href="#cb4-26" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-27"><a href="#cb4-27" aria-hidden="true" tabindex="-1"></a>  <span class="co"># The platform the configuration will be used on.</span></span>
<span id="cb4-28"><a href="#cb4-28" aria-hidden="true" tabindex="-1"></a>  <span class="va">nixpkgs</span>.<span class="va">hostPlatform</span> <span class="op">=</span> <span class="st">&quot;aarch64-darwin&quot;</span><span class="op">;</span></span>
<span id="cb4-29"><a href="#cb4-29" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<p>Its time to bootstrap the system with <code>nix-darwin</code>!</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="ex">%</span> nix run nix-darwin <span class="at">--</span> switch <span class="at">--flake</span> ~/.config/nix-darwin</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a><span class="ex">building</span> the system configuration...</span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a><span class="ex">[1/38/42</span> built, 227 copied <span class="er">(</span><span class="ex">1406.7/1407.6</span> MiB<span class="kw">)</span><span class="ex">,</span> 237.3 MiB DL] building darwin-uninstaller <span class="er">(</span><span class="ex">fixupPhase</span><span class="kw">)</span><span class="bu">:</span> str</span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a><span class="ex">Password:</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a><span class="ex">setting</span> up /run via /etc/synthetic.conf...</span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a><span class="ex">user</span> defaults...</span>
<span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a><span class="ex">setting</span> up user launchd services...</span>
<span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a><span class="ex">setting</span> up /Applications/Nix Apps...</span>
<span id="cb5-9"><a href="#cb5-9" aria-hidden="true" tabindex="-1"></a><span class="ex">setting</span> up pam...</span>
<span id="cb5-10"><a href="#cb5-10" aria-hidden="true" tabindex="-1"></a><span class="ex">applying</span> patches...</span>
<span id="cb5-11"><a href="#cb5-11" aria-hidden="true" tabindex="-1"></a><span class="ex">setting</span> up /etc...</span>
<span id="cb5-12"><a href="#cb5-12" aria-hidden="true" tabindex="-1"></a><span class="ex">system</span> defaults...</span>
<span id="cb5-13"><a href="#cb5-13" aria-hidden="true" tabindex="-1"></a><span class="ex">setting</span> up launchd services...</span>
<span id="cb5-14"><a href="#cb5-14" aria-hidden="true" tabindex="-1"></a><span class="ex">creating</span> service org.nixos.activate-system</span>
<span id="cb5-15"><a href="#cb5-15" aria-hidden="true" tabindex="-1"></a><span class="ex">reloading</span> service org.nixos.nix-daemon</span>
<span id="cb5-16"><a href="#cb5-16" aria-hidden="true" tabindex="-1"></a><span class="ex">reloading</span> nix-daemon...</span>
<span id="cb5-17"><a href="#cb5-17" aria-hidden="true" tabindex="-1"></a><span class="ex">waiting</span> for nix-daemon</span>
<span id="cb5-18"><a href="#cb5-18" aria-hidden="true" tabindex="-1"></a><span class="ex">waiting</span> for nix-daemon</span>
<span id="cb5-19"><a href="#cb5-19" aria-hidden="true" tabindex="-1"></a><span class="ex">configuring</span> networking...</span>
<span id="cb5-20"><a href="#cb5-20" aria-hidden="true" tabindex="-1"></a><span class="ex">setting</span> nvram variables...</span></code></pre></div>
<p>During the bootstrap, <code>nix-darwin</code> installs the command <code>darwin-rebuild</code>, subsequent rebuilds should use <code>darwin-rebuild</code>.</p>
<p>Both <code>nix-darwin</code> and <code>darwin-rebuild</code> follows same semantics as <code>nixos-rebuild</code>, <code>test</code> for test activation, <code>build</code> for only building the configuration, <code>switch</code> for commit and activate etc.</p>
<h2 id="install-some-packages">Install some packages</h2>
<p>I have a set of packages that I like to have available system-wide (for all users). Add those to
<code>environment.systemPackages</code> in <code>configuration.nix</code>, which gives us:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="op">{</span> <span class="va">config</span><span class="op">,</span> <span class="va">lib</span><span class="op">,</span> <span class="va">pkgs</span><span class="op">,</span> <span class="op">...</span> <span class="op">}</span>:</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a>  <span class="co"># List packages installed in system profile. To search by name, run:</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a>  <span class="co"># $ nix-env -qaP | grep wget</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a>  <span class="va">environment</span>.<span class="va">systemPackages</span> <span class="op">=</span> <span class="kw">with</span> pkgs<span class="op">;</span> <span class="op">[</span></span>
<span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a>    vim</span>
<span id="cb6-8"><a href="#cb6-8" aria-hidden="true" tabindex="-1"></a>    curl</span>
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a>    gitAndTools<span class="op">.</span>gitFull</span>
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a>    mg</span>
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a>    mosh</span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a>  <span class="op">];</span></span>
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a>...</span></code></pre></div>
<p>Activate with <code>darwin-rebuild switch --flake ~/path-to-config-directory</code></p>
<h2 id="home-manager">Home Manager</h2>
<p><a href="https://github.com/nix-community/home-manager">home-manager</a> is a nix community project for managing user environments, it comes with a <a href="https://home-manager-options.extranix.com/">tone of module for configuring more day-to-day user facing programs</a>, for e.g the git module for configuring, well git.</p>
<div class="sourceCode" id="cb7"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>programs<span class="op">.</span>git = <span class="op">{</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>  <span class="va">enable</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a>  <span class="va">extraConfig</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a>    <span class="va">github</span>.<span class="va">user</span> <span class="op">=</span> <span class="st">&quot;&lt;user&gt;&quot;</span><span class="op">;</span></span>
<span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a>    <span class="va">init</span> <span class="op">=</span> <span class="op">{</span> <span class="va">defaultBranch</span> <span class="op">=</span> <span class="st">&quot;trunk&quot;</span><span class="op">;</span> <span class="op">};</span></span>
<span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a>    <span class="va">diff</span> <span class="op">=</span> <span class="op">{</span> <span class="va">external</span> <span class="op">=</span> <span class="st">&quot;</span><span class="sc">${</span>pkgs<span class="op">.</span>difftastic<span class="sc">}</span><span class="st">/bin/difft&quot;</span><span class="op">;</span> <span class="op">};</span></span>
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a>  <span class="op">};</span></span>
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a><span class="op">}</span>;</span></code></pre></div>
<p>Install <code>home-manager</code> with flakes,</p>
<ol type="1">
<li>Add a flake input in the inputs section</li>
</ol>
<div class="sourceCode" id="cb8"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>home<span class="op">-</span>manager = <span class="op">{</span></span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>    <span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:nix-community/home-manager&quot;</span><span class="op">;</span></span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>    <span class="va">inputs</span>.<span class="va">nixpkgs</span>.<span class="va">follows</span> <span class="op">=</span> <span class="st">&quot;nixpkgs-unstable&quot;</span><span class="op">;</span></span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a><span class="op">}</span>;</span></code></pre></div>
<ol start="2" type="1">
<li>And add the module to the <code>modules</code> section</li>
</ol>
<div class="sourceCode" id="cb9"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>home<span class="op">-</span>manager<span class="op">.</span>darwinModules<span class="op">.</span>home<span class="op">-</span>manager <span class="op">{</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>  <span class="co"># `home-manager` config</span></span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a>  <span class="va">home-manager</span>.<span class="va">useGlobalPkgs</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a>  <span class="va">home-manager</span>.<span class="va">useUserPackages</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a>  <span class="va">home-manager</span>.<span class="va">users</span>.<span class="va">db</span> <span class="op">=</span> <span class="bu">import</span> <span class="ss">./home.nix</span><span class="op">;</span></span>
<span id="cb9-6"><a href="#cb9-6" aria-hidden="true" tabindex="-1"></a><span class="op">}</span>;</span></code></pre></div>
<p>I choose to keep the home configuration in a separate file, <code>home.nix</code>.</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="op">{</span> <span class="va">config</span><span class="op">,</span> <span class="va">lib</span><span class="op">,</span> <span class="va">pkgs</span><span class="op">,</span> <span class="op">...</span> <span class="op">}</span>:</span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a>  <span class="va">home</span>.<span class="va">stateVersion</span> <span class="op">=</span> <span class="st">&quot;23.11&quot;</span><span class="op">;</span></span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a>  <span class="va">programs</span>.<span class="va">git</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a>    <span class="va">enable</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a>    <span class="va">userName</span> <span class="op">=</span> <span class="st">&quot;name&quot;</span><span class="op">;</span></span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a>    <span class="va">userEmail</span> <span class="op">=</span> <span class="st">&quot;mail@example.org&quot;</span><span class="op">;</span></span>
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true" tabindex="-1"></a>    <span class="va">extraConfig</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb10-11"><a href="#cb10-11" aria-hidden="true" tabindex="-1"></a>      <span class="va">github</span>.<span class="va">user</span> <span class="op">=</span> <span class="st">&quot;&lt;user&gt;&quot;</span><span class="op">;</span></span>
<span id="cb10-12"><a href="#cb10-12" aria-hidden="true" tabindex="-1"></a>      <span class="va">init</span> <span class="op">=</span> <span class="op">{</span> <span class="va">defaultBranch</span> <span class="op">=</span> <span class="st">&quot;trunk&quot;</span><span class="op">;</span> <span class="op">};</span></span>
<span id="cb10-13"><a href="#cb10-13" aria-hidden="true" tabindex="-1"></a>      <span class="va">diff</span> <span class="op">=</span> <span class="op">{</span> <span class="va">external</span> <span class="op">=</span> <span class="st">&quot;</span><span class="sc">${</span>pkgs<span class="op">.</span>difftastic<span class="sc">}</span><span class="st">/bin/difft&quot;</span><span class="op">;</span> <span class="op">};</span></span>
<span id="cb10-14"><a href="#cb10-14" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span>
<span id="cb10-15"><a href="#cb10-15" aria-hidden="true" tabindex="-1"></a>  <span class="op">};</span></span>
<span id="cb10-16"><a href="#cb10-16" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<p>Also the updated <code>flake.nix</code> is now</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a>  <span class="va">description</span> <span class="op">=</span> <span class="st">&quot;System flake configuration file&quot;</span><span class="op">;</span></span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a>  <span class="va">inputs</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a>    <span class="va">nixpkgs</span>.<span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:NixOS/nixpkgs/nixpkgs-unstable&quot;</span><span class="op">;</span></span>
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a>    <span class="va">nixpkgs-unstable</span>.<span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:NixOS/nixpkgs/nixpkgs-unstable&quot;</span><span class="op">;</span></span>
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a>    <span class="va">nix-darwin</span>.<span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:LnL7/nix-darwin&quot;</span><span class="op">;</span></span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a>    <span class="va">nix-darwin</span>.<span class="va">inputs</span>.<span class="va">nixpkgs</span>.<span class="va">follows</span> <span class="op">=</span> <span class="st">&quot;nixpkgs&quot;</span><span class="op">;</span></span>
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a>    <span class="va">home-manager</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a>      <span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:nix-community/home-manager&quot;</span><span class="op">;</span></span>
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a>      <span class="va">inputs</span>.<span class="va">nixpkgs</span>.<span class="va">follows</span> <span class="op">=</span> <span class="st">&quot;nixpkgs&quot;</span><span class="op">;</span></span>
<span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span>
<span id="cb11-14"><a href="#cb11-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-15"><a href="#cb11-15" aria-hidden="true" tabindex="-1"></a>  <span class="op">};</span></span>
<span id="cb11-16"><a href="#cb11-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-17"><a href="#cb11-17" aria-hidden="true" tabindex="-1"></a>  <span class="va">outputs</span> <span class="op">=</span> inputs@<span class="op">{</span> <span class="va">self</span><span class="op">,</span> <span class="va">nix-darwin</span><span class="op">,</span> <span class="va">nixpkgs</span><span class="op">,</span> <span class="va">home-manager</span><span class="op">,</span> <span class="va">nix-homebrew</span></span>
<span id="cb11-18"><a href="#cb11-18" aria-hidden="true" tabindex="-1"></a>    <span class="op">,</span> <span class="va">homebrew-core</span><span class="op">,</span> <span class="va">homebrew-cask</span><span class="op">,</span> <span class="va">homebrew-bundle</span><span class="op">,</span> <span class="op">...</span> <span class="op">}</span>:</span>
<span id="cb11-19"><a href="#cb11-19" aria-hidden="true" tabindex="-1"></a>    <span class="op">{</span></span>
<span id="cb11-20"><a href="#cb11-20" aria-hidden="true" tabindex="-1"></a>      <span class="co"># Build darwin flake using:</span></span>
<span id="cb11-21"><a href="#cb11-21" aria-hidden="true" tabindex="-1"></a>      <span class="co"># $ darwin-rebuild build --flake .#MacBook-Pro</span></span>
<span id="cb11-22"><a href="#cb11-22" aria-hidden="true" tabindex="-1"></a>      <span class="va">darwinConfigurations</span>.<span class="st">&quot;MacBook-Pro&quot;</span> <span class="op">=</span></span>
<span id="cb11-23"><a href="#cb11-23" aria-hidden="true" tabindex="-1"></a>        nix<span class="op">-</span>darwin<span class="op">.</span>lib<span class="op">.</span>darwinSystem <span class="op">{</span></span>
<span id="cb11-24"><a href="#cb11-24" aria-hidden="true" tabindex="-1"></a>          <span class="va">modules</span> <span class="op">=</span> <span class="op">[</span></span>
<span id="cb11-25"><a href="#cb11-25" aria-hidden="true" tabindex="-1"></a>            <span class="ss">./configuration.nix</span></span>
<span id="cb11-26"><a href="#cb11-26" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-27"><a href="#cb11-27" aria-hidden="true" tabindex="-1"></a>            home-manager<span class="op">.</span>darwinModules<span class="op">.</span>home-manager</span>
<span id="cb11-28"><a href="#cb11-28" aria-hidden="true" tabindex="-1"></a>            <span class="op">{</span></span>
<span id="cb11-29"><a href="#cb11-29" aria-hidden="true" tabindex="-1"></a>              <span class="co"># `home-manager` config</span></span>
<span id="cb11-30"><a href="#cb11-30" aria-hidden="true" tabindex="-1"></a>              <span class="va">home-manager</span>.<span class="va">useGlobalPkgs</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb11-31"><a href="#cb11-31" aria-hidden="true" tabindex="-1"></a>              <span class="va">home-manager</span>.<span class="va">useUserPackages</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb11-32"><a href="#cb11-32" aria-hidden="true" tabindex="-1"></a>              <span class="va">home-manager</span>.<span class="va">users</span>.<span class="va">db</span> <span class="op">=</span> <span class="bu">import</span> <span class="ss">./home.nix</span><span class="op">;</span></span>
<span id="cb11-33"><a href="#cb11-33" aria-hidden="true" tabindex="-1"></a>            <span class="op">}</span></span>
<span id="cb11-34"><a href="#cb11-34" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-35"><a href="#cb11-35" aria-hidden="true" tabindex="-1"></a>          <span class="op">];</span></span>
<span id="cb11-36"><a href="#cb11-36" aria-hidden="true" tabindex="-1"></a>        <span class="op">};</span></span>
<span id="cb11-37"><a href="#cb11-37" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb11-38"><a href="#cb11-38" aria-hidden="true" tabindex="-1"></a>      <span class="co"># Expose the package set, including overlays, for convenience.</span></span>
<span id="cb11-39"><a href="#cb11-39" aria-hidden="true" tabindex="-1"></a>      <span class="va">darwinPackages</span> <span class="op">=</span></span>
<span id="cb11-40"><a href="#cb11-40" aria-hidden="true" tabindex="-1"></a>        self<span class="op">.</span>darwinConfigurations<span class="op">.</span><span class="st">&quot;MacBook-Pro&quot;</span><span class="op">.</span>pkgs<span class="op">;</span></span>
<span id="cb11-41"><a href="#cb11-41" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span>
<span id="cb11-42"><a href="#cb11-42" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<p>If you get an error <code>Error: HOME is set to "/Users/&lt;username&gt;" but we expect "/var/empty"</code>, make sure you have set <code>users.users.&lt;username&gt;.home</code> in configuration.nix.</p>
<h2 id="manage-homebrew-applications">Manage homebrew applications</h2>
<p>Sadly, nix still has some catching up to do with mac compatibility, biggest gripe for me was <a href="https://github.com/LnL7/nix-darwin/issues/214">accessing GUI apps with spotlight seems to need some workarounds</a>. Luckily brew solves this and we can just install applications with brew, still managed by nix.</p>
<p><code>nix-darwin</code> can declaratively manage brew packages, however we need <a href="https://github.com/zhaofengli/nix-homebrew">nix-homebrew</a> to install brew itself and manage the taps declaratively.</p>
<p>Grab nix-homebrew using flakes, and also add the taps itself as inputs, this maybe the most underrated flakes feature. We can pin the taps to a specific version!</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>inputs = <span class="op">{</span></span>
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>    <span class="va">nix-homebrew</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a>      <span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:zhaofengli-wip/nix-homebrew&quot;</span><span class="op">;</span></span>
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a>      <span class="va">inputs</span>.<span class="va">nixpkgs</span>.<span class="va">follows</span> <span class="op">=</span> <span class="st">&quot;nixpkgs-unstable&quot;</span><span class="op">;</span></span>
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span>
<span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a>    <span class="va">homebrew-core</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a>      <span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:homebrew/homebrew-core&quot;</span><span class="op">;</span></span>
<span id="cb12-9"><a href="#cb12-9" aria-hidden="true" tabindex="-1"></a>      <span class="va">flake</span> <span class="op">=</span> <span class="cn">false</span><span class="op">;</span></span>
<span id="cb12-10"><a href="#cb12-10" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span>
<span id="cb12-11"><a href="#cb12-11" aria-hidden="true" tabindex="-1"></a>    <span class="va">homebrew-cask</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb12-12"><a href="#cb12-12" aria-hidden="true" tabindex="-1"></a>      <span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:homebrew/homebrew-cask&quot;</span><span class="op">;</span></span>
<span id="cb12-13"><a href="#cb12-13" aria-hidden="true" tabindex="-1"></a>      <span class="va">flake</span> <span class="op">=</span> <span class="cn">false</span><span class="op">;</span></span>
<span id="cb12-14"><a href="#cb12-14" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span>
<span id="cb12-15"><a href="#cb12-15" aria-hidden="true" tabindex="-1"></a>    <span class="va">homebrew-bundle</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb12-16"><a href="#cb12-16" aria-hidden="true" tabindex="-1"></a>      <span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:homebrew/homebrew-bundle&quot;</span><span class="op">;</span></span>
<span id="cb12-17"><a href="#cb12-17" aria-hidden="true" tabindex="-1"></a>      <span class="va">flake</span> <span class="op">=</span> <span class="cn">false</span><span class="op">;</span></span>
<span id="cb12-18"><a href="#cb12-18" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span></code></pre></div>
<p>.. and import the module into the system configuration.</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>nix<span class="op">-</span>homebrew<span class="op">.</span>darwinModules<span class="op">.</span>nix<span class="op">-</span>homebrew</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a>  <span class="va">nix-homebrew</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a>    <span class="va">enable</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a>    <span class="co"># Apple Silicon Only: Also install Homebrew under the default Intel prefix for Rosetta 2</span></span>
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a>    <span class="va">enableRosetta</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a>    <span class="va">user</span> <span class="op">=</span> <span class="st">&quot;username&quot;</span><span class="op">;</span></span>
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb13-9"><a href="#cb13-9" aria-hidden="true" tabindex="-1"></a>    <span class="va">taps</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb13-10"><a href="#cb13-10" aria-hidden="true" tabindex="-1"></a>      <span class="st">&quot;homebrew/homebrew-core&quot;</span> <span class="op">=</span> homebrew<span class="op">-</span>core<span class="op">;</span></span>
<span id="cb13-11"><a href="#cb13-11" aria-hidden="true" tabindex="-1"></a>      <span class="st">&quot;homebrew/homebrew-cask&quot;</span> <span class="op">=</span> homebrew<span class="op">-</span>cask<span class="op">;</span></span>
<span id="cb13-12"><a href="#cb13-12" aria-hidden="true" tabindex="-1"></a>      <span class="st">&quot;homebrew/homebrew-bundle&quot;</span> <span class="op">=</span> homebrew<span class="op">-</span>bundle<span class="op">;</span></span>
<span id="cb13-13"><a href="#cb13-13" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span>
<span id="cb13-14"><a href="#cb13-14" aria-hidden="true" tabindex="-1"></a>    <span class="va">mutableTaps</span> <span class="op">=</span> <span class="cn">false</span><span class="op">;</span></span>
<span id="cb13-15"><a href="#cb13-15" aria-hidden="true" tabindex="-1"></a>  <span class="op">};</span></span>
<span id="cb13-16"><a href="#cb13-16" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<p>The package installations are itself managed by nix-darwin, using <code>homebrew.*</code> options.</p>
<div class="sourceCode" id="cb14"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>homebrew = <span class="op">{</span></span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a>  <span class="va">enable</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a>  <span class="va">global</span>.<span class="va">autoIpdate</span> <span class="op">=</span> <span class="cn">false</span><span class="op">;</span></span>
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a>  <span class="va">casks</span> <span class="op">=</span> <span class="op">[</span> <span class="st">&quot;kitty&quot;</span> <span class="op">];</span></span>
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a><span class="op">}</span>;</span></code></pre></div>
<h2 id="fin">Fin!</h2>
<p>If you have followed through all of the above, like me, you should have a mac with almost everything configured declaratively, using nix.</p>
<p>Further customizations options can be found in</p>
<ul>
<li><a href="https://daiderd.com/nix-darwin/manual/index.html">nix-darwin options search</a>, you could also use <code>man configuration.nix</code></li>
<li><a href="https://home-manager-options.extranix.com/">Home manager option search</a></li>
</ul>
<p>This setup helps me share configuration with my other machines; they are just an <code>import</code> away! However this bootstrapping is neither simple nor short, that’s definitly something to improve.</p>
<h2 id="final-configuration-files">Final configuration files</h2>
<details>
<summary>
flake.nix
</summary>
<div class="sourceCode" id="cb15"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>  <span class="va">description</span> <span class="op">=</span> <span class="st">&quot;System flake configuration file&quot;</span><span class="op">;</span></span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a>  <span class="va">inputs</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a>    <span class="va">nixpkgs</span>.<span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:NixOS/nixpkgs/nixpkgs-unstable&quot;</span><span class="op">;</span></span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a>    <span class="va">nixpkgs-unstable</span>.<span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:NixOS/nixpkgs/nixpkgs-unstable&quot;</span><span class="op">;</span></span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true" tabindex="-1"></a>    <span class="va">nix-darwin</span>.<span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:LnL7/nix-darwin&quot;</span><span class="op">;</span></span>
<span id="cb15-8"><a href="#cb15-8" aria-hidden="true" tabindex="-1"></a>    <span class="va">nix-darwin</span>.<span class="va">inputs</span>.<span class="va">nixpkgs</span>.<span class="va">follows</span> <span class="op">=</span> <span class="st">&quot;nixpkgs&quot;</span><span class="op">;</span></span>
<span id="cb15-9"><a href="#cb15-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-10"><a href="#cb15-10" aria-hidden="true" tabindex="-1"></a>    <span class="va">home-manager</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb15-11"><a href="#cb15-11" aria-hidden="true" tabindex="-1"></a>      <span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:nix-community/home-manager&quot;</span><span class="op">;</span></span>
<span id="cb15-12"><a href="#cb15-12" aria-hidden="true" tabindex="-1"></a>      <span class="va">inputs</span>.<span class="va">nixpkgs</span>.<span class="va">follows</span> <span class="op">=</span> <span class="st">&quot;nixpkgs&quot;</span><span class="op">;</span></span>
<span id="cb15-13"><a href="#cb15-13" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span>
<span id="cb15-14"><a href="#cb15-14" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-15"><a href="#cb15-15" aria-hidden="true" tabindex="-1"></a>    <span class="va">nix-homebrew</span> <span class="op">=</span> <span class="op">{</span> <span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:zhaofengli-wip/nix-homebrew&quot;</span><span class="op">;</span> <span class="op">};</span></span>
<span id="cb15-16"><a href="#cb15-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-17"><a href="#cb15-17" aria-hidden="true" tabindex="-1"></a>    <span class="va">homebrew-core</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb15-18"><a href="#cb15-18" aria-hidden="true" tabindex="-1"></a>      <span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:homebrew/homebrew-core&quot;</span><span class="op">;</span></span>
<span id="cb15-19"><a href="#cb15-19" aria-hidden="true" tabindex="-1"></a>      <span class="va">flake</span> <span class="op">=</span> <span class="cn">false</span><span class="op">;</span></span>
<span id="cb15-20"><a href="#cb15-20" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span>
<span id="cb15-21"><a href="#cb15-21" aria-hidden="true" tabindex="-1"></a>    <span class="va">homebrew-cask</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb15-22"><a href="#cb15-22" aria-hidden="true" tabindex="-1"></a>      <span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:homebrew/homebrew-cask&quot;</span><span class="op">;</span></span>
<span id="cb15-23"><a href="#cb15-23" aria-hidden="true" tabindex="-1"></a>      <span class="va">flake</span> <span class="op">=</span> <span class="cn">false</span><span class="op">;</span></span>
<span id="cb15-24"><a href="#cb15-24" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span>
<span id="cb15-25"><a href="#cb15-25" aria-hidden="true" tabindex="-1"></a>    <span class="va">homebrew-bundle</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb15-26"><a href="#cb15-26" aria-hidden="true" tabindex="-1"></a>      <span class="va">url</span> <span class="op">=</span> <span class="st">&quot;github:homebrew/homebrew-bundle&quot;</span><span class="op">;</span></span>
<span id="cb15-27"><a href="#cb15-27" aria-hidden="true" tabindex="-1"></a>      <span class="va">flake</span> <span class="op">=</span> <span class="cn">false</span><span class="op">;</span></span>
<span id="cb15-28"><a href="#cb15-28" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span>
<span id="cb15-29"><a href="#cb15-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-30"><a href="#cb15-30" aria-hidden="true" tabindex="-1"></a>  <span class="op">};</span></span>
<span id="cb15-31"><a href="#cb15-31" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-32"><a href="#cb15-32" aria-hidden="true" tabindex="-1"></a>  <span class="va">outputs</span> <span class="op">=</span> inputs@<span class="op">{</span> <span class="va">self</span><span class="op">,</span> <span class="va">nix-darwin</span><span class="op">,</span> <span class="va">nixpkgs</span><span class="op">,</span> <span class="va">home-manager</span><span class="op">,</span> <span class="va">nix-homebrew</span></span>
<span id="cb15-33"><a href="#cb15-33" aria-hidden="true" tabindex="-1"></a>    <span class="op">,</span> <span class="va">homebrew-core</span><span class="op">,</span> <span class="va">homebrew-cask</span><span class="op">,</span> <span class="va">homebrew-bundle</span><span class="op">,</span> <span class="op">...</span> <span class="op">}</span>: <span class="op">{</span></span>
<span id="cb15-34"><a href="#cb15-34" aria-hidden="true" tabindex="-1"></a>      <span class="co"># Build darwin flake using:</span></span>
<span id="cb15-35"><a href="#cb15-35" aria-hidden="true" tabindex="-1"></a>      <span class="co"># $ darwin-rebuild build --flake .#MacBook-Pro</span></span>
<span id="cb15-36"><a href="#cb15-36" aria-hidden="true" tabindex="-1"></a>      <span class="va">darwinConfigurations</span>.<span class="st">&quot;MacBook-Pro&quot;</span> <span class="op">=</span></span>
<span id="cb15-37"><a href="#cb15-37" aria-hidden="true" tabindex="-1"></a>        nix<span class="op">-</span>darwin<span class="op">.</span>lib<span class="op">.</span>darwinSystem <span class="op">{</span></span>
<span id="cb15-38"><a href="#cb15-38" aria-hidden="true" tabindex="-1"></a>          <span class="va">system</span> <span class="op">=</span> <span class="st">&quot;aarch64-darwin&quot;</span><span class="op">;</span></span>
<span id="cb15-39"><a href="#cb15-39" aria-hidden="true" tabindex="-1"></a>          <span class="va">modules</span> <span class="op">=</span> <span class="op">[</span></span>
<span id="cb15-40"><a href="#cb15-40" aria-hidden="true" tabindex="-1"></a>            <span class="ss">./configuration.nix</span></span>
<span id="cb15-41"><a href="#cb15-41" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-42"><a href="#cb15-42" aria-hidden="true" tabindex="-1"></a>            home-manager<span class="op">.</span>darwinModules<span class="op">.</span>home-manager</span>
<span id="cb15-43"><a href="#cb15-43" aria-hidden="true" tabindex="-1"></a>            <span class="op">{</span></span>
<span id="cb15-44"><a href="#cb15-44" aria-hidden="true" tabindex="-1"></a>              <span class="co"># `home-manager` config</span></span>
<span id="cb15-45"><a href="#cb15-45" aria-hidden="true" tabindex="-1"></a>              <span class="va">home-manager</span>.<span class="va">useGlobalPkgs</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb15-46"><a href="#cb15-46" aria-hidden="true" tabindex="-1"></a>              <span class="va">home-manager</span>.<span class="va">useUserPackages</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb15-47"><a href="#cb15-47" aria-hidden="true" tabindex="-1"></a>              <span class="va">home-manager</span>.<span class="va">users</span>.<span class="va">db</span> <span class="op">=</span> <span class="bu">import</span> <span class="ss">./home.nix</span><span class="op">;</span></span>
<span id="cb15-48"><a href="#cb15-48" aria-hidden="true" tabindex="-1"></a>            <span class="op">}</span></span>
<span id="cb15-49"><a href="#cb15-49" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-50"><a href="#cb15-50" aria-hidden="true" tabindex="-1"></a>            nix-homebrew<span class="op">.</span>darwinModules<span class="op">.</span>nix-homebrew</span>
<span id="cb15-51"><a href="#cb15-51" aria-hidden="true" tabindex="-1"></a>            <span class="op">{</span></span>
<span id="cb15-52"><a href="#cb15-52" aria-hidden="true" tabindex="-1"></a>              <span class="va">nix-homebrew</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb15-53"><a href="#cb15-53" aria-hidden="true" tabindex="-1"></a>                <span class="va">enable</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb15-54"><a href="#cb15-54" aria-hidden="true" tabindex="-1"></a>                <span class="co"># Apple Silicon Only: Also install Homebrew under the default Intel prefix for Rosetta 2</span></span>
<span id="cb15-55"><a href="#cb15-55" aria-hidden="true" tabindex="-1"></a>                <span class="va">enableRosetta</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb15-56"><a href="#cb15-56" aria-hidden="true" tabindex="-1"></a>                <span class="va">user</span> <span class="op">=</span> <span class="st">&quot;db&quot;</span><span class="op">;</span></span>
<span id="cb15-57"><a href="#cb15-57" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-58"><a href="#cb15-58" aria-hidden="true" tabindex="-1"></a>                <span class="va">taps</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb15-59"><a href="#cb15-59" aria-hidden="true" tabindex="-1"></a>                  <span class="st">&quot;homebrew/homebrew-core&quot;</span> <span class="op">=</span> homebrew<span class="op">-</span>core<span class="op">;</span></span>
<span id="cb15-60"><a href="#cb15-60" aria-hidden="true" tabindex="-1"></a>                  <span class="st">&quot;homebrew/homebrew-cask&quot;</span> <span class="op">=</span> homebrew<span class="op">-</span>cask<span class="op">;</span></span>
<span id="cb15-61"><a href="#cb15-61" aria-hidden="true" tabindex="-1"></a>                  <span class="st">&quot;homebrew/homebrew-bundle&quot;</span> <span class="op">=</span> homebrew<span class="op">-</span>bundle<span class="op">;</span></span>
<span id="cb15-62"><a href="#cb15-62" aria-hidden="true" tabindex="-1"></a>                <span class="op">};</span></span>
<span id="cb15-63"><a href="#cb15-63" aria-hidden="true" tabindex="-1"></a>                <span class="va">mutableTaps</span> <span class="op">=</span> <span class="cn">false</span><span class="op">;</span></span>
<span id="cb15-64"><a href="#cb15-64" aria-hidden="true" tabindex="-1"></a>              <span class="op">};</span></span>
<span id="cb15-65"><a href="#cb15-65" aria-hidden="true" tabindex="-1"></a>            <span class="op">}</span></span>
<span id="cb15-66"><a href="#cb15-66" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-67"><a href="#cb15-67" aria-hidden="true" tabindex="-1"></a>          <span class="op">];</span></span>
<span id="cb15-68"><a href="#cb15-68" aria-hidden="true" tabindex="-1"></a>        <span class="op">};</span></span>
<span id="cb15-69"><a href="#cb15-69" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb15-70"><a href="#cb15-70" aria-hidden="true" tabindex="-1"></a>      <span class="co"># Expose the package set, including overlays, for convenience.</span></span>
<span id="cb15-71"><a href="#cb15-71" aria-hidden="true" tabindex="-1"></a>      <span class="va">darwinPackages</span> <span class="op">=</span></span>
<span id="cb15-72"><a href="#cb15-72" aria-hidden="true" tabindex="-1"></a>        self<span class="op">.</span>darwinConfigurations<span class="op">.</span><span class="st">&quot;MacBook-Pro&quot;</span><span class="op">.</span>pkgs<span class="op">;</span></span>
<span id="cb15-73"><a href="#cb15-73" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span>
<span id="cb15-74"><a href="#cb15-74" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
</details>
<details>
<summary>
configuration.nix
</summary>
<div class="sourceCode" id="cb16"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="op">{</span> <span class="va">config</span><span class="op">,</span> <span class="va">lib</span><span class="op">,</span> <span class="va">pkgs</span><span class="op">,</span> <span class="op">...</span> <span class="op">}</span>:</span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a>  <span class="co"># List packages installed in system profile. To search by name, run:</span></span>
<span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a>  <span class="co"># $ nix-env -qaP | grep wget</span></span>
<span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a>  <span class="va">environment</span>.<span class="va">systemPackages</span> <span class="op">=</span> <span class="kw">with</span> pkgs<span class="op">;</span> <span class="op">[</span></span>
<span id="cb16-7"><a href="#cb16-7" aria-hidden="true" tabindex="-1"></a>    vim</span>
<span id="cb16-8"><a href="#cb16-8" aria-hidden="true" tabindex="-1"></a>    curl</span>
<span id="cb16-9"><a href="#cb16-9" aria-hidden="true" tabindex="-1"></a>    gitAndTools<span class="op">.</span>gitFull</span>
<span id="cb16-10"><a href="#cb16-10" aria-hidden="true" tabindex="-1"></a>    mg</span>
<span id="cb16-11"><a href="#cb16-11" aria-hidden="true" tabindex="-1"></a>    mosh</span>
<span id="cb16-12"><a href="#cb16-12" aria-hidden="true" tabindex="-1"></a>  <span class="op">];</span></span>
<span id="cb16-13"><a href="#cb16-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-14"><a href="#cb16-14" aria-hidden="true" tabindex="-1"></a>  <span class="va">homebrew</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb16-15"><a href="#cb16-15" aria-hidden="true" tabindex="-1"></a>    <span class="va">enable</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb16-16"><a href="#cb16-16" aria-hidden="true" tabindex="-1"></a>    <span class="va">global</span>.<span class="va">autoUpdate</span> <span class="op">=</span> <span class="cn">false</span><span class="op">;</span></span>
<span id="cb16-17"><a href="#cb16-17" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-18"><a href="#cb16-18" aria-hidden="true" tabindex="-1"></a>    <span class="va">casks</span> <span class="op">=</span> <span class="op">[</span> <span class="st">&quot;kitty&quot;</span> <span class="op">];</span></span>
<span id="cb16-19"><a href="#cb16-19" aria-hidden="true" tabindex="-1"></a>  <span class="op">};</span></span>
<span id="cb16-20"><a href="#cb16-20" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-21"><a href="#cb16-21" aria-hidden="true" tabindex="-1"></a>  <span class="va">users</span>.<span class="va">users</span>.<span class="va">db</span>.<span class="va">home</span> <span class="op">=</span> <span class="st">&quot;/Users/db&quot;</span><span class="op">;</span></span>
<span id="cb16-22"><a href="#cb16-22" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-23"><a href="#cb16-23" aria-hidden="true" tabindex="-1"></a>  <span class="co"># Auto upgrade nix package and the daemon service.</span></span>
<span id="cb16-24"><a href="#cb16-24" aria-hidden="true" tabindex="-1"></a>  <span class="va">services</span>.<span class="va">nix-daemon</span>.<span class="va">enable</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb16-25"><a href="#cb16-25" aria-hidden="true" tabindex="-1"></a>  <span class="co"># nix.package = pkgs.nix;</span></span>
<span id="cb16-26"><a href="#cb16-26" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-27"><a href="#cb16-27" aria-hidden="true" tabindex="-1"></a>  <span class="co"># Necessary for using flakes on this system.</span></span>
<span id="cb16-28"><a href="#cb16-28" aria-hidden="true" tabindex="-1"></a>  <span class="va">nix</span>.<span class="va">settings</span>.<span class="va">experimental-features</span> <span class="op">=</span> <span class="st">&quot;nix-command flakes&quot;</span><span class="op">;</span></span>
<span id="cb16-29"><a href="#cb16-29" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-30"><a href="#cb16-30" aria-hidden="true" tabindex="-1"></a>  <span class="co"># Create /etc/zshrc that loads the nix-darwin environment.</span></span>
<span id="cb16-31"><a href="#cb16-31" aria-hidden="true" tabindex="-1"></a>  <span class="va">programs</span>.<span class="va">zsh</span>.<span class="va">enable</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span> <span class="co"># default shell on catalina</span></span>
<span id="cb16-32"><a href="#cb16-32" aria-hidden="true" tabindex="-1"></a>  <span class="co"># programs.fish.enable = true;</span></span>
<span id="cb16-33"><a href="#cb16-33" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-34"><a href="#cb16-34" aria-hidden="true" tabindex="-1"></a>  <span class="co"># Used for backwards compatibility, please read the changelog before changing.</span></span>
<span id="cb16-35"><a href="#cb16-35" aria-hidden="true" tabindex="-1"></a>  <span class="co"># $ darwin-rebuild changelog</span></span>
<span id="cb16-36"><a href="#cb16-36" aria-hidden="true" tabindex="-1"></a>  <span class="va">system</span>.<span class="va">stateVersion</span> <span class="op">=</span> <span class="dv">3</span><span class="op">;</span></span>
<span id="cb16-37"><a href="#cb16-37" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-38"><a href="#cb16-38" aria-hidden="true" tabindex="-1"></a>  <span class="va">nix</span>.<span class="va">configureBuildUsers</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb16-39"><a href="#cb16-39" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb16-40"><a href="#cb16-40" aria-hidden="true" tabindex="-1"></a>  <span class="co"># The platform the configuration will be used on.</span></span>
<span id="cb16-41"><a href="#cb16-41" aria-hidden="true" tabindex="-1"></a>  <span class="va">nixpkgs</span>.<span class="va">hostPlatform</span> <span class="op">=</span> <span class="st">&quot;aarch64-darwin&quot;</span><span class="op">;</span></span>
<span id="cb16-42"><a href="#cb16-42" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
</details>
<details>
<summary>
home.nix
</summary>
<div class="sourceCode" id="cb17"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="op">{</span> <span class="va">config</span><span class="op">,</span> <span class="va">pkgs</span><span class="op">,</span> <span class="op">...</span> <span class="op">}</span>:</span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb17-4"><a href="#cb17-4" aria-hidden="true" tabindex="-1"></a>  <span class="va">home</span>.<span class="va">stateVersion</span> <span class="op">=</span> <span class="st">&quot;23.11&quot;</span><span class="op">;</span></span>
<span id="cb17-5"><a href="#cb17-5" aria-hidden="true" tabindex="-1"></a>  <span class="va">programs</span>.<span class="va">git</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb17-6"><a href="#cb17-6" aria-hidden="true" tabindex="-1"></a>    <span class="va">enable</span> <span class="op">=</span> <span class="cn">true</span><span class="op">;</span></span>
<span id="cb17-7"><a href="#cb17-7" aria-hidden="true" tabindex="-1"></a>    <span class="va">userName</span> <span class="op">=</span> <span class="st">&quot;user name&quot;</span><span class="op">;</span></span>
<span id="cb17-8"><a href="#cb17-8" aria-hidden="true" tabindex="-1"></a>    <span class="va">userEmail</span> <span class="op">=</span> <span class="st">&quot;email&quot;</span><span class="op">;</span></span>
<span id="cb17-9"><a href="#cb17-9" aria-hidden="true" tabindex="-1"></a>    <span class="va">extraConfig</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb17-10"><a href="#cb17-10" aria-hidden="true" tabindex="-1"></a>      <span class="va">github</span>.<span class="va">user</span> <span class="op">=</span> <span class="st">&quot;gh_user&quot;</span><span class="op">;</span></span>
<span id="cb17-11"><a href="#cb17-11" aria-hidden="true" tabindex="-1"></a>      <span class="va">init</span> <span class="op">=</span> <span class="op">{</span> <span class="va">defaultBranch</span> <span class="op">=</span> <span class="st">&quot;trunk&quot;</span><span class="op">;</span> <span class="op">};</span></span>
<span id="cb17-12"><a href="#cb17-12" aria-hidden="true" tabindex="-1"></a>      <span class="va">diff</span> <span class="op">=</span> <span class="op">{</span> <span class="va">external</span> <span class="op">=</span> <span class="st">&quot;</span><span class="sc">${</span>pkgs<span class="op">.</span>difftastic<span class="sc">}</span><span class="st">/bin/difft&quot;</span><span class="op">;</span> <span class="op">};</span></span>
<span id="cb17-13"><a href="#cb17-13" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span>
<span id="cb17-14"><a href="#cb17-14" aria-hidden="true" tabindex="-1"></a>  <span class="op">};</span></span>
<span id="cb17-15"><a href="#cb17-15" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
</details>
<h2 id="revisions">Revisions</h2>
<ol type="1">
<li>28-03-2024: Removed <a href="https://functional.cafe/@roberth/112162631890741471">redundant <code>system</code> attribute</a> – Thx <a href="https://functional.cafe/@roberth"><span class="citation" data-cites="roberth">@roberth</span><span class="citation" data-cites="functional.cafe">@functional.cafe</span></a></li>
</ol>
<section id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes">
<hr />
<ol>
<li id="fn1"><p>Explaining flakes or nix nuanceses are out of scope and probably out of my reach, <a href="https://nixos-and-flakes.thiscute.world/" class="uri">https://nixos-and-flakes.thiscute.world/</a> is a better resource.<a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn2"><p>For flake build system to find them, git should be aware of the files.<a href="#fnref2" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
</ol>
</section></section>
</article>
]]></summary>
</entry>
<entry>
    <title>Experiments in Portable computing</title>
    <link href="https://blog.dbalan.in/blog/2024/01/18/experiments-in-portable-computing/index.html" />
    <id>https://blog.dbalan.in/blog/2024/01/18/experiments-in-portable-computing/index.html</id>
    <published>2024-01-18T00:00:00Z</published>
    <updated>2024-01-18T00:00:00Z</updated>
    <summary type="html"><![CDATA[<article class="group">
  <h1><a href="/blog/2024/01/18/experiments-in-portable-computing/index.html">Experiments in Portable computing</a></h1>
  <div class="postmeta">
    <div id="date">January 18, 2024</div>
    
    <div id="tags">Posted in <a title="All pages tagged &#39;cyberdeck&#39;." href="/tags/cyberdeck.html" rel="tag">cyberdeck</a>, <a title="All pages tagged &#39;computing&#39;." href="/tags/computing.html" rel="tag">computing</a>, <a title="All pages tagged &#39;iphone&#39;." href="/tags/iphone.html" rel="tag">iphone</a></div>
    
  </div>

  <section><p>I use my phone a lot. Its the best for consuming media on the go sort of things, like reading, watching videos etc. Always on, always connected, ready to whip out in a moments notice!</p>
<p>I also hate using my phone for anything else: for a long time the reasons have eluded me, but this time I have a lead – I <strong>hate</strong> typing on my phone.</p>
<p>Obviously there are more fundamental problems here than those solved by <a href="https://www.clicks.tech/">strapping on a keyboard</a><a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a>, explained so well by this quote from <a href="https://99percentinvisible.org/episode/of-mice-and-men/">99% Percent invisible episode</a> about Douglas Englebart -</p>
<blockquote>
<p>The consumer market prioritizes simple and “user-friendly” devices over more complex and “learnable” devices.</p>
</blockquote>
<p>They elaborate further</p>
<blockquote>
<p>Englebart used to compare the sleek, simplified Apple products to a tricycle. You don’t need any special training to operate a tricycle, and that’s fine if you’re just going to go around the block. If you’re trying to go up a hill or go a long distance, you want a real bike. The kind with gears and brakes– the kind that takes time to learn how to steer and balance on.</p>
</blockquote>
<p>Recently, I got to try a <a href="https://mntre.com/media/reform_md/2022-06-20-introducing-mnt-pocket-reform.html">pocket reform</a>. For the uninitiated, its a 7” pocket sized (arguably, depending on what kind of pockets you have) computer. It is a nifty little device with a lot of cool factor, including a compact mechanical keyboard and more or less running blob free software stack!</p>
<p>This got me thinking: <em>Is it worthwhile to compromise extreme portability to gain learnability and configuration?</em></p>
<p>A device like pocket reform is not going to be as good as my phone for quickly reading through my reading list, at least not out of the box. Would I still prefer to stick with my phone? Obviously the answer is going to personal and subjective, but I believe its worthwhile to try!</p>
<p>Pocket reforms are currently only sold through the crown supply store in US, so I decided to wait until MNT starts selling them from their EU store, and spent the waiting time maybe hacking alternatives a bit – Can I strap a <a href="https://www.solder.party/docs/bbq20kbd/">Blackberry Keyboard</a> to my phone? <a href="https://postmarketos.org/">Running mainline linux</a> with the stack you are used to seems fun etc etc. Honestly, I needed some deliberation before dropping a cool grand on an experiment.</p>
<p>Also, after going through bit of internet searching, the options are not as limited as I thought; there are bunch of manufactures trying to make devices in this form factor: GPD seems to be the most popular, there are <a href="https://www.aliexpress.us/w/wholesale-pocket-laptop.html?spm=a2g0o.detail.search.0">also no-name products</a> with <a href="https://news.ycombinator.com/item?id=39013008">at least one very happy HN reader</a>.</p>
<p>This nerdary also led me discover <strong>“Cyberdecks”</strong>. I have not read Neuromancer so I don’t know what makes something a cyberdeck; but the community seems to be <a href="https://www.reddit.com/r/cyberDeck/top/?sort=top&amp;t=year">building some of the coolest portable computing</a> out there. Definitely check it out if you were living under a rock like me!</p>
<section id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes">
<hr />
<ol>
<li id="fn1"><p>Still, probably would try it when becomes avaible for my phone and comes down from its &gt; $100 pricetag.<a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
</ol>
</section></section>
</article>
]]></summary>
</entry>
<entry>
    <title>Mount a Zvol under linux</title>
    <link href="https://blog.dbalan.in/blog/2024/01/12/mount-a-zvol-under-linux/index.html" />
    <id>https://blog.dbalan.in/blog/2024/01/12/mount-a-zvol-under-linux/index.html</id>
    <published>2024-01-12T00:00:00Z</published>
    <updated>2024-01-12T00:00:00Z</updated>
    <summary type="html"><![CDATA[<article class="group">
  <h1><a href="/blog/2024/01/12/mount-a-zvol-under-linux/index.html">Mount a Zvol under linux</a></h1>
  <div class="postmeta">
    <div id="date">January 12, 2024</div>
    
    <div id="tags">Posted in <a title="All pages tagged &#39;zfs&#39;." href="/tags/zfs.html" rel="tag">zfs</a>, <a title="All pages tagged &#39;zvol&#39;." href="/tags/zvol.html" rel="tag">zvol</a>, <a title="All pages tagged &#39;mount&#39;." href="/tags/mount.html" rel="tag">mount</a>, <a title="All pages tagged &#39;kpartx&#39;." href="/tags/kpartx.html" rel="tag">kpartx</a>, <a title="All pages tagged &#39;linux&#39;." href="/tags/linux.html" rel="tag">linux</a>, <a title="All pages tagged &#39;nixos&#39;." href="/tags/nixos.html" rel="tag">nixos</a></div>
    
  </div>

  <section><p>Zvol are volumes backed by a zfs pool. They are quite popular as vm disk images.</p>
<p>Sometimes you just want to examine them in the host; here is how to mount them.</p>
<p>When the pool is imported, they show up under <code>/dev/zvol/&lt;path to zvol dataset&gt;</code>. At this point they are just raw drives, and kernel knows nothing
about its structure. To be able to mount them, we first need to read its
partition structure and create partition specific <code>/dev/</code> entires with
<code>kpartx(8)</code><a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a>.</p>
<pre class="shell"><code># -a for add
kpartx -a /dev/zvol/&lt;pathtozvol&gt;</code></pre>
<p>This will create corresponding devices for partitions under <code>/dev/mapper</code></p>
<pre><code>$:/dev/mapper]# ls -al
total 0
drwxr-xr-x  2 root root     120 Jan 12 17:04 .
drwxr-xr-x 20 root root    3980 Jan 12 17:04 ..
crw-------  1 root root 10, 236 Jan 12 17:00 control
lrwxrwxrwx  1 root root       7 Jan 12 17:04 root-zvol1 -&gt; ../dm-0
lrwxrwxrwx  1 root root       7 Jan 12 17:04 root-zvol2 -&gt; ../dm-1
lrwxrwxrwx  1 root root       7 Jan 12 17:04 root-zvol3 -&gt; ../dm-2</code></pre>
<p>Now you can mount them as a regular disk with <code>mount</code>.</p>
<pre><code>mount /dev/mapper/root-zvol1 /mnt</code></pre>
<section id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes">
<hr />
<ol>
<li id="fn1"><p>In nixos, <code>kpartx</code> is part of package <a href="https://search.nixos.org/packages?channel=23.11&amp;show=multipath-tools&amp;from=0&amp;size=50&amp;sort=relevance&amp;type=packages&amp;query=kpartx"><code>multipath-tools</code></a><a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
</ol>
</section></section>
</article>
]]></summary>
</entry>
<entry>
    <title>Easy NixOS remote deployments</title>
    <link href="https://blog.dbalan.in/blog/2023/11/14/easy-nixos-remote-deployments/index.html" />
    <id>https://blog.dbalan.in/blog/2023/11/14/easy-nixos-remote-deployments/index.html</id>
    <published>2023-11-14T00:00:00Z</published>
    <updated>2023-11-14T00:00:00Z</updated>
    <summary type="html"><![CDATA[<article class="group">
  <h1><a href="/blog/2023/11/14/easy-nixos-remote-deployments/index.html">Easy NixOS remote deployments</a></h1>
  <div class="postmeta">
    <div id="date">November 14, 2023</div>
    
    <div id="tags">Posted in <a title="All pages tagged &#39;nixos&#39;." href="/tags/nixos.html" rel="tag">nixos</a>, <a title="All pages tagged &#39;nix&#39;." href="/tags/nix.html" rel="tag">nix</a>, <a title="All pages tagged &#39;flakes&#39;." href="/tags/flakes.html" rel="tag">flakes</a></div>
    
  </div>

  <section><p>There exists a <a href="https://github.com/NixOS/nixops">mutitude</a>
<a href="https://github.com/DBCDK/morph">of</a> <a href="https://github.com/krebs/krops">tooling</a>
to remotely manage nixos machines, each with its own features and compromises.</p>
<p>In my experience, for a simple deployment of few hosts
<code>nixos-rebuild --target-host</code> is pretty powerful.</p>
<p>This is the workflow I’ve been using to manage my personal systems:</p>
<p>I bootstrap the machines manually by following the <a href="https://nixos.org/manual/nixos/stable/#sec-installation">nixos install
guide</a>, and copy over
the generated configuration to <code>config/&lt;hostname&gt;/configuration.nix</code>.</p>
<p>On the root directory create <code>flake.nix</code>:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode nix"><code class="sourceCode nix"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>  <span class="va">description</span> <span class="op">=</span> <span class="st">&quot;systems needed&quot;</span><span class="op">;</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a>  <span class="va">inputs</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>     <span class="co"># extra inputs go here</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a>  <span class="op">};</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a>  <span class="va">outputs</span> <span class="op">=</span> <span class="op">{</span> <span class="va">self</span><span class="op">,</span> <span class="va">nixpkgs</span> <span class="op">}</span>@<span class="va">attrs</span><span class="op">:</span> <span class="op">{</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a>    <span class="co"># this is where we add new machines</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a>    <span class="va">nixosConfigurations</span> <span class="op">=</span> <span class="op">{</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a>     <span class="co"># host fancyHostname</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a>      <span class="va">fancyHostname</span> <span class="op">=</span> nixpkgs<span class="op">.</span>lib<span class="op">.</span>nixosSystem <span class="op">{</span></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a>        <span class="va">system</span> <span class="op">=</span> <span class="st">&quot;x86_64-linux&quot;</span><span class="op">;</span></span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a>        <span class="va">specialArgs</span> <span class="op">=</span> attrs<span class="op">;</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a>        <span class="va">modules</span> <span class="op">=</span> <span class="op">[</span></span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a>          <span class="co"># This points to the actual machine configuration</span></span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a>          <span class="op">(</span><span class="bu">import</span> <span class="ss">./config/nixmachine/configuration.nix</span><span class="op">)</span></span>
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true" tabindex="-1"></a>        <span class="op">];</span></span>
<span id="cb1-18"><a href="#cb1-18" aria-hidden="true" tabindex="-1"></a>      <span class="op">};</span></span>
<span id="cb1-19"><a href="#cb1-19" aria-hidden="true" tabindex="-1"></a>    <span class="op">};</span></span>
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true" tabindex="-1"></a>  <span class="op">};</span></span>
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
<p>From there, hosts can deployed over SSH!</p>
<pre><code>nixos-rebuild switch  --target-host root@fancyHostname --flake &#39;.#fancyHostname&#39;</code></pre>
<p>More hosts can be added by adding them to the <code>nixosConfigurations</code> attribute set.</p>
<pre><code>nixosConfigurations = {
    fancySecondHost = { ... }
    ...
}</code></pre>
<h2 id="should-i-do-this">Should I do this?</h2>
<p>I think this is an easier workflow for me to manage and debug, However a lot of
things in this space has non-linear learning curves and has sparse documentation
at best.</p>
<p>So maybe a tool with better documentation might work well for you?</p>
<p>This also relies heavily on <code>flakes</code>, which is “experimental”. In my experience,
ground reality is everyone uses flakes, but good documentation is hard to come by</p>
<p>I’ve herd good things about Nix <a href="https://nixos-and-flakes.thiscute.world/">Flakes Book</a>, but
haven’t read it</p>
<p><em>This was first published at <a href="https://pencil.lalalala.in/dbalan/easy-nixos-remote-deployments" class="uri">https://pencil.lalalala.in/dbalan/easy-nixos-remote-deployments</a></em></p></section>
</article>
]]></summary>
</entry>
<entry>
    <title>Setting up a private package repo for FreeBSD</title>
    <link href="https://blog.dbalan.in/blog/2020/04/07/setting-up-a-private-package-repo-for-freebsd/index.html" />
    <id>https://blog.dbalan.in/blog/2020/04/07/setting-up-a-private-package-repo-for-freebsd/index.html</id>
    <published>2020-04-07T00:00:00Z</published>
    <updated>2020-04-07T00:00:00Z</updated>
    <summary type="html"><![CDATA[<article class="group">
  <h1><a href="/blog/2020/04/07/setting-up-a-private-package-repo-for-freebsd/index.html">Setting up a private package repo for FreeBSD</a></h1>
  <div class="postmeta">
    <div id="date">April  7, 2020</div>
    
    <div id="tags">Posted in <a title="All pages tagged &#39;freebsd&#39;." href="/tags/freebsd.html" rel="tag">freebsd</a>, <a title="All pages tagged &#39;pkgng&#39;." href="/tags/pkgng.html" rel="tag">pkgng</a></div>
    
  </div>

  <section><p>Lately the EU mirror for FreeBSD packages(<a href="http://pkg0.bme.freebsd.org" class="uri">http://pkg0.bme.freebsd.org</a>) has been really slow for me. My best guess is the mirror is being overloaded, it could be because of my ISP peering weirdly too.</p>
<p>I already have a <a href="https://www.freebsd.org/doc/handbook/ports-poudriere.html">Poudriere</a> setup running on a beefy server. How hard it would be building all the packages that I need? Turns out its not that hard at all.</p>
<p>First step is to get all the packages that I currently use and their port names</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> pkg query <span class="st">&#39;%o&#39;</span> <span class="op">&gt;</span> x230-packages</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="co"># make sure they look right</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> head x230-packages</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="ex">math/coinmp</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="ex">x11-fonts/gentium-basic</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="ex">graphics/ImageMagick6</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a><span class="ex">devel/ORBit2</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a><span class="ex">graphics/aalib</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a><span class="ex">sysutils/accountsservice</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a><span class="ex">print/adobe-cmaps</span></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a><span class="ex">x11-themes/adwaita-icon-theme</span></span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a><span class="ex">x11/alacritty</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a><span class="ex">audio/alsa-lib</span></span></code></pre></div>
<p>Setup poudriere with instructions from handbook: <a href="https://www.freebsd.org/doc/handbook/ports-poudriere.html" class="uri">https://www.freebsd.org/doc/handbook/ports-poudriere.html</a></p>
<p>Build the packages</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="ex">/usr/local/bin/poudriere</span> ports <span class="at">-p</span> local <span class="at">-u</span></span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="ex">/usr/local/bin/poudriere</span> bulk <span class="at">-j</span> 12amd64 <span class="at">-p</span> local <span class="at">-z</span> x230 <span class="at">-f</span> /root/x230-packages</span></code></pre></div>
<p>After <strong>a day and half</strong> poudriere built all the packages I need :)</p>
<p>Now all that left is to disable the official repo and replace it with mine</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">cat</span> <span class="op">&gt;</span> /usr/local/etc/pkg/repos/Mine.conf <span class="op">&lt;&lt;EOF</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="st">FreeBSD: { enabled: no }</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="st">builder: {</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="st">  url: &quot;https://&lt;path to repo&gt;/repo/12amd64-local-x230/&quot;,</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a><span class="st">  enabled: yes</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="st">}</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a><span class="op">EOF</span></span></code></pre></div>
<p>Bye bye slow mirrors!</p>
<p>This should be filed under over-engineering, and I should really investigate why the mirror is slow; This does work and love how simple and powerful the pkg system is. Workflow is far better than I am used to bulk building debian or arch packages.</p></section>
</article>
]]></summary>
</entry>

</feed>
