about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorWilliButz <willibutz@posteo.de>2024-03-19 17:42:22 +0100
committerWilliButz <willibutz@posteo.de>2024-03-21 11:37:43 +0100
commit5282cdd926c0784073b420c11077093c40819ede (patch)
tree5936a88a98323007ba656d64d4744b514a3f94b8 /nixos
parentd7ef2defdadd066beaa81c82206dc23217402ef6 (diff)
downloadnixlib-5282cdd926c0784073b420c11077093c40819ede.tar
nixlib-5282cdd926c0784073b420c11077093c40819ede.tar.gz
nixlib-5282cdd926c0784073b420c11077093c40819ede.tar.bz2
nixlib-5282cdd926c0784073b420c11077093c40819ede.tar.lz
nixlib-5282cdd926c0784073b420c11077093c40819ede.tar.xz
nixlib-5282cdd926c0784073b420c11077093c40819ede.tar.zst
nixlib-5282cdd926c0784073b420c11077093c40819ede.zip
nixos/repart-image: add internal option to expose finalPartitions
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/image/repart.nix36
1 files changed, 23 insertions, 13 deletions
diff --git a/nixos/modules/image/repart.nix b/nixos/modules/image/repart.nix
index aa5426cef076..f9f4754b1656 100644
--- a/nixos/modules/image/repart.nix
+++ b/nixos/modules/image/repart.nix
@@ -211,6 +211,15 @@ in
       '';
     };
 
+    finalPartitions = lib.mkOption {
+      type = lib.types.attrs;
+      internal = true;
+      readOnly = true;
+      description = lib.mdDoc ''
+        Convenience option to access partitions with added closures.
+      '';
+    };
+
   };
 
   config = {
@@ -224,6 +233,16 @@ in
             "zstd" = ".zst";
             "xz" = ".xz";
           }."${cfg.compression.algorithm}";
+
+        makeClosure = paths: pkgs.closureInfo { rootPaths = paths; };
+
+        # Add the closure of the provided Nix store paths to cfg.partitions so
+        # that amend-repart-definitions.py can read it.
+        addClosure = _name: partitionConfig: partitionConfig // (
+          lib.optionalAttrs
+            (partitionConfig.storePaths or [ ] != [ ])
+            { closure = "${makeClosure partitionConfig.storePaths}/store-paths"; }
+        );
       in
       {
         name = lib.mkIf (config.system.image.id != null) (lib.mkOptionDefault config.system.image.id);
@@ -239,6 +258,8 @@ in
             "xz" = 3;
           }."${cfg.compression.algorithm}";
         };
+
+        finalPartitions = lib.mapAttrs addClosure cfg.partitions;
       };
 
     system.build.image =
@@ -247,26 +268,15 @@ in
           (f: f != null)
           (lib.mapAttrsToList (_n: v: v.repartConfig.Format or null) cfg.partitions);
 
-        makeClosure = paths: pkgs.closureInfo { rootPaths = paths; };
-
-        # Add the closure of the provided Nix store paths to cfg.partitions so
-        # that amend-repart-definitions.py can read it.
-        addClosure = _name: partitionConfig: partitionConfig // (
-          lib.optionalAttrs
-            (partitionConfig.storePaths or [ ] != [ ])
-            { closure = "${makeClosure partitionConfig.storePaths}/store-paths"; }
-        );
-
-        finalPartitions = lib.mapAttrs addClosure cfg.partitions;
 
         format = pkgs.formats.ini { };
 
         definitionsDirectory = utils.systemdUtils.lib.definitions
           "repart.d"
           format
-          (lib.mapAttrs (_n: v: { Partition = v.repartConfig; }) finalPartitions);
+          (lib.mapAttrs (_n: v: { Partition = v.repartConfig; }) cfg.finalPartitions);
 
-        partitionsJSON = pkgs.writeText "partitions.json" (builtins.toJSON finalPartitions);
+        partitionsJSON = pkgs.writeText "partitions.json" (builtins.toJSON cfg.finalPartitions);
 
         mkfsEnv = mkfsOptionsToEnv cfg.mkfsOptions;
       in