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.
This commit is contained in:
WilliButz 2024-03-07 17:38:30 +01:00
parent d7570b0493
commit f88148f05e
No known key found for this signature in database
GPG key ID: AB05DF703EB9DC70

View file

@ -3,6 +3,7 @@
{ lib { lib
, runCommand , runCommand
, runCommandLocal
, python3 , python3
, black , black
, ruff , ruff
@ -50,6 +51,11 @@ let
mypy --strict $out mypy --strict $out
''; '';
amendedRepartDefinitions = runCommandLocal "amended-repart.d" {} ''
definitions=$(${amendRepartDefinitions} ${partitions} ${definitionsDirectory})
cp -r $definitions $out
'';
fileSystemToolMapping = { fileSystemToolMapping = {
"vfat" = [ dosfstools mtools ]; "vfat" = [ dosfstools mtools ];
"ext4" = [ e2fsprogs.bin ]; "ext4" = [ e2fsprogs.bin ];
@ -74,28 +80,37 @@ in
runCommand imageFileBasename runCommand imageFileBasename
{ {
__structuredAttrs = true;
nativeBuildInputs = [ nativeBuildInputs = [
systemd systemd
fakeroot fakeroot
util-linux util-linux
compressionPkg compressionPkg
] ++ fileSystemTools; ] ++ 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 mkdir -p $out
cd $out cd $out
echo "Building image with systemd-repart..." echo "Building image with systemd-repart..."
unshare --map-root-user fakeroot systemd-repart \ unshare --map-root-user fakeroot systemd-repart \
--dry-run=no \ ''${systemdRepartFlags[@]} \
--empty=create \
--size=auto \
--seed="${seed}" \
--definitions="$amendedRepartDefinitions" \
--split="${lib.boolToString split}" \
--json=pretty \
${lib.optionalString (sectorSize != null) "--sector-size=${toString sectorSize}"} \
${imageFileBasename}.raw \ ${imageFileBasename}.raw \
| tee repart-output.json | tee repart-output.json