Nixn' it Up (And Burning It Down)

I have been using Linux since 2001, most of the time using Red Hat Linux and Fedora. With a short spell of Arch around 2005-2006. Recently I learned about Guix and played with it for a bit, I thought it was cool, but it had a few issues so I moved on to Nix.

Both Guix and Nix are very different from traditional Linux distributions. They are both based around expression languages that enable the OS to be configured as code. For example, if I want to install and configure Xmonad I could use the following or at it to my configuration. (This is code for another tool, home-manager, but the idea is the same)

{
  xsession = {
    enable = true;


windowManager.xmonad = {
      enable = true;
      enableContribAndExtras = true;
      extraPackages = hp: [
	hp.dbus
	hp.monad-logger
	hp.xmonad-contrib
      ];
      config = /home/zoglesby/s/dot/xmonad/xmonad.hs;
    };
  };
}

This type of configuration allows for a workflow similar to Ansible, Puppet, or Chef. The difference is that the package manager and the operating system are aware of the state. Role backs, for instance, are supported, even at the boot menu level. If you change your configuration and break the start-up process, you can simply boot into the previous configuration and fix it. This feature is built-in functionality that the OS is aware of, not something bolted on like many of the ZFS/package manager solutions that are popular now.

Nix is also not dependent on the traditional file system structure for binaries that most Linux distributions use. While you typically find Python at /usr/bin/python or something similar, Nix uses a hash such as /nix/store/hb1lzaisgx2m9n29hqhh6yp6hasplq1v-python3-3.9.10/bin/python. This hashed path enables several cool features, but the first is that you can use more than one version of Python or any other tool.

Nix-shell also allows you to have dependencies that are not in your $PATH for specific projects or folders. So you can cd into a directory where all of your dev tools will show up, but they will not be there while you are doing random things on your computer. It can also be helpful if you just need to run a program once but don't want to keep it installed as it can be cleaned up automatically later without you having to do anything.

[zoglesby@trill:~]$ which python
which: no python in (/run/wrappers/bin:/home/zoglesby/.nix-profile/bin:/etc/profiles/per-user/zoglesby/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin)

[zoglesby@trill:~]$ nix-shell -p python3

[nix-shell:~]$ which python
/nix/store/hb1lzaisgx2m9n29hqhh6yp6hasplq1v-python3-3.9.10/bin/python

I want to cover more about Nix in more depth in the coming weeks. For instance, how I have moved all of my servers to it, or the Surface Go 2 I am using Nix and Gnome on for a Linux-based tablet.