How should I install software?

You aren’t crazy–this is a real problem to some degree. But it isn’t Nix-specific. It’s the legacy of taking a container, let’s call it a “data storage device”, and tossing in conceptually-different kinds of data with no great way to tell the types apart aside from knowing what is what. Backup/restore and file sync also struggle with these fundamental mismatches.

The big mess of “state” in a computer is really important, but the value isn’t evenly distributed. Copying the whole mess to another system isn’t very useful. Building the mess of state in each computer manually and consistently is a pain. Keeping the valuable parts in sync across different devices is still a hard problem.

Keeping an archive/copy/backup/repository of dotfiles is one traditional approach that partially addresses this problem, but dotfiles are somewhat divorced from what system they were running on. Nix/NixOS break off a big piece of this problem, making it possible to archive an executable description of what your system and software looked like alongside messier configuration state.

The quick-and-dirty answer: ferret out app config that has value and store it alongside your system config. As they evolve, commit the changes.

The other answer (I’ll resist characterizing it) is to move the config into Nix expressions in one form or another. I don’t really recommend this if you intend to share config with systems that aren’t NixOS, especially if you don’t intend to use Nix on them. Think about your lowest-common-denominator before you convert something.

IIRC there are at least two common ways to do this:

  1. Use the module system(s) (in NixOS, nix-darwin, home-manager, and probably elsewhere), which usually provide a simplified interface for configuring the underlying software. The asterisk is that they’re shaped by the needs and contributions of individuals. They’re a great path forward if the software you need has a module that supports your needs. If not, I don’t think developing or extending a module is a good place to start. (But it’s a great learning exercise once you’ve found your sea legs…)
  2. Cut out the middle-man. Take a config and either read the file into your Nix expression by path, or literally paste the contents into a string, write it into the store as a file, and link it into place.

I think community practice is still evolving here, but hopefully someone else will swat my hand if they feel like a clear best-practice has emerged. How to add my .vimrc straight to config file? · Issue #26754 · NixOS/nixpkgs · GitHub might be an interesting read in this regard.

1 Like