about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2014-02-13 12:07:43 -0500
committerShea Levy <shea@shealevy.com>2014-02-13 12:10:50 -0500
commit220654e2052774ec7d3d834547119db105686715 (patch)
treea76ded963a34d1c72937ed259d757f1cf058b129 /lib
parent5857e5c4f8f0c8185ff616d2f5ec7e5530bc160f (diff)
downloadnixlib-220654e2052774ec7d3d834547119db105686715.tar
nixlib-220654e2052774ec7d3d834547119db105686715.tar.gz
nixlib-220654e2052774ec7d3d834547119db105686715.tar.bz2
nixlib-220654e2052774ec7d3d834547119db105686715.tar.lz
nixlib-220654e2052774ec7d3d834547119db105686715.tar.xz
nixlib-220654e2052774ec7d3d834547119db105686715.tar.zst
nixlib-220654e2052774ec7d3d834547119db105686715.zip
Revert "Add heterogeneousAttrsOf option type"
Moving recent types work to a separate branch for now

This reverts commit 3f70dabad320b115d586a59db8cca05c7f3b7c75.
Diffstat (limited to 'lib')
-rw-r--r--lib/types.nix30
1 files changed, 19 insertions, 11 deletions
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 ++ ["<name>"]);
     };
 
-    heterogeneousAttrsOf = elemTypeFn: mkOptionType {
-      name = "attribute set of values of many types, including ${(elemTypeFn "<name>").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 "<name>").getSubOptions (prefix ++ ["<name>"]);
-    };
-
     # 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.