nixos/repart-image: add options to specify mkfs parameters

This new option makes it easier to specify extra mkfs parameters for the
systemd-repart builder.

See https://github.com/systemd/systemd/blob/v255/docs/ENVIRONMENT.md?plain=1#L575-L577
This commit is contained in:
WilliButz 2024-03-07 18:24:00 +01:00
parent f88148f05e
commit 82ef47d3b7
No known key found for this signature in database
GPG key ID: AB05DF703EB9DC70
2 changed files with 34 additions and 1 deletions

View file

@ -34,6 +34,7 @@
, seed , seed
, definitionsDirectory , definitionsDirectory
, sectorSize , sectorSize
, mkfsEnv ? {}
}: }:
let let
@ -89,6 +90,8 @@ runCommand imageFileBasename
compressionPkg compressionPkg
] ++ fileSystemTools; ] ++ fileSystemTools;
env = mkfsEnv;
systemdRepartFlags = [ systemdRepartFlags = [
"--dry-run=no" "--dry-run=no"
"--empty=create" "--empty=create"

View file

@ -60,6 +60,11 @@ let
}; };
}; };
}; };
mkfsOptionsToEnv = opts: lib.mapAttrs' (fsType: options: {
name = "SYSTEMD_REPART_MKFS_OPTIONS_${lib.toUpper fsType}";
value = builtins.concatStringsSep " " options;
}) opts;
in in
{ {
options.image.repart = { options.image.repart = {
@ -183,6 +188,29 @@ in
''; '';
}; };
mkfsOptions = lib.mkOption {
type = with lib.types; attrsOf (listOf str);
default = {};
example = lib.literalExpression ''
{
vfat = [ "-S 512" "-c" ];
}
'';
description = lib.mdDoc ''
Specify extra options for created file systems. The specified options
are converted to individual environment variables of the format
`SYSTEMD_REPART_MKFS_OPTIONS_<FSTYPE>`.
See [upstream systemd documentation](https://github.com/systemd/systemd/blob/v255/docs/ENVIRONMENT.md?plain=1#L575-L577)
for information about the usage of these environment variables.
The example would produce the following environment variable:
```
SYSTEMD_REPART_MKFS_OPTIONS_VFAT="-S 512 -c"
```
'';
};
}; };
config = { config = {
@ -239,11 +267,13 @@ in
(lib.mapAttrs (_n: v: { Partition = v.repartConfig; }) finalPartitions); (lib.mapAttrs (_n: v: { Partition = v.repartConfig; }) finalPartitions);
partitions = pkgs.writeText "partitions.json" (builtins.toJSON finalPartitions); partitions = pkgs.writeText "partitions.json" (builtins.toJSON finalPartitions);
mkfsEnv = mkfsOptionsToEnv cfg.mkfsOptions;
in in
pkgs.callPackage ./repart-image.nix { pkgs.callPackage ./repart-image.nix {
systemd = cfg.package; systemd = cfg.package;
inherit (cfg) imageFileBasename compression split seed sectorSize; inherit (cfg) imageFileBasename compression split seed sectorSize;
inherit fileSystems definitionsDirectory partitions; inherit fileSystems definitionsDirectory partitions mkfsEnv;
}; };
meta.maintainers = with lib.maintainers; [ nikstur ]; meta.maintainers = with lib.maintainers; [ nikstur ];