zaphyra's git: nixfiles

zaphyra and void's nixfiles

commit 10a406b632d36afc561bbf0e0d8a22c2b56835a5
parent 444c8af1e46fcd52b2018256631a02349e38d735
Author: Katja (zaphyra) <git@ctu.cx>
Date: Mon, 2 Jun 2025 08:27:34 +0200

config/nixos/modules/impermanence: some chnages
1 file changed, 66 insertions(+), 40 deletions(-)
M
config/nixos/modules/filesystem/impermanence.nix
|
106
+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
diff --git a/config/nixos/modules/filesystem/impermanence.nix b/config/nixos/modules/filesystem/impermanence.nix
@@ -1,6 +1,7 @@
 {
   pov,
   povSelf,
+  hostConfig,
   config,
   lib,
   pkgs,

@@ -74,48 +75,73 @@ in
   };
 
   config = lib.mkMerge [
-    (lib.mkIf (cfg.system.enable && (cfgFilesystem.rootDisk.type == "zfs")) {
-      boot.initrd.systemd.services = {
-        defenestrate = {
-          description = "Defenestrate old root";
-          wantedBy = [ "initrd.target" ];
-          after = [ "zfs-import.target" ];
-          before = [ "sysroot.mount" ];
-          onFailure = [ "emergency.target" ];
-          unitConfig.DefaultDependencies = "no";
-          serviceConfig.Type = "oneshot";
-          script =
-            let
-              prefix = "${config.networking.hostName}/os/nixos/root-";
-            in
-            ''
-              # We keep root from the previous last 3 boots
-              # Any command except create can fail in case the system has not
-              # booted that often yet
-              zfs destroy -r ${prefix}4 || true
-              zfs rename ${prefix}3 ${prefix}4 || true
-              zfs rename ${prefix}2 ${prefix}3 || true
-              zfs rename ${prefix}1 ${prefix}2 || true
-              zfs create -o devices=off -o exec=off -o mountpoint=legacy -o setuid=off ${prefix}1
+    (
+      lib.mkIf cfg.home.enable {
+        assertions = [
+          {
+            assertion = config.modules.filesystem.rootDisk.type == "zfs";
+            message = ''
+              Impermanence is currently only available for ZFS.
             '';
+          }
+        ];
+
+        modules.filesystem.rootDisk.parts.home = true;
+      }
+    )
+    (
+      lib.mkIf cfg.system.enable {
+        assertions = [
+          {
+            assertion = config.modules.filesystem.rootDisk.type == "zfs";
+            message = ''
+              Impermanence is currently only available for ZFS.
+            '';
+          }
+        ];
+
+        modules.filesystem.rootDisk.parts.system = true;
+        boot.initrd.systemd.services = {
+          defenestrate = {
+            description = "Defenestrate old root";
+            wantedBy = [ "initrd.target" ];
+            after = [ "zfs-import.target" ];
+            before = [ "sysroot.mount" ];
+            onFailure = [ "emergency.target" ];
+            unitConfig.DefaultDependencies = "no";
+            serviceConfig.Type = "oneshot";
+            script =
+              let
+                prefix = "${hostConfig.hostName}/os/nixos/root-";
+              in
+              ''
+                # We keep root from the previous last 3 boots
+                # Any command except create can fail in case the system has not
+                # booted that often yet
+                zfs destroy -r ${prefix}4 || true
+                zfs rename ${prefix}3 ${prefix}4 || true
+                zfs rename ${prefix}2 ${prefix}3 || true
+                zfs rename ${prefix}1 ${prefix}2 || true
+                zfs create -o devices=off -o exec=off -o mountpoint=legacy -o setuid=off ${prefix}1
+              '';
+          };
         };
-      };
-      environment.persistence."/nix/persist/system" = {
-        enable = true;
-        hideMounts = true;
-        directories = [
-          "/etc/nixos"
-          "/etc/zfs"
-          "/var/log"
-          "/var/db/sudo/lectured" # "We trust you have received the usual lecture from the local System Administrator."
-          "/var/lib/nixos"
-          "/var/lib/systemd/coredump"
-        ] ++ cfg.system.dirs;
-        files = [
-          "/etc/machine-id"
-        ] ++ cfg.system.files;
-      };
-    })
+        environment.persistence."/nix/persist/system" = {
+          enable = true;
+          hideMounts = true;
+          directories = [
+            "/etc/zfs"
+            "/var/log"
+            "/var/db/sudo/lectured" # "We trust you have received the usual lecture from the local System Administrator."
+            "/var/lib/nixos"
+            "/var/lib/systemd/coredump"
+          ] ++ cfg.system.dirs;
+          files = [
+            "/etc/machine-id"
+          ] ++ cfg.system.files;
+        };
+      }
+    )
   ];
 
 }