Skip to content

Commit 7a5424d

Browse files
authored
modules/nix: init activation-script (nushell#848)
1 parent adaae97 commit 7a5424d

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

modules/nix/README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Nix
22

3-
Commands for working with [nix](https://nixos.org/).
3+
Commands for working with [nix/nixos](https://nixos.org/).
44

55
### ns
66
Shorthand search (`nix search nixpkgs ...`) with much nicer output.
@@ -24,3 +24,31 @@ Shorthand search (`nix search nixpkgs ...`) with much nicer output.
2424
╰───┴────────────────┴──────────────────────────────────────────────────────────────┴─────────╯
2525
```
2626

27+
### activation-script
28+
29+
Shows changed packages after running `nixos-rebuild switch/boot` and change in total size of installed packages. Changes that don't affect the installed size are filtered out. Intended to be added to `configuration.nix` of `NixOS`.
30+
31+
```
32+
╭─────────────────┬─────────────┬─────────────┬───────────╮
33+
│ Package │ Old_Version │ New_Version │ Diff │
34+
├─────────────────┼─────────────┼─────────────┼───────────┤
35+
│ xwayland │ ∅ │ 24.1.0 │ 5.3 MB │
36+
│ lsp-plugins │ 1.2.15 │ 1.2.16 │ 1.1 MB │
37+
│ libei │ ∅ │ 1.2.1 │ 547.6 KB │
38+
│ libXfont2 │ ∅ │ 2.0.6 │ 270.0 KB │
39+
│ xkbcomp │ ∅ │ 1.4.7 │ 235.7 KB │
40+
│ font-util │ ∅ │ 1.4.1 │ 234.1 KB │
41+
│ libxkbfile │ ∅ │ 1.1.3 │ 174.6 KB │
42+
│ xfsprogs │ 6.6.0 │ 6.8.0 │ 61.0 KB │
43+
│ xcb-util-errors │ ∅ │ 1.0.1 │ 48.5 KB │
44+
│ libieee1284 │ 0.2.11 │ ∅ │ -123.1 KB │
45+
│ libgnomekbd │ 3.28.1 │ ∅ │ -702.0 KB │
46+
│ xwayland │ 24.1.0 │ ∅ │ -5.3 MB │
47+
│ libgweather │ 4.4.0 │ ∅ │ -23.8 MB │
48+
╰─────────────────┴─────────────┴─────────────┴───────────╯
49+
50+
╭──────┬──────────╮
51+
│ Diff │ -22.0 MB │
52+
╰──────┴──────────╯
53+
```
54+

modules/nix/activation-script

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### add to configuration.nix
2+
3+
nix.settings.experimental-features = ["nix-command"];
4+
5+
system.activationScripts.diff = ''
6+
if [[ -e /run/current-system ]]; then
7+
echo
8+
${pkgs.nushell}/bin/nu -c "let diff_closure = ${pkgs.nix}/bin/nix store diff-closures /run/current-system '$systemConfig'; if \$diff_closure != \"\" { let table = \$diff_closure | lines | where \$it =~ KiB | where \$it =~ → | parse -r '^(?<Package>\S+): (?<Old_Version>[^,]+)(?:.*) → (?<New_Version>[^,]+)(?:.*, )(?<DiffBin>.*)$' | insert Diff { get DiffBin | ansi strip | str trim -l -c '+' | into filesize } | reject DiffBin | sort-by -r Diff; print \$table; \$table | math sum }"
9+
fi
10+
'';
11+

0 commit comments

Comments
 (0)