and here’s a nushell version (edit: tiny update to work with current nu as it evolves)
def gcdu [
--processes (-p) # also show roots from running processes
]: nothing -> table {
let roots = ^nix-store --gc --print-roots
| parse "{root} -> {closure}"
| where root !~ '{censored}|^/proc' or $processes
| group-by --to-table closure
| rename path roots
| update roots { get root | sort | str join "\n" }
let pathinfo = ^nix path-info --closure-size --json ...($roots | get path)
| from json
| select closureSize narSize path
| into filesize closureSize narSize
$roots | join $pathinfo path
| update path { path basename }
| rename -c { path: "store path" }
| sort-by -r closureSize
}
in addition to the shell/syntax differences, this version uses a different method to find the roots in a way that shows the thing(s) you want to delete in order to let the closure get gc’d, and groups them together.
sample output, in md format (slightly modified because discourse’s md tables don’t do inner newlines)
❯ gcdu | take 10 | to md -p
store path | roots | closureSize | narSize |
---|---|---|---|
qvz2lfr2513g26m41h8jrfy9p9vwz62i-nixos-system-oenone-24.11.20241111.dc460ec | /nix/var/nix/profiles/system-557-link | 31.9 GiB | 157.5 KiB |
lbm6m1q8jg9lc02fwjs79x6jx64a1k5z-nixos-system-oenone-24.11.20241109.76612b1 | /nix/var/nix/profiles/system-556-link | 31.9 GiB | 157.5 KiB |
94dh5jxqfbknbpyvx3dmkswvf97n9pgf-nixos-system-oenone-24.11.20241109.76612b1 | /nix/var/nix/profiles/system-555-link | 31.9 GiB | 157.5 KiB |
611ma22g3azfzify0yc2sxyshwr4p4kv-nixos-system-oenone-25.05.20241115.5e4fbfb | /nix/var/nix/profiles/system-559-link /run/booted-system /run/current-system |
29.4 GiB | 157.5 KiB |
aq3pnl3xfcg2h68lx7iwv7knj7992mwc-nixos-system-oenone-25.05.20241115.5e4fbfb | /nix/var/nix/profiles/system-558-link | 29.3 GiB | 157.5 KiB |
ifrfgpyilgvigl2iary8dsxswn9313iq-nix-shell-env | /home/dan/work/resl/qualysdata/.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa | 2.8 GiB | 72.8 KiB |
2zwmk2wsxm534qyb3597p12y3bs1wim2-nix-shell-env | /data/foss/rust/serde-norway/.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa | 1.6 GiB | 84.5 KiB |
vysk2fzd96zyv1qdsd9j9x4fwdi93jpk-home-manager-generation | /home/dan/.local/state/nix/profiles/home-manager-248-link | 1021.8 MiB | 14.5 KiB |
fjbyx7bkzfahpiklab7m1k6qzngq7d2q-home-manager-generation | /home/dan/.local/state/nix/profiles/home-manager-247-link | 1017.9 MiB | 14.5 KiB |
z4cjvbn055bqsdgs3sjj0whs6m8gmasx-home-manager-generation | /home/dan/.local/state/nix/profiles/home-manager-246-link | 1017.9 MiB | 14.5 KiB |