<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<title>セピー</title>
	<link href="https://sefidel.net/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="https://sefidel.net"/>
	<generator uri="https://www.getzola.org/">Zola</generator>
	<updated>2023-01-31T00:00:00+00:00</updated>
	<id>https://sefidel.net/atom.xml</id>
	<entry xml:lang="en">
		<title>Installing NixOS with ZFS mirrored boot</title>
		<published>2023-01-31T00:00:00+00:00</published>
		<updated>2023-01-31T00:00:00+00:00</updated>
		<link rel="alternate" href="https://sefidel.net/posts/nixos-zfs-mirrored-boot/" type="text/html"/>
		<id>https://sefidel.net/posts/nixos-zfs-mirrored-boot/</id>
		<content type="html">&lt;p&gt;&#x2F;&#x2F; TODO: add PlantUML diagrams&lt;&#x2F;p&gt;
&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;&#x2F;h2&gt;
&lt;p&gt;In this post, we&#x27;re going to set up a ZFS mirrored boot system with full-disk encryption that is unlockable remotely.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;preparing-the-installation-medium&quot;&gt;Preparing the installation medium&lt;&#x2F;h2&gt;
&lt;p&gt;This step may vary depending on what system you&#x27;re going to install NixOS into.&lt;&#x2F;p&gt;
&lt;p&gt;This post assumes that you&#x27;re installing this on a normal server, with a
minimal NixOS image.&lt;&#x2F;p&gt;
&lt;p&gt;The community-maintained &lt;a href=&quot;https:&#x2F;&#x2F;nixos.wiki&quot;&gt;NixOS wiki&lt;&#x2F;a&gt; contains guides to install
NixOS to devices in other conditions, such as a server with only remote access.&lt;&#x2F;p&gt;
&lt;p&gt;You will need a USB stick before proceeding to the next step.&lt;&#x2F;p&gt;
&lt;p&gt;First, download the latest NixOS image, and flash it:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;$ curl&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -L&lt;&#x2F;span&gt;&lt;span&gt; https:&#x2F;&#x2F;channels.nixos.org&#x2F;nixos-unstable&#x2F;latest-nixos-minimal-x86_64-linux.iso&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -O&lt;&#x2F;span&gt;&lt;span&gt; nixos.iso
&lt;&#x2F;span&gt;&lt;span&gt;$ dd if=.&#x2F;nixos.iso of=&#x2F;dev&#x2F;sdX bs=1M status=progress
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If your target machine architecture is not &lt;code&gt;x86_64&lt;&#x2F;code&gt;, replace it with your
desired architecture (e.g. &lt;code&gt;i686&lt;&#x2F;code&gt;, &lt;code&gt;aarch64&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;p&gt;After the image has been successfully flashed into your installation medium,
unplug it and boot using the medium on the target machine.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;preparing-disks&quot;&gt;Preparing Disks&lt;&#x2F;h2&gt;
&lt;p&gt;We&#x27;ll start by defining variables pointing to each disk by ID.&lt;&#x2F;p&gt;
&lt;p&gt;According to the &lt;a href=&quot;https:&#x2F;&#x2F;wiki.archlinux.org&quot;&gt;Archlinux.org Wiki&lt;&#x2F;a&gt;, If you create zpools using device names
(e.g. &lt;code&gt;&#x2F;dev&#x2F;sda&lt;&#x2F;code&gt;), ZFS might not be able to detect zpools intermittently on
boot.&lt;&#x2F;p&gt;
&lt;p&gt;You can grab the ID via &lt;code&gt;ls -lh &#x2F;dev&#x2F;disk&#x2F;by-id&#x2F;&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;DISK1&lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&#x2F;dev&#x2F;disk&#x2F;by-id&#x2F;ata-VENDOR-ID-OF-THE-FIRST-DRIVE
&lt;&#x2F;span&gt;&lt;span&gt;DISK2&lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&#x2F;dev&#x2F;disk&#x2F;by-id&#x2F;ata-VENDOR-ID-OF-THE-SECOND-DRIVE
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;partitioning&quot;&gt;Partitioning&lt;&#x2F;h3&gt;
&lt;p&gt;Then we&#x27;ll partition our disks. Since this is a mirrored setup, we&#x27;ll have to do
the exactly same operation twice. Fortunately, bash function come into rescue.&lt;&#x2F;p&gt;
&lt;p&gt;The partition structure is the following:&lt;&#x2F;p&gt;
&lt;pre style=&quot;background-color:#272822;color:#f8f8f2;&quot;&gt;&lt;code&gt;&lt;span&gt;1GiB Boot | ~Remaining ZFS
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;partition&lt;&#x2F;span&gt;&lt;span&gt;() {
&lt;&#x2F;span&gt;&lt;span&gt;    sgdisk&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; --zap-all &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;$1&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;    sgdisk&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -n&lt;&#x2F;span&gt;&lt;span&gt; 1:0:+1GiB&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -t&lt;&#x2F;span&gt;&lt;span&gt; 1:EF00&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -c&lt;&#x2F;span&gt;&lt;span&gt; 1:boot &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;$1&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# Swap is omitted.
&lt;&#x2F;span&gt;&lt;span&gt;    sgdisk&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -n&lt;&#x2F;span&gt;&lt;span&gt; 2:0:0&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -t&lt;&#x2F;span&gt;&lt;span&gt; 2:BF01&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -c&lt;&#x2F;span&gt;&lt;span&gt; 2:zfs &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;$1&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;    sgdisk&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; --print &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;$1&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;partition $DISK1
&lt;&#x2F;span&gt;&lt;span&gt;partition $DISK2
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;creating-vfat-filesystem-for-boot&quot;&gt;Creating vfat filesystem for boot&lt;&#x2F;h3&gt;
&lt;p&gt;Boot partitions should be formatted with &#x27;vfat&#x27;, in order for it to mount and
function without issues.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;mkfs.vfat $DISK1-part1
&lt;&#x2F;span&gt;&lt;span&gt;mkfs.vfat $DISK2-part1
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;configuring-zfs-pool&quot;&gt;Configuring ZFS pool&lt;&#x2F;h3&gt;
&lt;p&gt;This dataset structure is based on &lt;a href=&quot;https:&#x2F;&#x2F;grahamc.com&#x2F;blog&#x2F;erase-your-darlings&quot;&gt;Erase your darlings&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Now that we&#x27;re done partitioning our disks, we&#x27;ll create a ZFS pool named
&#x27;rpool&#x27;, which is mirrored. This will prompt you to enter a passphrase for your
new ZFS pool.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;zpool create \
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt;    -o&lt;&#x2F;span&gt;&lt;span&gt; ashift=12 \
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt;    -O&lt;&#x2F;span&gt;&lt;span&gt; mountpoint=none&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -O&lt;&#x2F;span&gt;&lt;span&gt; atime=off&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -O&lt;&#x2F;span&gt;&lt;span&gt; acltype=posixacl&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -O&lt;&#x2F;span&gt;&lt;span&gt; xattr=sa \
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt;    -O&lt;&#x2F;span&gt;&lt;span&gt; compression=lz4&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -O&lt;&#x2F;span&gt;&lt;span&gt; encryption=aes-256-gcm&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -O&lt;&#x2F;span&gt;&lt;span&gt; keyformat=passphrase \
&lt;&#x2F;span&gt;&lt;span&gt;    rpool mirror \
&lt;&#x2F;span&gt;&lt;span&gt;    $DISK1-part2 $DISK2-part2
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then, we create a &#x27;root dataset&#x27; which is &lt;code&gt;&#x2F; (root)&lt;&#x2F;code&gt; for the target machine,
then snapshot the empty state as &#x27;blank&#x27;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;zfs create&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -p -o&lt;&#x2F;span&gt;&lt;span&gt; mountpoint=legacy rpool&#x2F;local&#x2F;root
&lt;&#x2F;span&gt;&lt;span&gt;zfs snapshot rpool&#x2F;local&#x2F;root@blank
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note the &#x27;local&#x27; after rpool. In this setup, &#x27;local&#x27; is treated as unimportant
data, i.e. packages, root, etc., Whereas &#x27;safe&#x27; is treated as important data,
which needs to be backed up.&lt;&#x2F;p&gt;
&lt;p&gt;And mount it:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;mount&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -t&lt;&#x2F;span&gt;&lt;span&gt; zfs rpool&#x2F;local&#x2F;root &#x2F;mnt
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then we mount the multiple boot partitions we created:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;mkdir &#x2F;mnt&#x2F;boot
&lt;&#x2F;span&gt;&lt;span&gt;mkdir &#x2F;mnt&#x2F;boot-fallback
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;mount $DISK1-part1 &#x2F;mnt&#x2F;boot
&lt;&#x2F;span&gt;&lt;span&gt;mount $DISK2-part1 &#x2F;mnt&#x2F;boot-fallback
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Create and mount a dataset for &lt;code&gt;&#x2F;nix&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;zfs create&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -p -o&lt;&#x2F;span&gt;&lt;span&gt; mountpoint=legacy rpool&#x2F;local&#x2F;nix
&lt;&#x2F;span&gt;&lt;span&gt;mkdir &#x2F;mnt&#x2F;nix
&lt;&#x2F;span&gt;&lt;span&gt;mount&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -t&lt;&#x2F;span&gt;&lt;span&gt; zfs rpool&#x2F;local&#x2F;nix &#x2F;mnt&#x2F;nix
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And a dataset for &lt;code&gt;&#x2F;home&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;zfs create&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -p -o&lt;&#x2F;span&gt;&lt;span&gt; mountpoint=legacy rpool&#x2F;safe&#x2F;home
&lt;&#x2F;span&gt;&lt;span&gt;mkdir &#x2F;mnt&#x2F;home
&lt;&#x2F;span&gt;&lt;span&gt;mount&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -t&lt;&#x2F;span&gt;&lt;span&gt; zfs rpool&#x2F;safe&#x2F;home &#x2F;mnt&#x2F;home
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And a dataset for states that needs to be persisted between boots:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;zfs create&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -p -o&lt;&#x2F;span&gt;&lt;span&gt; mountpoint=legacy rpool&#x2F;safe&#x2F;persist
&lt;&#x2F;span&gt;&lt;span&gt;mkdir &#x2F;mnt&#x2F;persist
&lt;&#x2F;span&gt;&lt;span&gt;mount&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -t&lt;&#x2F;span&gt;&lt;span&gt; zfs rpool&#x2F;safe&#x2F;persist &#x2F;mnt&#x2F;persist
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note: All states will be wiped each boot after setting up
&lt;a href=&quot;https:&#x2F;&#x2F;sefidel.net&#x2F;posts&#x2F;nixos-zfs-mirrored-boot&#x2F;#erasing-your-darlings&quot;&gt;these&lt;&#x2F;a&gt;.
Make sure to put states that need to persist on &lt;code&gt;&#x2F;persist&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;configuring-nixos&quot;&gt;Configuring NixOS&lt;&#x2F;h2&gt;
&lt;p&gt;Now that we&#x27;re done with partitions and ZFS, it&#x27;s time to declaratively
configure the machine. This step may vary depending on your machine,
please consult the docs when in doubt.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;getting-the-base-configuration&quot;&gt;Getting the base configuration&lt;&#x2F;h3&gt;
&lt;p&gt;In this post, we&#x27;re going to use plain &lt;code&gt;nixos-generate-config&lt;&#x2F;code&gt; to get a base
configuration files for the machine.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;nixos-generate-config&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; --root&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;mnt
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;erasing-your-darlings&quot;&gt;Erasing your darlings&lt;&#x2F;h3&gt;
&lt;p&gt;In the &lt;a href=&quot;https:&#x2F;&#x2F;sefidel.net&#x2F;posts&#x2F;nixos-zfs-mirrored-boot&#x2F;#configuring-zfs-pool&quot;&gt;previous step&lt;&#x2F;a&gt;, we&#x27;ve made a snapshot of blank
root to roll back to it each boot, to keep the system stateless.&lt;&#x2F;p&gt;
&lt;p&gt;Add this to the &lt;code&gt;configuration.nix&lt;&#x2F;code&gt; to wipe the root dataset on each boot by
rolling back to the blank snapshot after the devices are made available:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;nix&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-nix &quot;&gt;&lt;code class=&quot;language-nix&quot; data-lang=&quot;nix&quot;&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;boot&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;initrd&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;postDeviceCommands &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt;lib&lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt;mkAfter &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;#39;&amp;#39;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;    zfs rollback -r rpool&#x2F;local&#x2F;root@blank
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;  &amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;configuring-bootloader&quot;&gt;Configuring Bootloader&lt;&#x2F;h3&gt;
&lt;p&gt;In order to get ZFS to work, we need the following options to be set:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;nix&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-nix &quot;&gt;&lt;code class=&quot;language-nix&quot; data-lang=&quot;nix&quot;&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;boot&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;supportedFilesystems &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;[ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;zfs&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;networking&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;hostId &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;&amp;lt;8 random chars&amp;gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You can grab your machine ID at &lt;code&gt;&#x2F;etc&#x2F;machine-id&lt;&#x2F;code&gt; for the &lt;code&gt;hostId&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Then we&#x27;ll configure grub:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;nix&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-nix &quot;&gt;&lt;code class=&quot;language-nix&quot; data-lang=&quot;nix&quot;&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# Whether installer can modify the EFI variables.
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# If you encounter errors, set this to `false`.
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;boot&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;loader&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;efi&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;canTouchEfiVariables &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ae81ff;&quot;&gt;true&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;boot&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;loader&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;grub&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;enable &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ae81ff;&quot;&gt;true&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;boot&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;loader&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;grub&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;efiSupport &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ae81ff;&quot;&gt;true&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;boot&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;loader&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;grub&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;device &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;nodev&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# This should be done automatically, but explicitly declare it just in case.
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;boot&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;loader&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;grub&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;copyKernels &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ae81ff;&quot;&gt;true&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# Make sure that you&amp;#39;ve listed all of the boot partitions here.
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;boot&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;loader&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;grub&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;mirroredBoots &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;[
&lt;&#x2F;span&gt;&lt;span&gt;    { &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;path &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;&#x2F;boot&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;devices &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;&#x2F;dev&#x2F;disk&#x2F;by-uuid&#x2F;&amp;lt;ID-HERE&amp;gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;]; }
&lt;&#x2F;span&gt;&lt;span&gt;    { &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;path &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;&#x2F;boot-fallback&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;devices &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;&#x2F;dev&#x2F;disk&#x2F;by-uuid&#x2F;&amp;lt;ID-HERE&amp;gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;]; }
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# ...
&lt;&#x2F;span&gt;&lt;span&gt;  ];
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;handling-boot-partitions-gracefully&quot;&gt;Handling boot partitions gracefully&lt;&#x2F;h3&gt;
&lt;p&gt;By default, NixOS will throw an error and complain about it when there is a
missing partition&#x2F;disk. Since we want the server to boot smoothly even if there
is a missing boot partition, so we need to set the &#x27;nofail&#x27; option to those
partitions:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;nix&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-nix &quot;&gt;&lt;code class=&quot;language-nix&quot; data-lang=&quot;nix&quot;&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;fileSystems&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;&#x2F;boot&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;options &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;[ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;nofail&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;fileSystems&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;&#x2F;boot-fallback&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;options &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;[ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;nofail&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;enabling-remote-zfs-unlock&quot;&gt;Enabling Remote ZFS Unlock&lt;&#x2F;h3&gt;
&lt;p&gt;On each boot, ZFS will ask for a passphrase to unlock the ZFS pool.
To work around this issue, we can start an SSH server in &lt;code&gt;initrd&lt;&#x2F;code&gt;, that is going
to live until the pool is unlocked.&lt;&#x2F;p&gt;
&lt;p&gt;Note: If you rename the keys after, you may have some trouble rolling back to
previous generations: See &lt;a href=&quot;caveat-remote-unlock&quot;&gt;here&lt;&#x2F;a&gt; for details.&lt;&#x2F;p&gt;
&lt;p&gt;To achieve that, we&#x27;ll first have to generate an SSH host key for the initrd:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;ssh-keygen&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -t&lt;&#x2F;span&gt;&lt;span&gt; ed25519&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -N &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; -f&lt;&#x2F;span&gt;&lt;span&gt; &#x2F;mnt&#x2F;boot&#x2F;initrd-ssh-key
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# Each boot partition should have the same key
&lt;&#x2F;span&gt;&lt;span&gt;cp &#x2F;mnt&#x2F;boot&#x2F;initrd-ssh-key &#x2F;mnt&#x2F;boot-fallback&#x2F;initrd-ssh-key
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then configure &lt;code&gt;initrd&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;nix&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-nix &quot;&gt;&lt;code class=&quot;language-nix&quot; data-lang=&quot;nix&quot;&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;boot&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;kernelModules &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;[ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;&amp;lt;YOUR-NETWORK-CARD&amp;gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;boot&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;initrd&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;kernelModules &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;[ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;&amp;lt;YOUR-NETWORK-CARD&amp;gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# DHCP Configuration, comment on Static IP
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;networking&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;networkmanager&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;enable &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ae81ff;&quot;&gt;false&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;networking&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;useDHCP &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ae81ff;&quot;&gt;true&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# Uncomment on Static IP
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# boot.kernelParams = [
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;#   # See &amp;lt;https:#www.kernel.org&#x2F;doc&#x2F;Documentation&#x2F;filesystems&#x2F;nfs&#x2F;nfsroot.txt&amp;gt; for documentation.
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;#   # ip=&amp;lt;client-ip&amp;gt;:&amp;lt;server-ip&amp;gt;:&amp;lt;gw-ip&amp;gt;:&amp;lt;netmask&amp;gt;:&amp;lt;hostname&amp;gt;:&amp;lt;device&amp;gt;:&amp;lt;autoconf&amp;gt;:&amp;lt;dns0-ip&amp;gt;:&amp;lt;dns1-ip&amp;gt;:&amp;lt;ntp0-ip&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;#   # The server ip refers to the NFS server -- not needed in this case.
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;#   &amp;quot;ip=&amp;lt;YOUR-IPV4-ADDR&amp;gt;::&amp;lt;YOUR-IPV4-GATEWAY&amp;gt;:&amp;lt;YOUR-IPV4-NETMASK&amp;gt;:&amp;lt;YOUR-HOSTNAME&amp;gt;-initrd:&amp;lt;YOUR-NETWORK-INTERFACE&amp;gt;:off:&amp;lt;DNS-IP&amp;gt;&amp;quot;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# ];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;boot&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;initrd&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;network&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;enable &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ae81ff;&quot;&gt;true&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;boot&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;initrd&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;network&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;ssh &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;enable &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ae81ff;&quot;&gt;true&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# Using the same port as the actual SSH will cause clients to throw errors
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# related to host key mismatch.
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;port &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ae81ff;&quot;&gt;2222&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# This takes &amp;#39;path&amp;#39;s, not &amp;#39;string&amp;#39;s.
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;hostKeys &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;[
&lt;&#x2F;span&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&#x2F;boot&#x2F;initrd-ssh-key
&lt;&#x2F;span&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&#x2F;boot-fallback&#x2F;initrd-ssh-key
&lt;&#x2F;span&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# ...
&lt;&#x2F;span&gt;&lt;span&gt;    ];
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# Public ssh key to log into the initrd ssh
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;authorizedKeys &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span&gt;[ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;quot;&amp;lt;YOUR-SSH-PUBKEY&amp;gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;];
&lt;&#x2F;span&gt;&lt;span&gt;  };
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;boot&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;initrd&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;network&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#a6e22e;&quot;&gt;postCommands &lt;&#x2F;span&gt;&lt;span style=&quot;color:#f92672;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;&amp;#39;&amp;#39;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;    cat &amp;lt;&amp;lt;EOF &amp;gt; &#x2F;root&#x2F;.profile
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;    if pgrep -x &amp;quot;zfs&amp;quot; &amp;gt; &#x2F;dev&#x2F;null
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;    then
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;      zfs load-key -a
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;      killall zfs
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;    else
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;      echo &amp;quot;ZFS is not running -- this could be a sign of failure.&amp;quot;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;    fi
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;    EOF
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e6db74;&quot;&gt;  &amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;installing-nixos&quot;&gt;Installing NixOS&lt;&#x2F;h2&gt;
&lt;p&gt;Run &lt;code&gt;nixos-install&lt;&#x2F;code&gt;, then reboot your machine.&lt;&#x2F;p&gt;
&lt;p&gt;Note: Make sure that you&#x27;ve configured SSH and network for your machine,
failure to do so may result in an inaccessible system.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s it! Enjoy your fresh NixOS machine!&lt;&#x2F;p&gt;
&lt;h2 id=&quot;troubleshooting&quot;&gt;Troubleshooting&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;failed-to-import-pool-more-than-one-matching-pool&quot;&gt;Failed to import pool - more than one matching pool&lt;&#x2F;h3&gt;
&lt;p&gt;This error might occur when&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;one of your disks were previously used in another ZFS pool, and its metadata
weren&#x27;t properly removed&lt;&#x2F;li&gt;
&lt;li&gt;you messed up during install, and you repartitioning the disk without removing
its ZFS metadata.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This is because the ZFS metadata doesn&#x27;t live on a partition, but on a disk.&lt;&#x2F;p&gt;
&lt;p&gt;Note: the following operations will irrevocably delete ANY data on your disk!&lt;&#x2F;p&gt;
&lt;p&gt;To remove those left behind:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; style=&quot;background-color:#272822;color:#f8f8f2;&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;&lt;span&gt;sgdisk&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fd971f;&quot;&gt; --zap-all &lt;&#x2F;span&gt;&lt;span&gt;$DISK
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# Overwrite first 256M of the disk, removing metadata
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# In some cases just `wipefs -a` works, but I found this to be the most
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# reliable way to wipe them no matter what operations were performed on the disk
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#75715e;&quot;&gt;# before.
&lt;&#x2F;span&gt;&lt;span&gt;dd if=&#x2F;dev&#x2F;urandom bs=1M count=256 of=$DISK
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And then you can try the installation again.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;&#x2F;h2&gt;
&lt;h2 id=&quot;acknowledgements&quot;&gt;Acknowledgements&lt;&#x2F;h2&gt;
&lt;p&gt;I wrote this article because I&#x27;ve noticed that I always forget some steps
during NixOS installation to a newly acquired server.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;ve compiled resources listed below to make a step-by-step guide for a setup I
find &#x27;optimal&#x27;. Please do check out those resources!&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;discourse.nixos.org&#x2F;t&#x2F;nixos-on-mirrored-ssd-boot-swap-native-encrypted-zfs&#x2F;9215&quot;&gt;NixOS Discourse Thread&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;grahamc.com&#x2F;blog&#x2F;erase-your-darlings&quot;&gt;Erase your darlings&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;mazzo.li&#x2F;posts&#x2F;hetzner-zfs.html&quot;&gt;Remote, encrypted ZFS storage server with NixOS&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;elis.nu&#x2F;blog&#x2F;2019&#x2F;08&#x2F;encrypted-zfs-mirror-with-mirrored-boot-on-nixos&quot;&gt;Encrypted ZFS mirror with mirrored boot on NixOS&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Hello, world!</title>
		<published>2023-01-23T00:00:00+00:00</published>
		<updated>2023-01-23T00:00:00+00:00</updated>
		<link rel="alternate" href="https://sefidel.net/posts/hello-world/" type="text/html"/>
		<id>https://sefidel.net/posts/hello-world/</id>
		<content type="html">&lt;p&gt;&lt;strong&gt;Hello, world!&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;This is my first post on my personal website.&lt;&#x2F;p&gt;
&lt;p&gt;Here&#x27;s a quick overview of what will be posted here:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Status Updates&lt;&#x2F;li&gt;
&lt;li&gt;Development notes&lt;&#x2F;li&gt;
&lt;li&gt;Generally anything I find interesting (they&#x27;ll be tagged accordingly)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I have a broad interest in technology, so if you have something to share, please
don&#x27;t hesitate to &lt;a href=&quot;https:&#x2F;&#x2F;sefidel.net&#x2F;about&#x2F;&quot;&gt;reach out&lt;&#x2F;a&gt; to me!&lt;&#x2F;p&gt;
</content>
	</entry>
</feed>
