Functional Package Management

I just read a great paper about NixOS, a Linux distribution with a “purely functional” package manager. I’ve been thinking about the parallels between programming and system administration, and this is a brilliant use of the comparison. They created a package manager named Nix where all packages are built and maintained independently even of other versions of themselves.

I’m surprised there are sysadmins who miss obvious ways to improve their systems, like keeping a server’s /etc and cron jobs under version control. Cloning server configs from each other. Automated backups. Automated rotating and pruning of logs. Writing scripts to set up any software not covered by the package manager — or, better, building packages. Uptime and performance monitoring and alerts.

(The list goes on. This is my basic competency list. I got a lot of these techniques from watching a great sysadmin in action, reading some sysadmin blogs (curiously, sysadmins do not seem to blog nearly as prolifically as developers), pondering what programming skills and tools I can apply, and hours and hours of hair-tearing experience. I’m regularly surprised by how infrequently these things are done, even the really obvious bits of automation.)

I’ve long realized these techniques are about making system setups known and repeatable, like boiling down a test case in a programming language. What I didn’t recognize until I read the NixOS paper is that this is about the same kind of determinism that drives functional programming languages. Running systems are like imperative programs, and the core goal is minimizing the amount of potential state that can 1. exist 2. be unknown 3. blow things up. Imagine reversing all the effects of a function call in a procedural language with global variables kicking around: it’s the exact same problem as reversing the effects of upgrading a piece of software.

It looks like Nix has some great features I can’t imagine “imperative” package managers supporting well, like non-privileged users installing software. My sysadmin work is lately limited to the usual developer kvetching about one’s dedicated sysadmins, so I haven’t dived too deeply (I plan to play with it in a VM sometime soon). Looking at NixOS has left me with a desire to practice more functional programming. The cross-pollination from one field to another is invaluable.

Want more? I'm not as good at forgetting to update @pushcx on Twitter.