NixOS 22.05 release

June 11, 2022

Last month NixOS-22.05 release came out. If you never seent it you should give it a try: https://nixos.org/download.html#nixos-iso.

I took the release event as a good excude to share a few tips.

Nicer logs

Nix is full of boring paths with long prefixes like /nix/store/xk0rdw0sj3ysnjyh90z85mlx3w0kab5s-coreutils-full-9.1/bin/ls. It’s a lot longer than /usr/bin/ls. But with all the noise it contains useful hint that ls comes from coreutils package.

$ ls -l /run/current-system/sw/bin/ls
lrwxrwxrwx 9 root root 69 Jan  1  1970 /run/current-system/sw/bin/ls -> /nix/store/xk0rdw0sj3ysnjyh90z85mlx3w0kab5s-coreutils-full-9.1/bin/ls

To save some space and keep useful detail I’m using ~/bin/unnix one-liner:

#!/usr/bin/env bash

sed -r 's@/nix/store/[0-9a-z]{32}-@/<<NIX>>/@g'

It leaves out hashes but not package names or versions:

$ ls -l /run/current-system/sw/bin/ls |& unnix
lrwxrwxrwx 9 root root 69 Jan  1  1970 /run/current-system/sw/bin/ls -> /<<NIX>>/coreutils-full-9.1/bin/ls

I frequently use unnix to compare build logs from different environments.

Running binaries from arbitrary nixpkgs commits

Normally you can pull in a program in your environment by installing it. Or by running it directly:

$ nix run nixpkgs#re2c -- --version
re2c 3.0

But sometimes it’s useful to run a program from a specific commit of a repository. Flake syntax allows you to do it as is:

$ nix run github:NixOS/nixpkgs/4a7f99d55d299453a9c2397f90b33d1120669775#re2c -- --version
re2c 1.3

With GitHub’s synthetic branches you can even run tools right from yet unmerged PRs against nixpkgs:

# Use firefox from (then) yet unmerged PR: https://github.com/NixOS/nixpkgs/pull/175618
$ nix run github:NixOS/nixpkgs/pull/175618/merge#firefox

Be careful to review the commit first. You are running something that is not yet a part of nixpkgs proper.

Pulling cross-compiler environments with pkgsCross

nixpkgs has a pkgsCross.* package prefix with a ton of cross-compilers available. It makes portability related work a breeze. We can pull the cross-compiler in with a simple nix develop run:

$ nix develop nixpkgs#pkgsCross.mingw32.re2c
$ dev>LANG=C i686-w64-mingw32-gcc -v |& unnix
Using built-in specs.
COLLECT_GCC=/<<NIX>>/i686-w64-mingw32-stage-final-gcc-debug-10.3.0/bin/i686-w64-mingw32-gcc
COLLECT_LTO_WRAPPER=/<<NIX>>/i686-w64-mingw32-stage-final-gcc-debug-10.3.0/libexec/gcc/i686-w64-mingw32/10.3.0/lto-wrapper
Target: i686-w64-mingw32
Configured with:
Thread model: mcf
Supported LTO compression algorithms: zlib
gcc version 10.3.0 (GCC)

Mass updates for maintained packages

I have a bunch if local packages I occasionally update. nixpkgs has a script to update them automatically:

# run from nixpkgs checkout:
$ nix-shell maintainers/scripts/update.nix --argstr maintainer trofi --arg include-overlays true
Going to be running update for following packages:
 - CorsixTH-unstable-2022-05-23
 - dwarffs-unstable-2022-03-06
 - multitextor-unstable-2022-04-22
 - seekwatcher-0.14
 - ski-unstable-2022-04-18
 - vcmi-unstable-2022-05-28

Press Enter key to continue...

Running update for:
 - CorsixTH-unstable-2022-05-23: UPDATING ...
 - dwarffs-unstable-2022-03-06: UPDATING ...
 - multitextor-unstable-2022-04-22: UPDATING ...
 - seekwatcher-0.14: UPDATING ...
 - seekwatcher-0.14: DONE.
 - ski-unstable-2022-04-18: UPDATING ...
 - dwarffs-unstable-2022-03-06: DONE.
 - vcmi-unstable-2022-05-28: UPDATING ...
 - multitextor-unstable-2022-04-22: DONE.
 - ski-unstable-2022-04-18: DONE.
 - CorsixTH-unstable-2022-05-23: DONE.
 - vcmi-unstable-2022-05-28: DONE.

Now all it takes is to build/run the packages to see if things still work. We got 2 updates ready to commit as is:

$ LANG=C git status
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   corsix-th/default.nix
        modified:   vcmi/default.nix

$ nix build -f. corsix-th vcmi

$ LANG=C ls -l | unnix
...
lrwxrwxrwx 1 slyfox users   72 Jun 11 19:06 result -> /<<NIX>>/CorsixTH-unstable-2022-06-07
lrwxrwxrwx 1 slyfox users   68 Jun 11 19:06 result-1 -> /<<NIX>>/vcmi-unstable-2022-06-11

$ ./result/bin/corsix-th
$ ./result-1/bin/vcmiclient

Ready to be committed.