diff options
author | WilliButz <willibutz@posteo.de> | 2024-03-07 17:38:30 +0100 |
---|---|---|
committer | WilliButz <willibutz@posteo.de> | 2024-03-07 18:27:11 +0100 |
commit | f88148f05e28015dbd01d49bc8c22ff11b3db052 (patch) | |
tree | 47209ee2d08b933d383dbb5ab1296ae325d0b189 /nixos/modules/image | |
parent | d7570b04936e9b0f5268e0d834dee40368ad3308 (diff) |
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/image')
-rw-r--r-- | nixos/modules/image/repart-image.nix | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/nixos/modules/image/repart-image.nix b/nixos/modules/image/repart-image.nix index 7ac47ee32ff43..56f2775636a86 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 |