From eec83d41e3e7d9ad5bc1086198d972d55bab1203 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Tue, 31 Dec 2019 04:25:35 +0100 Subject: [PATCH] lib/types: Allow paths as submodule values --- lib/types.nix | 8 +++++--- nixos/doc/manual/development/option-types.xml | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index de3c4f0d603032..847a4e902cab60 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -376,14 +376,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 1ec7e3efad714b..173fdfcbbc8334 100644 --- a/nixos/doc/manual/development/option-types.xml +++ b/nixos/doc/manual/development/option-types.xml @@ -257,9 +257,9 @@ A set of sub options o. - o 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 + o 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 types.submoduleWith { modules = toList o; shorthandOnlyDefinesConfig = true; }. Submodules are detailed in