diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-10-17 15:24:26 +0200 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-10-17 15:24:28 +0200 |
commit | 29b5140a343448ed1873cc5225ffe656a3b13fda (patch) | |
tree | bc31ac3e1ab2a146626697d6159dd67be6954ec8 /hardware/virtualbox | |
parent | Modules/Secrets: Wiregurad: Change peer settings (diff) | |
download | nixos-config-29b5140a343448ed1873cc5225ffe656a3b13fda.tar.gz nixos-config-29b5140a343448ed1873cc5225ffe656a3b13fda.tar.bz2 nixos-config-29b5140a343448ed1873cc5225ffe656a3b13fda.zip |
Hardware: Disks: Add diff-root utility
This utility allows to check what changed in the / from boot till the execution of the command. Useful for knowing what to persist.
Diffstat (limited to '')
-rw-r--r-- | hardware/virtualbox/disks.nix | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/hardware/virtualbox/disks.nix b/hardware/virtualbox/disks.nix index ab2e053..330b4ac 100644 --- a/hardware/virtualbox/disks.nix +++ b/hardware/virtualbox/disks.nix @@ -44,6 +44,22 @@ let mount -o compress-force=zstd,noatime /dev/mapper/encrypted_root_pool-persist /mnt/persist mount -o compress-force=zstd,noatime /dev/mapper/encrypted_root_pool-nix /mnt/nix ''; + + # Utility to save a snapshot of the root tree + save-root = pkgs.writers.writeDashBin "save-root" '' + ${pkgs.findutils}/bin/find \ + / -xdev \( -path /tmp -o -path /var/tmp -o -path /var/log/journal \) \ + -prune -false -o -print0 | sort -z | tr '\0' '\n' > "$1" + ''; + + # Utility to compare the root tree + diff-root = pkgs.writers.writeDashBin "diff-root" '' + export PATH=${with pkgs; lib.makeBinPath [ diffutils less ]}:$PATH + current="$(mktemp current-root.XXX --tmpdir)" + trap 'rm "$current"' EXIT INT HUP + ${save-root}/bin/save-root "$current" + diff -u /run/initial-root "$current" --color=always | ''${PAGER:-less -R} + ''; in { config = { @@ -118,7 +134,19 @@ in config.disks-create config.disks-format config.disks-mount + + diff-root ]; + + systemd.services.save-root-snapshot = { + description = "save a snapshot of the initial root tree"; + wantedBy = [ "sysinit.target" ]; + requires = [ "-.mount" ]; + after = [ "-.mount" ]; + serviceConfig.Type = "oneshot"; + serviceConfig.RemainAfterExit = true; + serviceConfig.ExecStart = ''${save-root}/bin/save-root /run/initial-root''; + }; }; options.disks-create = with lib; mkOption rec { |