2023-12-18 22:33:04 +01:00
|
|
|
# This is an expression meant to be called from `./repart.nix`, it is NOT a
|
|
|
|
# NixOS module that can be imported.
|
|
|
|
|
|
|
|
{ lib
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
, stdenvNoCC
|
2023-12-18 22:33:04 +01:00
|
|
|
, runCommand
|
|
|
|
, python3
|
|
|
|
, black
|
|
|
|
, ruff
|
|
|
|
, mypy
|
|
|
|
, systemd
|
|
|
|
, fakeroot
|
2023-12-30 00:15:17 +01:00
|
|
|
|
|
|
|
# filesystem tools
|
2023-12-18 22:33:04 +01:00
|
|
|
, dosfstools
|
|
|
|
, mtools
|
|
|
|
, e2fsprogs
|
|
|
|
, squashfsTools
|
|
|
|
, erofs-utils
|
|
|
|
, btrfs-progs
|
|
|
|
, xfsprogs
|
|
|
|
|
2023-12-30 00:15:17 +01:00
|
|
|
# compression tools
|
|
|
|
, zstd
|
|
|
|
, xz
|
|
|
|
|
2023-12-18 22:33:04 +01:00
|
|
|
# arguments
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
, name
|
|
|
|
, version
|
2023-12-30 00:15:17 +01:00
|
|
|
, imageFileBasename
|
|
|
|
, compression
|
2023-12-18 22:33:04 +01:00
|
|
|
, fileSystems
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
, partitionsJSON
|
2023-12-18 22:33:04 +01:00
|
|
|
, split
|
|
|
|
, seed
|
|
|
|
, definitionsDirectory
|
2024-01-27 07:26:46 +01:00
|
|
|
, sectorSize
|
2024-03-07 18:24:00 +01:00
|
|
|
, mkfsEnv ? {}
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
, createEmpty ? true
|
2023-12-18 22:33:04 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2024-04-04 17:38:07 +02:00
|
|
|
systemdArch = let
|
|
|
|
inherit (stdenvNoCC) hostPlatform;
|
|
|
|
in
|
|
|
|
if hostPlatform.isAarch32 then "arm"
|
|
|
|
else if hostPlatform.isAarch64 then "arm64"
|
|
|
|
else if hostPlatform.isx86_32 then "x86"
|
|
|
|
else if hostPlatform.isx86_64 then "x86-64"
|
|
|
|
else if hostPlatform.isMips32 then "mips-le"
|
|
|
|
else if hostPlatform.isMips64 then "mips64-le"
|
|
|
|
else if hostPlatform.isPower then "ppc"
|
|
|
|
else if hostPlatform.isPower64 then "ppc64"
|
|
|
|
else if hostPlatform.isRiscV32 then "riscv32"
|
|
|
|
else if hostPlatform.isRiscV64 then "riscv64"
|
|
|
|
else if hostPlatform.isS390 then "s390"
|
|
|
|
else if hostPlatform.isS390x then "s390x"
|
|
|
|
else if hostPlatform.isLoongArch64 then "loongarch64"
|
|
|
|
else if hostPlatform.isAlpha then "alpha"
|
|
|
|
else hostPlatform.parsed.cpu.name;
|
|
|
|
|
2023-12-18 22:33:04 +01:00
|
|
|
amendRepartDefinitions = runCommand "amend-repart-definitions.py"
|
|
|
|
{
|
|
|
|
# TODO: ruff does not splice properly in nativeBuildInputs
|
|
|
|
depsBuildBuild = [ ruff ];
|
|
|
|
nativeBuildInputs = [ python3 black mypy ];
|
|
|
|
} ''
|
|
|
|
install ${./amend-repart-definitions.py} $out
|
|
|
|
patchShebangs --build $out
|
|
|
|
|
|
|
|
black --check --diff $out
|
2024-07-10 11:37:59 +02:00
|
|
|
ruff check --line-length 88 $out
|
2023-12-18 22:33:04 +01:00
|
|
|
mypy --strict $out
|
|
|
|
'';
|
|
|
|
|
|
|
|
fileSystemToolMapping = {
|
|
|
|
"vfat" = [ dosfstools mtools ];
|
|
|
|
"ext4" = [ e2fsprogs.bin ];
|
|
|
|
"squashfs" = [ squashfsTools ];
|
|
|
|
"erofs" = [ erofs-utils ];
|
|
|
|
"btrfs" = [ btrfs-progs ];
|
|
|
|
"xfs" = [ xfsprogs ];
|
|
|
|
};
|
|
|
|
|
|
|
|
fileSystemTools = builtins.concatMap (f: fileSystemToolMapping."${f}") fileSystems;
|
2023-12-30 00:15:17 +01:00
|
|
|
|
|
|
|
compressionPkg = {
|
|
|
|
"zstd" = zstd;
|
|
|
|
"xz" = xz;
|
|
|
|
}."${compression.algorithm}";
|
|
|
|
|
|
|
|
compressionCommand = {
|
2024-06-14 06:11:40 +02:00
|
|
|
"zstd" = "zstd --no-progress --threads=$NIX_BUILD_CORES -${toString compression.level}";
|
|
|
|
"xz" = "xz --keep --verbose --threads=$NIX_BUILD_CORES -${toString compression.level}";
|
2023-12-30 00:15:17 +01:00
|
|
|
}."${compression.algorithm}";
|
2023-12-18 22:33:04 +01:00
|
|
|
in
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
stdenvNoCC.mkDerivation (finalAttrs:
|
|
|
|
(if (version != null)
|
|
|
|
then { pname = name; inherit version; }
|
|
|
|
else { inherit name; }
|
|
|
|
) // {
|
2024-03-07 17:38:30 +01:00
|
|
|
__structuredAttrs = true;
|
|
|
|
|
2023-12-18 22:33:04 +01:00
|
|
|
nativeBuildInputs = [
|
|
|
|
systemd
|
|
|
|
fakeroot
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
] ++ lib.optionals (compression.enable) [
|
2023-12-30 00:15:17 +01:00
|
|
|
compressionPkg
|
2023-12-18 22:33:04 +01:00
|
|
|
] ++ fileSystemTools;
|
|
|
|
|
2024-03-07 18:24:00 +01:00
|
|
|
env = mkfsEnv;
|
|
|
|
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
inherit partitionsJSON definitionsDirectory;
|
|
|
|
|
|
|
|
# relative path to the repart definitions that are read by systemd-repart
|
|
|
|
finalRepartDefinitions = "repart.d";
|
|
|
|
|
2024-03-07 17:38:30 +01:00
|
|
|
systemdRepartFlags = [
|
2024-04-04 17:38:07 +02:00
|
|
|
"--architecture=${systemdArch}"
|
2024-03-07 17:38:30 +01:00
|
|
|
"--dry-run=no"
|
|
|
|
"--size=auto"
|
|
|
|
"--seed=${seed}"
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
"--definitions=${finalAttrs.finalRepartDefinitions}"
|
2024-03-07 17:38:30 +01:00
|
|
|
"--split=${lib.boolToString split}"
|
|
|
|
"--json=pretty"
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
] ++ lib.optionals createEmpty [
|
|
|
|
"--empty=create"
|
2024-03-07 17:38:30 +01:00
|
|
|
] ++ lib.optionals (sectorSize != null) [
|
|
|
|
"--sector-size=${toString sectorSize}"
|
|
|
|
];
|
|
|
|
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
dontUnpack = true;
|
|
|
|
dontConfigure = true;
|
|
|
|
doCheck = false;
|
|
|
|
|
|
|
|
patchPhase = ''
|
|
|
|
runHook prePatch
|
|
|
|
|
|
|
|
amendedRepartDefinitionsDir=$(${amendRepartDefinitions} $partitionsJSON $definitionsDirectory)
|
|
|
|
ln -vs $amendedRepartDefinitionsDir $finalRepartDefinitions
|
2023-12-18 22:33:04 +01:00
|
|
|
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
runHook postPatch
|
|
|
|
'';
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
|
|
|
echo "Building image with systemd-repart..."
|
2024-05-26 18:49:54 +02:00
|
|
|
fakeroot systemd-repart \
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
''${systemdRepartFlags[@]} \
|
|
|
|
${imageFileBasename}.raw \
|
|
|
|
| tee repart-output.json
|
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
runHook preInstall
|
2023-12-30 00:15:17 +01:00
|
|
|
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
mkdir -p $out
|
|
|
|
''
|
2023-12-30 00:15:17 +01:00
|
|
|
# Compression is implemented in the same derivation as opposed to in a
|
|
|
|
# separate derivation to allow users to save disk space. Disk images are
|
|
|
|
# already very space intensive so we want to allow users to mitigate this.
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
+ lib.optionalString compression.enable
|
|
|
|
''
|
2023-12-30 00:15:17 +01:00
|
|
|
for f in ${imageFileBasename}*; do
|
|
|
|
echo "Compressing $f with ${compression.algorithm}..."
|
|
|
|
# Keep the original file when compressing and only delete it afterwards
|
|
|
|
${compressionCommand} $f && rm $f
|
|
|
|
done
|
nixos/repart-image: refactor to use mkDerivation
As a follow-up to https://github.com/NixOS/nixpkgs/pull/294096 this
should further improve the flexibility around building OS images with
systemd-repart:
* Previously the attribute set `compression` needed to be fully
populated, including `algorithm` and `level` because
`compression.enable` was evaluated by bash, after being interpolated
as strings into the `buildCommand`. Now it's sufficient to pass
`compression.enable = false` to the builder, e.g. in `overrideAttrs`,
to disable the compression.
* Using mkDerivation allows for much more customization than the
previously used `runCommand`, making use of phases and pre/post hooks.
This is especially helpful for building multiple images from the same
system configuration, e.g. to build an image `Y` based on a partially
built raw image `X`, by injecting a UKI that depends on `X` into a
defered ESP.
* Before this change it was non-trivial to conduct further manipulations
on the amended repart definitions. Now, the definitions that
systemd-repart uses to build the image can be easily manipulated in
`postPatch` or `preBuild`.
Aside from this, the build is now executed in the build directory, rather
than `$out`. This allows references to relative paths in the build
environment to be used, especially for `--definitions`, which previously
required an absolute path.
2024-03-19 17:04:47 +01:00
|
|
|
'' + ''
|
|
|
|
mv -v repart-output.json ${imageFileBasename}* $out
|
|
|
|
|
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit amendRepartDefinitions;
|
|
|
|
};
|
|
|
|
})
|