+++ title = "NixOS on encrypted ZFS" author = ["Elia el Lazkani"] date = 2021-10-17 lastmod = 2021-10-17 tags = ["zfs", "encryption"] categories = ["nix", "nixos"] draft = false +++ I wouldn't call myself a distro hopper. The decision of distribution is solely based on requirements. I have requirements and I want the distribution to fulfill them as much as possible. After 15 years, I know what I want and I go and find it. In this case, an unexpected project caught my eye. The idea is so radically different that I wasn't actually searching for it this time. It is one of those times where it found me first. After looking into **Nix** and **NixOS**, I decided it is going to be my distribution of choice on the desktop. I will use that as my test bed before migrating all the serious work there. That's how I got my first taste of **NixOS** outside of the deterministic virtualization layer and into the wild. ## Requirements {#requirements} Before installing any new system, I draftdown a list of requirements I would need this system to run. These are things that are very hard to change on the fly in the future without some serious work. Also, things that simply need to be there in this day and age. ### Filesystem {#filesystem} I'm a big fan of `zfs`. I've been running it on Linux, since the `openzfs` project successfully ported it, with no issues. It's a solid choice for a filesystem and I don't see a reason not to choose it. Is it really a requirement ? Well, yes. By now, `openzfs` should be accessible to all distributions but my choice of distribution is not usually for the beginner user. I need to know it's supported and documented. I can figure out the rest from there. ### Encryption {#encryption} This is the first requirement, I always want encryption. The reason why I put it second in the list is that I needed to talk about `zfs` first. The `zfs` filesystem offers encryption. Unfortunately, my research have shown that `zfs` might not encrypt some metadata. This might not be a big deal but the choice of using Luks is there as well. With Luks, we can encrypt the whole drive. So let's do that; Luks with `zfs` on top. ## NixOS {#nixos} **NixOS** utilizes **Nix** to build you an OS from a configuration file. This configuration file is written in the `nix` language. It is very analogous to written an `Ansible` playbook but it builds an OS instead. The idea sounded appealing to me. A good friend of mine, [setkeh](https://setkeh.com/), gave me a quick and dirty overview, at first. That pushed me into doing more research of my own where I found out that I can spawn off a `nix-shell` with whatever dependencies I want without having them installed on my system. What a great concept for development or even running applications you don't really want to run. `Java` stuff for example. Anyway, for all of these different reasons I have chosen **NixOS** to be the OS of choice to go on the desktop. ## Installation {#installation} After testing [**NixOS**](https://nixos.org/) in a VM a few times, I got `setkeh` on a conference session and we dug into this. ### Filesystem partitioning {#filesystem-partitioning} For the filesystem, we're going to create two partitions. We need one, `vfat`, for the boot and another, `zfs`, for the rest of the filesystem.
Note
The assumption is that we're installing **NixOS** on an `EFI` enabled system.Note
It is usually easier to do the partitioning using `GParted`. Make sure that the partitions are unformatted, if you do so.Warning
Do **NOT** forget to enable the boot flag on the first partition or your system will not boot.Warning
At this sage, you're formatting a partition. Make sure you're pointing to the partition and not your whole disk as in the previous section.