about summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorWilliButz <willibutz@posteo.de>2024-03-07 17:38:30 +0100
committerWilliButz <willibutz@posteo.de>2024-03-07 18:27:11 +0100
commitf88148f05e28015dbd01d49bc8c22ff11b3db052 (patch)
tree47209ee2d08b933d383dbb5ab1296ae325d0b189 /nixos/modules
parentd7570b04936e9b0f5268e0d834dee40368ad3308 (diff)
downloadnixlib-f88148f05e28015dbd01d49bc8c22ff11b3db052.tar
nixlib-f88148f05e28015dbd01d49bc8c22ff11b3db052.tar.gz
nixlib-f88148f05e28015dbd01d49bc8c22ff11b3db052.tar.bz2
nixlib-f88148f05e28015dbd01d49bc8c22ff11b3db052.tar.lz
nixlib-f88148f05e28015dbd01d49bc8c22ff11b3db052.tar.xz
nixlib-f88148f05e28015dbd01d49bc8c22ff11b3db052.tar.zst
nixlib-f88148f05e28015dbd01d49bc8c22ff11b3db052.zip
nixos/repart-image: improve overridability, use structuredAttrs
Parameters passed to systemd-repart are now passed to the build script
via environment variable, which is defined as a list of strings in
combination with `__structuredAttrs = true`. This should make it easier
to customize the image build using `overrideAttrs`.

Both the script used to amend the repart definitions and the amended
definitions are now available via passthru.
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/image/repart-image.nix35
1 files changed, 25 insertions, 10 deletions
diff --git a/nixos/modules/image/repart-image.nix b/nixos/modules/image/repart-image.nix
index 7ac47ee32ff4..56f2775636a8 100644
--- a/nixos/modules/image/repart-image.nix
+++ b/nixos/modules/image/repart-image.nix
@@ -3,6 +3,7 @@
 
 { lib
 , runCommand
+, runCommandLocal
 , python3
 , black
 , ruff
@@ -50,6 +51,11 @@ let
     mypy --strict $out
   '';
 
+  amendedRepartDefinitions = runCommandLocal "amended-repart.d" {} ''
+    definitions=$(${amendRepartDefinitions} ${partitions} ${definitionsDirectory})
+    cp -r $definitions $out
+  '';
+
   fileSystemToolMapping = {
     "vfat" = [ dosfstools mtools ];
     "ext4" = [ e2fsprogs.bin ];
@@ -74,28 +80,37 @@ in
 
 runCommand imageFileBasename
 {
+  __structuredAttrs = true;
+
   nativeBuildInputs = [
     systemd
     fakeroot
     util-linux
     compressionPkg
   ] ++ fileSystemTools;
-} ''
-  amendedRepartDefinitions=$(${amendRepartDefinitions} ${partitions} ${definitionsDirectory})
 
+  systemdRepartFlags = [
+    "--dry-run=no"
+    "--empty=create"
+    "--size=auto"
+    "--seed=${seed}"
+    "--definitions=${amendedRepartDefinitions}"
+    "--split=${lib.boolToString split}"
+    "--json=pretty"
+  ] ++ lib.optionals (sectorSize != null) [
+    "--sector-size=${toString sectorSize}"
+  ];
+
+  passthru = {
+    inherit amendRepartDefinitions amendedRepartDefinitions;
+  };
+} ''
   mkdir -p $out
   cd $out
 
   echo "Building image with systemd-repart..."
   unshare --map-root-user fakeroot systemd-repart \
-    --dry-run=no \
-    --empty=create \
-    --size=auto \
-    --seed="${seed}" \
-    --definitions="$amendedRepartDefinitions" \
-    --split="${lib.boolToString split}" \
-    --json=pretty \
-    ${lib.optionalString (sectorSize != null) "--sector-size=${toString sectorSize}"} \
+    ''${systemdRepartFlags[@]} \
     ${imageFileBasename}.raw \
     | tee repart-output.json