Lagrange Point

Distro reviews: NixOS

What is NixOS?

Nix is a functional package manager and it also has an operating system built around it, called NixOS. Together it makes for quite a powerful combo.

I have been using NixOS now for many years, and I do find it to generally be usable and rock solid, despite it’s many quirks. I still haven’t taught myself the Nix language, though. Just haven’t found the need to do that for some reason. I just follow example Nix configs, either in the docs or from other online places.

For a summary of how NixOS works, you can go to the official site. Nevertheless it uses a lot of systemd benefits to make all the magic glue come together.

Of course, there’s also Guix, which is a NixOS derivative, but it doesn’t use systemd, but shepherd, their own custom init system. The neat thing about shepherd, compared to systemd, is that you can customize everything in the Guile Scheme language. I mean, you can customize all of Guix in Guile Scheme. It’s a lisp dream system, really. But, imho, it does have a drawback, which is finding good hardware and a good connection to get it to run. That
plagues NixOS too, somewhat. Both NixOS and Guix have seemingly higher than normal system requirements, but more so Guix since it’s rolling release.

NixOS First Steps

If you’re first getting started with NixOS, I would recommend doing the simple install first, and it now includes a good installer too! After installation, take a look at configuration.nix file in /etc/nixos/.

I would recommend to add simple things like enabling Steam or OpenSSH by perusing the wiki. Copying and pasting is fine, since all NixOS operations are atomic. If you get/do something wrong, it doesn’t make a huge difference since you can rollback to a previous config after running(As root) nixos-rebuild switch!

You can also install packages in a non-declarative manner via the command “nix-env -iA “. Be sure to look at the NixOS site search to double check for the package and it’s name you want.

I believe NixOS is revamping it’s non-declarative package installation and other functions with a command set more comparable to Guix’s.

Guix is pretty simple in comparison in regards to packages,
just a easy invocation of “guix install ” and you’re good to go.

Further NixOS customization

Once you’re familiar with the above, I would suggest looking online
for other NixOS configs and basically stealing what works from them. Also look at the Wiki more and and various other sites for finding inspiration.

Did you know that NixOS has ZFS integration into it’s kernel?
You can install NixOS onto a ZFS root if you so desire! But you
also have to do the entire install via the command line if you end
doing so. It’s not that hard, just time-consuming. I can help you
get started tho…

OK, assuming you started the LiveCD with either Plasma or GNOME, open up either Konsole or GNOME Terminal/Console. Become root via “sudo su”. After becoming root, identify your hard drive/SSD through something like “lsblk –fs” command. After finding the root of your drive which would be like “/dev/sda” or “/dev/nvm0n1”, use a tool like cfdisk, parted or something else of that nature and partition the disk. Once you’ve designated the root partition, run something like this “zpool create rpool /dev/sda2”. Now you’ve created a zpool! Next, we need to create some datasets in the pool. I would suggest creating a root dataset and home dataset, at minimum. You can do by going “zfs create mountpoint=legacy rpool/root” for a root partition and then
“zfs create mountpoint=legacy rpool/root/home” for the home partition.

Next, mount the root partition onto /mnt, like so “mount -t zfs rpool/root /mnt”. Then create the home dir in the root partition you just mounted. “mkdir /mnt/home”. Now we mount the zfs home partition we created onto home partition we created. Like so
“mount -t zfs rpool/root/home /mnt/home”. I’m assuming you also created swap space and a boot partition, and turned on swap. If not, see the end of this article on how to do that.

Now just run “nixos-generate-config –root /mnt”. NixOS will generate a config file in “/mnt/etc/nixos/configuration.nix”, which you can edit with something like nano or vi. You will need to add a couple of options to the config file. First, find your host ID,
which you can find by running “head -c 8 /etc/machine-id” I believe.(I will double check). Then you need to do this, add the following: “boot.supportedFilesystems = [ “zfs” ];”. You need to add the hostID config option as well. I will supply that at the end of article too. After editing it to your fit your preferences, run “nixos-install”, and after that does a ton of output, it will ask for a root password. Type in something good, and it will finish.

Congrats, you now have a NixOS system with ZFS!

Advanced NixOS

I’m still learning more of the advanced things you can do with NixOS AND Guix, but I am having lots of fun doing so. One thing you can check out that’s brewing for Nix and NixOS is flakes.

I will put out an article on flakes another time, as I’m still learning them myself.

Configuration.nix appends

“boot.loader.grub.device = “/dev/nvme0n1″;”
“networking.hostId = “”;”
“boot.supportedFilesystems = [“zfs”];”

All the appends are needed to get ZFS to be recognized on boot by NixOS.

How to create boot and swap easily

For creating the boot partition easily, assuming you have a UEFI system, and assuming you partitioned the disks already with the /dev/sda1 partition as the EFI FIle System type, you can simply type the following: As root: “mkfs.vfat -n BOOT /dev/sda1”. Done.
As for creating swap, it’s just as easy as boot. Assuming you put swap partition on /dev/sda3, simply type as root: “mkswap -L SWAP /dev/sda3”. Then, run the following to turn swap space on. As root: “swapon /dev/sda3”.
The end!