image/images: init (#359328)

This commit is contained in:
Jörg Thalheim 2024-11-26 21:32:18 +01:00 committed by GitHub
commit 43f6a895e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,48 @@
{
lib,
config,
pkgs,
...
}:
{
options.image = {
baseName = lib.mkOption {
type = lib.types.str;
default = "nixos-image-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}";
description = ''
Basename of the image filename without any extension (e.g. `image_1`).
'';
};
extension = lib.mkOption {
type = lib.types.str;
description = ''
Extension of the image filename (e.g. `raw`).
'';
};
# FIXME: this should be marked readOnly, when there are no
# mkRenamedOptionModuleWith calls with `image.fileName` as
# as a target left anymore (i.e. 24.11). We can't do it
# before, as some source options where writable before.
# Those should use image.baseName and image.extension instead.
fileName = lib.mkOption {
type = lib.types.str;
default = "${config.image.baseName}.${config.image.extension}";
description = ''
Filename of the image including all extensions (e.g `image_1.raw` or
`image_1.raw.zst`).
'';
};
filePath = lib.mkOption {
type = lib.types.str;
default = config.image.fileName;
description = ''
Path of the image, relative to `$out` in `system.build.image`.
While it defaults to `config.image.fileName`, it can be different for builders where
the image is in sub directory, such as `iso`, `sd-card` or `kexec` images.
'';
};
};
}

View File

@ -0,0 +1,56 @@
{
config,
lib,
pkgs,
extendModules,
...
}:
let
inherit (lib) types;
imageModules = { };
imageConfigs = lib.mapAttrs (
name: modules:
extendModules {
inherit modules;
}
) config.image.modules;
in
{
options = {
system.build = {
images = lib.mkOption {
type = types.lazyAttrsOf types.raw;
readOnly = true;
description = ''
Different target images generated for this NixOS configuration.
'';
};
};
image.modules = lib.mkOption {
type = types.attrsOf (types.listOf types.deferredModule);
description = ''
image-specific NixOS Modules used for `system.build.images`.
'';
};
};
config.image.modules = lib.mkIf (!config.system.build ? image) imageModules;
config.system.build.images = lib.mkIf (!config.system.build ? image) (
lib.mapAttrs (
name: nixos:
let
inherit (nixos) config;
inherit (config.image) filePath;
builder =
config.system.build.image
or (throw "Module for `system.build.images.${name}` misses required `system.build.image` option.");
in
lib.recursiveUpdate builder {
passthru = {
inherit config filePath;
};
}
) imageConfigs
);
}

View File

@ -125,6 +125,7 @@
./i18n/input-method/kime.nix
./i18n/input-method/nabi.nix
./i18n/input-method/uim.nix
./image/images.nix
./installer/tools/tools.nix
./misc/assertions.nix
./misc/crashdump.nix