diff --git a/nixos/modules/image/images.nix b/nixos/modules/image/images.nix new file mode 100644 index 000000000000..96d02f64fb9b --- /dev/null +++ b/nixos/modules/image/images.nix @@ -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 + ); +} diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 91ecee0ef265..8551e1b3406c 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -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