First steps in NixOS
Mon, 15 Jun 2015 15:10:01 +0000
According to the mtime of
/nix on this laptop I've been running
NixOS since February, so I should be past "first steps" by now,
really. But I decided last week to switch to the Nix package
collection on my work Mac as well, and that has prompted me to learn
how to package some of the stuff I use that isn't already available.
(tl;dr - It's here: https://github.com/telent/nix-local/ )
Item zero was to find a way of keeping local packages alongside the
real nixpkgs collection without a permanently divergent fork of the
nixpkgs repo. The approach I eventually decided on was to use
packageOverrides to augment the upstream package list with my own packages in an entirely separate repo. See https://github.com/telent/nix-local/blob/master/README.md#installation for details
With that out of the way, the fist thing I needed to package is vault which is a quite neat program for generating secure passwords given a master secret and a service name - i.e. you can have per-service passwords for each site you use without having to store the passwords anywhere.
by Sander van der
it does dependency management as well as building, and its model of
dependencies (semver, in theory) is considerably more lax than the Nix
model. So we use
npm2nix to produce nix expressions for all its
dependencies from `package.json`
$ git clone firstname.lastname@example.org:jcoglan/vault $ git co 0.3.0 $ `nix-build '<nixpkgs>' -A npm2nix`/bin/npm2nix package.json node-packages.generated.nix
then we copy the generated files into our nix-local repo.
$ mkdir -p ~/nix-local/vault/ $ cp node-packages.generated.nix default.nix ~/nix-local/vault/
The generated default.nix then needed significant manual editing:
- first it gave me
Assertion failed: (!s.empty()), function showId, file src/libexpr/nixexpr.cc, line 33.which seemed to be related to the definition of `tarball`. I replaced this with a call to
depsdefinition in the generated expression produced errors about unknown attributes, so I replaced that line with
deps = (filter (v: nixType v == "derivation") (attrValues nodePackages))
- I fiddled about a lot with the definition of `nodePackages` while trying to fix the first two problems: I don't know if it helped, but it made it look neater
Finally the package can be installed with
nix-env -iA nixpkgs.vault or
nix-env -i nodejs-vault. I don't know which of these is stylistically preferable, but in this case they both have exactly the same effect. As far as I know.