FliegendeWurst's corner of the WWW

Listing running Nix builds

2025-01-08 (updated )

It isn't easy to get the builds currently executed by the Nix daemon. In a relevant Discourse thread, the wonderful nix-output-monitor was suggested. Whilst that tool is very nice, it has two drawbacks: you need to remember to use it and it only lists builds for one command.

To get all builds running on the system, use the following bash/zsh command. It requires parallel (from moreutils), pgrep, ripgrep, xargs (from findutils) and my own recursive-cpu-usage. (If not needed, you can remove that part in the first line.)

nd=$(pgrep nix-daemon | head -n1)  && sudo parallel sh -c 'echo "$(recursive-cpu-usage $0)" \
 $(cat /proc/$0/environ | tr "\\0" "\\n" | rg "^(pname|version)=(.+)" - --replace "\$2" \
 | tr "\\n" " ")' -- $(cat "/proc/$nd/task/$nd/children" | tr ' ' '\n' \
 | xargs -L 1 sh -c 'cat /proc/$0/task/*/children') | sort --numeric

Example output:

 0.0 httplib2 0.22.0
 0.1 libpng 1.6.43
 0.5 element-web 1.11.89
 0.8 libnice 0.1.22
 1.6 onnxruntime 1.18.1
 2.7 seshat-node 2.3.3
23.0 qtlocation 5.15.16

The output is easily customizable to list other properties beyond the package name and version. For example, to list the name instead you only need to replace pname|version with name in the command. Useful if you want to know which packages are cross-compiling.

 0.2 aarch64-unknown-linux-gnu-rustc-1.83.0
 0.2 element-web-1.11.89
 2.3 openjdk-headless-17.0.13+11
 2.7 onnxruntime-1.18.1
 6.7 gtk4-4.16.7
 7.7 qtwebengine-5.15.18
 8.6 maturin-1.8.1

UPDATE: enhanced version with PID and time since build started.

ntop() {
 nd=$(pgrep nix-daemon | head -n1) && sudo parallel sh -c '
  secs=$(ps -o etimes= -p "$0");
  time=$(printf " %02dd %02dh %02dm %02ds " $((secs/(3600*24))) $((secs/3600%24)) $((secs%3600/60)) $((secs%60)));
  time="${time//00m/   }";
  time="${time//00h/   }";
  time="${time//00d/   }";
  pid=$(printf "%07d" $0);
  echo "PID $pid $time $(recursive-cpu-usage $0)" $(cat /proc/$0/environ | tr "\\0" "\\n" \
   | rg "^(name)=(.+)" - --replace "\$2" | tr "\\n" " ")' -- $(cat "/proc/$nd/task/$nd/children" \
   | tr ' ' '\n' | xargs -L 1 sh -c 'cat /proc/$0/task/*/children') \
   | sort | sed -s "s/ 00/   /g" | sed -s "s/ 0/  /g" | sed -s "s/m   s/m  0s/g"
}

Example output:

PID 3209181           9m 46s   1.8 qemu-9.2.0
PID 3552584           3m 24s   3.4 sleuthkit-4.12.1
PID 3580332           2m 43s   1.5 naja-0-unstable-2024-08-27
PID 3580604           2m 43s    .5 naja-aarch64-unknown-linux-gnu-0-unstable-2024-08-27
PID 3602884           2m  2s  18.1 systemd-257.1
PID 3619809           1m 25s    .2 nfs-utils-2.7.1
PID 3628731           1m  8s   1.9 libcxx-19.1.6
PID 3665614               1s    .9 temurin-bin-23.0.0


© FliegendeWurst, 2022-2025 (excluding evident exceptions). Website source. Contact.
This work is licensed under a Creative Commons Attribution 4.0 International License.
Website design inspired by Isabel Roses' website and Utku Demir's website.