monotux.tech

NixOS, bits & pieces part 1

NixOS

I’ve run NixOS for a year or two now, both on servers and my laptop, and I’ve been quite happy with it so far. But, as always with nix, it is hard to remember some commands & concepts, and the documentation is somewhat…dense. So I’m starting a small series of Nix(OS) tidbits which will at least serve as a reminder for myself.

First up is how to quickly build package definitions without importing them into the system configuration or so. Like when you just want to build a package you found in the nixpkgs repository:

nix-build -E 'with import <nixpkgs> { }; callPackage ./path/to/default.nix { }'

Replace the path to the package definition as needed. Writing this blog entry was a bit ironic, as I had to use the method above to install hugo to build this – the hugo version on my laptop was too old to build this site. Luckily I had the complete command ready this time, no googling required :)

The command above was stolen from StackOverflow.com, just like all other answers for things we should know by heart.