2023-12-18 13:33:04 -08: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 13:33:04 -08:00
|
|
|
runCommand,
|
|
|
|
python3,
|
|
|
|
black,
|
|
|
|
ruff,
|
|
|
|
mypy,
|
|
|
|
systemd,
|
|
|
|
fakeroot,
|
2025-02-01 17:58:01 +01:00
|
|
|
util-linux,
|
2023-12-30 00:15:17 +01:00
|
|
|
|
|
|
|
# filesystem tools
|
2023-12-18 13:33:04 -08:00
|
|
|
dosfstools,
|
|
|
|
mtools,
|
|
|
|
e2fsprogs,
|
|
|
|
squashfsTools,
|
|
|
|
erofs-utils,
|
|
|
|
btrfs-progs,
|
|
|
|
xfsprogs,
|
|
|
|
|
2023-12-30 00:15:17 +01:00
|
|
|
# compression tools
|
|
|
|
zstd,
|
|
|
|
xz,
|
2025-02-26 08:47:06 +01:00
|
|
|
zeekstd,
|
2023-12-30 00:15:17 +01:00
|
|
|
|
2023-12-18 13:33:04 -08: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 13:33:04 -08:00
|
|
|
fileSystems,
|
2024-09-30 16:31:56 +02:00
|
|
|
finalPartitions,
|
2023-12-18 13:33:04 -08:00
|
|
|
split,
|
|
|
|
seed,
|
|
|
|
definitionsDirectory,
|
2024-01-26 22:26:46 -08: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 13:33:04 -08: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;
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2023-12-18 13:33:04 -08: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
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2023-12-18 13:33:04 -08:00
|
|
|
black --check --diff $out
|
2024-07-10 11:37:59 +02:00
|
|
|
ruff check --line-length 88 $out
|
2023-12-18 13:33:04 -08:00
|
|
|
mypy --strict $out
|
|
|
|
'';
|
|
|
|
|
|
|
|
fileSystemToolMapping = {
|
|
|
|
"vfat" = [
|
|
|
|
dosfstools
|
|
|
|
mtools
|
|
|
|
];
|
|
|
|
"ext4" = [ e2fsprogs.bin ];
|
|
|
|
"squashfs" = [ squashfsTools ];
|
|
|
|
"erofs" = [ erofs-utils ];
|
|
|
|
"btrfs" = [ btrfs-progs ];
|
|
|
|
"xfs" = [ xfsprogs ];
|
2025-02-01 17:15:56 +01:00
|
|
|
"swap" = [ util-linux ];
|
2023-12-18 13:33:04 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
fileSystemTools = builtins.concatMap (f: fileSystemToolMapping."${f}") fileSystems;
|
2023-12-30 00:15:17 +01:00
|
|
|
|
|
|
|
compressionPkg =
|
|
|
|
{
|
|
|
|
"zstd" = zstd;
|
|
|
|
"xz" = xz;
|
2025-02-26 08:47:06 +01:00
|
|
|
"zstd-seekable" = zeekstd;
|
2023-12-30 00:15:17 +01:00
|
|
|
}
|
|
|
|
."${compression.algorithm}";
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2023-12-30 00:15:17 +01:00
|
|
|
compressionCommand =
|
|
|
|
{
|
2024-06-13 21:11:40 -07:00
|
|
|
"zstd" = "zstd --no-progress --threads=$NIX_BUILD_CORES -${toString compression.level}";
|
|
|
|
"xz" = "xz --keep --verbose --threads=$NIX_BUILD_CORES -${toString compression.level}";
|
2025-02-26 08:47:06 +01:00
|
|
|
"zstd-seekable" =
|
2025-05-29 19:27:22 +02:00
|
|
|
"zeekstd --no-progress --frame-size 2M --compression-level ${toString compression.level}";
|
2023-12-30 00:15:17 +01:00
|
|
|
}
|
|
|
|
."${compression.algorithm}";
|
2023-12-18 13:33:04 -08: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;
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2024-10-10 11:48:36 +02:00
|
|
|
# the image will be self-contained so we can drop references
|
|
|
|
# to the closure that was used to build it
|
|
|
|
unsafeDiscardReferences.out = true;
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2023-12-18 13:33:04 -08:00
|
|
|
nativeBuildInputs =
|
|
|
|
[
|
|
|
|
systemd
|
2025-02-01 17:58:01 +01:00
|
|
|
util-linux
|
2023-12-18 13:33:04 -08:00
|
|
|
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 13:33:04 -08:00
|
|
|
]
|
|
|
|
++ fileSystemTools;
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2024-03-07 18:24:00 +01:00
|
|
|
env = mkfsEnv;
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2024-09-30 16:31:56 +02:00
|
|
|
inherit finalPartitions definitionsDirectory;
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2024-09-30 16:31:56 +02:00
|
|
|
partitionsJSON = builtins.toJSON finalAttrs.finalPartitions;
|
2025-04-01 20:10:43 +02: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
|
|
|
# relative path to the repart definitions that are read by systemd-repart
|
|
|
|
finalRepartDefinitions = "repart.d";
|
2025-04-01 20:10:43 +02:00
|
|
|
|
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}"
|
|
|
|
];
|
2025-04-01 20:10:43 +02: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
|
|
|
dontUnpack = true;
|
|
|
|
dontConfigure = true;
|
|
|
|
doCheck = false;
|
2025-04-01 20:10:43 +02: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
|
|
|
patchPhase = ''
|
|
|
|
runHook prePatch
|
2025-04-01 20:10:43 +02:00
|
|
|
|
2024-09-30 16:31:56 +02:00
|
|
|
amendedRepartDefinitionsDir=$(${amendRepartDefinitions} <(echo "$partitionsJSON") $definitionsDirectory)
|
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
|
|
|
ln -vs $amendedRepartDefinitionsDir $finalRepartDefinitions
|
2025-04-01 20:10:43 +02: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
|
|
|
|
'';
|
2025-04-01 20:10:43 +02: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
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
2025-04-01 20:10:43 +02: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
|
|
|
echo "Building image with systemd-repart..."
|
2025-02-01 17:58:01 +01:00
|
|
|
unshare --map-root-user 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
|
2025-04-01 20:10:43 +02: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 postBuild
|
|
|
|
'';
|
2025-04-01 20:10:43 +02: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
|
|
|
installPhase =
|
|
|
|
''
|
|
|
|
runHook preInstall
|
2025-04-01 20:10:43 +02: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
|
2025-04-01 20:10:43 +02: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 postInstall
|
|
|
|
'';
|
2025-04-01 20:10:43 +02: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
|
|
|
passthru = {
|
|
|
|
inherit amendRepartDefinitions;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|