mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-12 20:55:31 +03:00
Add nixosSubmodule option type
Since NixOS modules expect special arguments, use a hack to provide them
This commit is contained in:
parent
2deb26bd4a
commit
ca1c5cfa8f
2 changed files with 21 additions and 1 deletions
|
@ -195,6 +195,25 @@ rec {
|
||||||
args = { name = ""; }; }).options;
|
args = { name = ""; }; }).options;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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
|
# Obsolete alternative to configOf. It takes its option
|
||||||
# declarations from the ‘options’ attribute of containing option
|
# declarations from the ‘options’ attribute of containing option
|
||||||
# declaration.
|
# declaration.
|
||||||
|
|
|
@ -15,6 +15,7 @@ with pkgs.lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.containers = mkOption {
|
systemd.containers = mkOption {
|
||||||
|
# !!! Should probably use nixosSubmodule here
|
||||||
type = types.attrsOf (types.submodule (
|
type = types.attrsOf (types.submodule (
|
||||||
{ config, options, name, ... }:
|
{ config, options, name, ... }:
|
||||||
{
|
{
|
||||||
|
@ -134,4 +135,4 @@ with pkgs.lib;
|
||||||
}) config.systemd.containers;
|
}) config.systemd.containers;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue