Skip to content

Commit

Permalink
init nixos/activation script
Browse files Browse the repository at this point in the history
  • Loading branch information
Schweber committed May 26, 2024
1 parent 93e71fe commit 21fd182
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
30 changes: 29 additions & 1 deletion modules/nix/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Nix

Commands for working with [nix](https://nixos.org/).
Commands for working with [nix/nixos](https://nixos.org/).

### ns
Shorthand search (`nix search nixpkgs ...`) with much nicer output.
Expand All @@ -24,3 +24,31 @@ Shorthand search (`nix search nixpkgs ...`) with much nicer output.
╰───┴────────────────┴──────────────────────────────────────────────────────────────┴─────────╯
```

### activation-script

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`.

```
╭─────────────────┬─────────────┬─────────────┬───────────╮
│ Package │ Old_Version │ New_Version │ Diff │
├─────────────────┼─────────────┼─────────────┼───────────┤
│ xwayland │ ∅ │ 24.1.0 │ 5.3 MB │
│ lsp-plugins │ 1.2.15 │ 1.2.16 │ 1.1 MB │
│ libei │ ∅ │ 1.2.1 │ 547.6 KB │
│ libXfont2 │ ∅ │ 2.0.6 │ 270.0 KB │
│ xkbcomp │ ∅ │ 1.4.7 │ 235.7 KB │
│ font-util │ ∅ │ 1.4.1 │ 234.1 KB │
│ libxkbfile │ ∅ │ 1.1.3 │ 174.6 KB │
│ xfsprogs │ 6.6.0 │ 6.8.0 │ 61.0 KB │
│ xcb-util-errors │ ∅ │ 1.0.1 │ 48.5 KB │
│ libieee1284 │ 0.2.11 │ ∅ │ -123.1 KB │
│ libgnomekbd │ 3.28.1 │ ∅ │ -702.0 KB │
│ xwayland │ 24.1.0 │ ∅ │ -5.3 MB │
│ libgweather │ 4.4.0 │ ∅ │ -23.8 MB │
╰─────────────────┴─────────────┴─────────────┴───────────╯
╭──────┬──────────╮
│ Diff │ -22.0 MB │
╰──────┴──────────╯
```

11 changes: 11 additions & 0 deletions modules/nix/activation-script
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### add to configuration.nix

nix.settings.experimental-features = ["nix-command"];

system.activationScripts.diff = ''
if [[ -e /run/current-system ]]; then
echo
${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 }"
fi
'';

0 comments on commit 21fd182

Please sign in to comment.