Nix flake configuration for my various machines (clients and homelab servers)
0

Configure Feed

Select the types of activity you want to include in your feed.

fix eval error for initrd => systemd service

Parthiv Krishna (Apr 26, 2026, 10:55 PM UTC) 54550b00 da3e1319

+43 -24
+4 -1
hosts/icicle/default.nix
··· 49 49 }; 50 50 51 51 meta = { 52 - impermanence.rootPartitionPath = "/dev/root_vg/root"; 52 + impermanence = { 53 + rootPartitionPath = "/dev/root_vg/root"; 54 + encryptedDevice = true; 55 + }; 53 56 sops.sopsFile = "icicle.yaml"; 54 57 }; 55 58
+39 -23
modules/features/meta/impermanence.nix
··· 12 12 description = "Path to root partition (will be wiped on boot)"; 13 13 }; 14 14 15 + encryptedDevice = lib.mkOption { 16 + type = lib.types.bool; 17 + default = false; 18 + description = "Whether the root partition is on an encrypted device. If true, wipe-root will wait for cryptsetup.target."; 19 + }; 20 + 15 21 # Home persistence options 16 22 directories = lib.mkOption { 17 23 type = lib.types.listOf lib.types.str; ··· 30 36 cfg: 31 37 { lib, ... }: 32 38 { 33 - # startup script from https://github.com/nix-community/impermanence 39 + # systemd service for impermanence root wipe from https://github.com/nix-community/impermanence 40 + # runs in initrd to: 34 41 # 1. backup current state of root 35 42 # 2. clear out backups older than 30d 36 - # 3. make a new empty root 37 - boot.initrd.postDeviceCommands = lib.mkAfter '' 38 - mkdir /btrfs_tmp 39 - mount ${cfg.rootPartitionPath} /btrfs_tmp 40 - if [[ -e /btrfs_tmp/root ]]; then 41 - mkdir -p /btrfs_tmp/old_roots 42 - timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S") 43 - mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp" 44 - fi 43 + # 3. make a new empty root subvolume 44 + boot.initrd.systemd.services.wipe-root = { 45 + description = "Wipe BTRFS root subvolume for impermanence"; 46 + wantedBy = [ "initrd.target" ]; 47 + after = lib.optionals cfg.encryptedDevice [ "cryptsetup.target" ]; 48 + before = [ "sysroot.mount" ]; 49 + unitConfig.DefaultDependencies = "no"; 50 + serviceConfig.Type = "oneshot"; 51 + script = '' 52 + mkdir -p /btrfs_tmp 53 + mount ${cfg.rootPartitionPath} /btrfs_tmp 45 54 46 - delete_subvolume_recursively() { 47 - IFS=$'\n' 48 - for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do 49 - delete_subvolume_recursively "/btrfs_tmp/$i" 50 - done 51 - btrfs subvolume delete "$1" 52 - } 55 + if [[ -e /btrfs_tmp/root ]]; then 56 + mkdir -p /btrfs_tmp/old_roots 57 + timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S") 58 + mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp" 59 + fi 60 + 61 + delete_subvolume_recursively() { 62 + IFS=$'\n' 63 + for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do 64 + delete_subvolume_recursively "/btrfs_tmp/$i" 65 + done 66 + btrfs subvolume delete "$1" 67 + } 53 68 54 - for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do 55 - delete_subvolume_recursively "$i" 56 - done 69 + for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do 70 + delete_subvolume_recursively "$i" 71 + done 57 72 58 - btrfs subvolume create /btrfs_tmp/root 59 - umount /btrfs_tmp 60 - ''; 73 + btrfs subvolume create /btrfs_tmp/root 74 + umount /btrfs_tmp 75 + ''; 76 + }; 61 77 62 78 # make sure /persist is available during boot 63 79 fileSystems."/persist".neededForBoot = lib.mkForce true;