From ca1c5cfa8fff055c74786dbe0d2ca889ae462365 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Tue, 11 Feb 2014 14:21:34 -0500 Subject: [PATCH] Add nixosSubmodule option type Since NixOS modules expect special arguments, use a hack to provide them --- lib/types.nix | 19 +++++++++++++++++++ nixos/modules/virtualisation/containers.nix | 3 ++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/types.nix b/lib/types.nix index afc8f80eb0ea..ac84ef296110 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -195,6 +195,25 @@ rec { 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 # declarations from the ‘options’ attribute of containing option # declaration. diff --git a/nixos/modules/virtualisation/containers.nix b/nixos/modules/virtualisation/containers.nix index bcbfaacd703f..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, ... }: { @@ -134,4 +135,4 @@ with pkgs.lib; }) config.systemd.containers; }; -} \ No newline at end of file +}