mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-11 20:25:32 +03:00
image/images: init
A new NixOS module that adds two new options to `system.build`: - imageModules: An attrset mapping image variant names to a list of nixos modules to use when building such images. - images: An attrset mapping image variant names to a nixos instance based on the current config plus variant-specific modules (see `system.build.imageModules` above.
This commit is contained in:
parent
148ba06717
commit
08b9155e20
2 changed files with 57 additions and 0 deletions
56
nixos/modules/image/images.nix
Normal file
56
nixos/modules/image/images.nix
Normal 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
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue