summary refs log tree commit diff
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2020-01-03 05:22:11 +0100
committerSilvan Mosberger <contact@infinisil.com>2020-01-08 23:54:45 +0100
commit6525da6321a7272faa0c2b1c15ffd3501888e9b9 (patch)
treef8288ac36e592287aa0e068f5153f8a3e9d53745
parent228a7b173e659a10c0f288f44e18e7ae050c78cb (diff)
downloadnixpkgs-6525da6321a7272faa0c2b1c15ffd3501888e9b9.tar
nixpkgs-6525da6321a7272faa0c2b1c15ffd3501888e9b9.tar.gz
nixpkgs-6525da6321a7272faa0c2b1c15ffd3501888e9b9.tar.bz2
nixpkgs-6525da6321a7272faa0c2b1c15ffd3501888e9b9.tar.lz
nixpkgs-6525da6321a7272faa0c2b1c15ffd3501888e9b9.tar.xz
nixpkgs-6525da6321a7272faa0c2b1c15ffd3501888e9b9.tar.zst
nixpkgs-6525da6321a7272faa0c2b1c15ffd3501888e9b9.zip
lib/types: Allow paths as submodule values
-rwxr-xr-xlib/tests/modules.sh3
-rw-r--r--lib/types.nix8
-rw-r--r--nixos/doc/manual/development/option-types.xml6
3 files changed, 9 insertions, 8 deletions
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index f69befd15c6..65b482ec194 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -174,8 +174,7 @@ checkConfigOutput "true" config.submodule.inner ./declare-submoduleWith-modules.
 checkConfigOutput "true" config.submodule.outer ./declare-submoduleWith-modules.nix
 
 ## Paths should be allowed as values and work as expected
-# Temporarily disabled until https://github.com/NixOS/nixpkgs/pull/76861
-#checkConfigOutput "true" config.submodule.enable ./declare-submoduleWith-path.nix
+checkConfigOutput "true" config.submodule.enable ./declare-submoduleWith-path.nix
 
 cat <<EOF
 ====== module tests ======
diff --git a/lib/types.nix b/lib/types.nix
index 4872a676657..7f2401c53d3 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -392,14 +392,16 @@ rec {
           else unify (if shorthandOnlyDefinesConfig then { config = value; } else value);
 
         allModules = defs: modules ++ imap1 (n: { value, file }:
-          # Annotate the value with the location of its definition for better error messages
-          coerce (lib.modules.unifyModuleSyntax file "${toString file}-${toString n}") value
+          if isAttrs value || isFunction value then
+            # Annotate the value with the location of its definition for better error messages
+            coerce (lib.modules.unifyModuleSyntax file "${toString file}-${toString n}") value
+          else value
         ) defs;
 
       in
       mkOptionType rec {
         name = "submodule";
-        check = x: isAttrs x || isFunction x;
+        check = x: isAttrs x || isFunction x || path.check x;
         merge = loc: defs:
           (evalModules {
             modules = allModules defs;
diff --git a/nixos/doc/manual/development/option-types.xml b/nixos/doc/manual/development/option-types.xml
index 1ec7e3efad7..173fdfcbbc8 100644
--- a/nixos/doc/manual/development/option-types.xml
+++ b/nixos/doc/manual/development/option-types.xml
@@ -257,9 +257,9 @@
     <listitem>
      <para>
       A set of sub options <replaceable>o</replaceable>.
-      <replaceable>o</replaceable> can be an attribute set or a function
-      returning an attribute set. Submodules are used in composed types to
-      create modular options. This is equivalent to
+      <replaceable>o</replaceable> can be an attribute set, a function
+      returning an attribute set, or a path to a file containing such a value. Submodules are used in
+      composed types to create modular options. This is equivalent to
       <literal>types.submoduleWith { modules = toList o; shorthandOnlyDefinesConfig = true; }</literal>.
       Submodules are detailed in
       <xref