Who cares how Nix works?


written by James Larisch on August 11, 2019.

I’ve been using NixOS for the past year. It has significantly improved my life. I have no idea how it works. I have no idea how to write a Nix expression. I will learn, eventually, but right now I don’t care, and I don’t need to care. This is what I know: Nix lets me specify the configuration of my Linux distribution (sans home directory) in one file. I can easily see all of the packages installed on my machine, global configuration such as DNS servers, which desktop manager I’m currently using, and more. It makes configuring and maintaining my computer a breeze. You don’t need to care how Nix works. If you’re crazy enough to run Ubuntu, you are crazy enough to run NixOS. If you aren’t that crazy, you can install & use the Nix package manager on other Linux distros or MacOS.

What’s the problem? Configuring a Linux (and to a lesser extent, MacOS) machine for daily use is an exercise in masochism. You use various tools to modify settings, install drivers, install software packages, add themes, change colors, add fonts, modify kernel parameters, mount disks on startup, and more. At the end, you feel like you have a working Linux distribution, but really all you have is a castle of duct tape that will collapse given the mildest breeze (and by breeze I mean apt-get install).

I don’t have those problems. I have one file. Look, I’ve enabled systemd-boot:

boot.loader.systemd-boot.enable = true;

And look, here are my kernel parameters:

boot.kernelParams = [ "acpi_rev_override=1" "ipv6.disable=1" ];

I want the option of running KDE Plasma, i3, or both, so I put this in that file:

services.xserver = {
  videoDrivers = ["intel"];
  xkbOptions = "ctrl:nocaps";
  layout = "us";
  enable = true;
  displayManager.sddm = {
    enable = true;
  };
  desktopManager.plasma5.enable = true;
  windowManager.i3.enable = true;
};

Which also remaps CapsLock to Ctrl.

Here are some fonts:

fonts.fonts = with pkgs; [
   source-code-pro
   source-sans-pro
   hasklig
   fira-code-symbols
];

And here are some packages:

environment.systemPackages = [
  httpie
  neovim
  openssl
  powertop
  htop
  firefox
  spotify
  thunderbird
  tmux
];

When I want to install a package, I add it to that file, type sudo nixos-rebuild switch, and then I feel good. Because my computer now reflects what’s in this file. And this file describes my computer. If I were the Nix developers, I would focus on this experience. I’d love the ability to specify all of my global Ruby gems, Python packages, NPM packages, Go packages, etc in this one file. People (I) use Linux because I want control over everything, not because I think the experience is actually better than say MacOS. As a result, I’ve often considered switching back to the Mac ecosystem. But Nix, and this experience in particular, holds me back. I don’t think I could return to a homebrew-based world.

A few items of note

  • This posts only scratches the surface in terms of the things Nix is capable of.
  • I don’t love the fact that all of the Nix packages are in one giant GitHub repository.
  • Nix Flakes.
  • Home Manager for applying this principle to your home directory configuration files. Never tried it.