diff --git a/lib/types.nix b/lib/types.nix index e9302688d5c3..77957a7763ba 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -124,17 +124,6 @@ rec { getSubOptions = prefix: elemType.getSubOptions (prefix ++ [""]); }; - heterogeneousAttrsOf = elemTypeFn: mkOptionType { - name = "attribute set of values of many types, including ${(elemTypeFn "").name}"; - check = x: isAttrs x && all (name: (elemTypeFn name).check (getAttr name x)) (attrNames x); - merge = loc: defs: - zipAttrsWith (name: (elemTypeFn name).merge (loc ++ [name])) - # Push down position info. - (map (def: listToAttrs (mapAttrsToList (n: def': - { name = n; value = { inherit (def) file; value = def'; }; }) def.value)) defs); - getSubOptions = prefix: (elemTypeFn "").getSubOptions (prefix ++ [""]); - }; - # List or attribute set of ... loaOf = elemType: let @@ -209,6 +198,25 @@ rec { submodule = submoduleWithExtraArgs {}; + nixosSubmodule = nixos: args: mkOptionType rec { + name = "submodule containing a NixOS config"; + check = x: isAttrs x || isFunction x; + merge = loc: defs: + let + coerce = def: if isFunction def then def else { config = def; }; + in (import (nixos + "/lib/eval-config.nix") (args // { + modules = (args.modules or []) ++ + map (def: { _file = def.file; imports = [(coerce def.value)]; }) defs; + + prefix = loc; + })).config; + getSubOptions = prefix: (import (nixos + "/lib/eval-config.nix") (args // { + modules = (args.modules or []); + + inherit prefix; + })).options; + }; + # Obsolete alternative to configOf. It takes its option # declarations from the ‘options’ attribute of containing option # declaration. diff --git a/nixos/modules/virtualisation/containers.nix b/nixos/modules/virtualisation/containers.nix index 99451e2bd3cd..531ee5596630 100644 --- a/nixos/modules/virtualisation/containers.nix +++ b/nixos/modules/virtualisation/containers.nix @@ -15,6 +15,7 @@ with pkgs.lib; }; systemd.containers = mkOption { + # !!! Should probably use nixosSubmodule here type = types.attrsOf (types.submodule ( { config, options, name, ... }: {