diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/default.nix | 4 | ||||
-rw-r--r-- | lib/lists.nix | 7 | ||||
-rw-r--r-- | lib/meta.nix | 27 | ||||
-rw-r--r-- | lib/modules.nix | 113 | ||||
-rw-r--r-- | lib/options.nix | 10 | ||||
-rw-r--r-- | lib/strings.nix | 2 | ||||
-rw-r--r-- | lib/systems/examples.nix | 6 | ||||
-rwxr-xr-x | lib/tests/modules.sh | 254 | ||||
-rw-r--r-- | lib/tests/modules/declare-submodule-via-evalModules.nix | 28 | ||||
-rw-r--r-- | lib/tests/modules/declare-variants.nix | 9 | ||||
-rw-r--r-- | lib/tests/modules/define-variant.nix | 22 | ||||
-rw-r--r-- | lib/tests/release.nix | 4 | ||||
-rwxr-xr-x | lib/tests/sources.sh | 20 | ||||
-rw-r--r-- | lib/trivial.nix | 2 | ||||
-rw-r--r-- | lib/types.nix | 56 |
15 files changed, 382 insertions, 182 deletions
diff --git a/lib/default.nix b/lib/default.nix index 5a85c542117..626a751cb10 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -105,7 +105,7 @@ let makeScope makeScopeWithSplicing; inherit (self.meta) addMetaAttrs dontDistribute setName updateName appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio - hiPrioSet; + hiPrioSet getLicenseFromSpdxId; inherit (self.sources) pathType pathIsDirectory cleanSourceFilter cleanSource sourceByRegex sourceFilesBySuffices commitIdFromGitRepo cleanSourceWith pathHasContext @@ -119,7 +119,7 @@ let mkFixStrictness mkOrder mkBefore mkAfter mkAliasDefinitions mkAliasAndWrapDefinitions fixMergeModules mkRemovedOptionModule mkRenamedOptionModule mkMergedOptionModule mkChangedOptionModule - mkAliasOptionModule doRename; + mkAliasOptionModule mkDerivedConfig doRename; inherit (self.options) isOption mkEnableOption mkSinkUndeclaredOptions mergeDefaultOption mergeOneOption mergeEqualOption getValues getFiles optionAttrSetToDocList optionAttrSetToDocList' diff --git a/lib/lists.nix b/lib/lists.nix index e469f3ef265..1dbff7668d7 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -642,7 +642,7 @@ rec { unique [ 3 2 3 4 ] => [ 3 2 4 ] */ - unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) []; + unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) []; /* Intersects list 'e' and another list. O(nm) complexity. @@ -663,9 +663,6 @@ rec { /* Test if two lists have no common element. It should be slightly more efficient than (intersectLists a b == []) */ - mutuallyExclusive = a: b: - (builtins.length a) == 0 || - (!(builtins.elem (builtins.head a) b) && - mutuallyExclusive (builtins.tail a) b); + mutuallyExclusive = a: b: length a == 0 || !(any (x: elem x a) b); } diff --git a/lib/meta.nix b/lib/meta.nix index bc04394dcf0..bc3387646f2 100644 --- a/lib/meta.nix +++ b/lib/meta.nix @@ -99,4 +99,31 @@ rec { availableOn = platform: pkg: lib.any (platformMatch platform) pkg.meta.platforms && lib.all (elem: !platformMatch platform elem) (pkg.meta.badPlatforms or []); + + /* Get the corresponding attribute in lib.licenses + from the SPDX ID. + For SPDX IDs, see + https://spdx.org/licenses + + Type: + getLicenseFromSpdxId :: str -> AttrSet + + Example: + lib.getLicenseFromSpdxId "MIT" == lib.licenses.mit + => true + lib.getLicenseFromSpdxId "mIt" == lib.licenses.mit + => true + lib.getLicenseFromSpdxId "MY LICENSE" + => trace: warning: getLicenseFromSpdxId: No license matches the given SPDX ID: MY LICENSE + => { shortName = "MY LICENSE"; } + */ + getLicenseFromSpdxId = + let + spdxLicenses = lib.mapAttrs (id: ls: assert lib.length ls == 1; builtins.head ls) + (lib.groupBy (l: lib.toLower l.spdxId) (lib.filter (l: l ? spdxId) (lib.attrValues lib.licenses))); + in licstr: + spdxLicenses.${ lib.toLower licstr } or ( + lib.warn "getLicenseFromSpdxId: No license matches the given SPDX ID: ${licstr}" + { shortName = licstr; } + ); } diff --git a/lib/modules.nix b/lib/modules.nix index e3abf846625..e3bb27aa946 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -50,15 +50,43 @@ in rec { - /* Evaluate a set of modules. The result is a set of two - attributes: ‘options’: the nested set of all option declarations, - and ‘config’: the nested set of all option values. + /* + Evaluate a set of modules. The result is a set with the attributes: + + ‘options’: The nested set of all option declarations, + + ‘config’: The nested set of all option values. + + ‘type’: A module system type representing the module set as a submodule, + to be extended by configuration from the containing module set. + + This is also available as the module argument ‘moduleType’. + + ‘extendModules’: A function similar to ‘evalModules’ but building on top + of the module set. Its arguments, ‘modules’ and ‘specialArgs’ are + added to the existing values. + + Using ‘extendModules’ a few times has no performance impact as long + as you only reference the final ‘options’ and ‘config’. + If you do reference multiple ‘config’ (or ‘options’) from before and + after ‘extendModules’, performance is the same as with multiple + ‘evalModules’ invocations, because the new modules' ability to + override existing configuration fundamentally requires a new + fixpoint to be constructed. + + This is also available as a module argument. + + ‘_module’: A portion of the configuration tree which is elided from + ‘config’. It contains some values that are mostly internal to the + module system implementation. + !!! Please think twice before adding to this argument list! The more that is specified here instead of in the modules themselves the harder it is to transparently move a set of modules to be a submodule of another config (as the proper arguments need to be replicated at each call to evalModules) and the less declarative the module set is. */ - evalModules = { modules + evalModules = evalModulesArgs@ + { modules , prefix ? [] , # This should only be used for special arguments that need to be evaluated # when resolving module structure (like in imports). For everything else, @@ -71,9 +99,31 @@ rec { check ? true }: let + withWarnings = x: + lib.warnIf (evalModulesArgs?args) "The args argument to evalModules is deprecated. Please set config._module.args instead." + lib.warnIf (evalModulesArgs?check) "The check argument to evalModules is deprecated. Please set config._module.check instead." + x; + + legacyModules = + optional (evalModulesArgs?args) { + config = { + _module.args = args; + }; + } + ++ optional (evalModulesArgs?check) { + config = { + _module.check = mkDefault check; + }; + }; + regularModules = modules ++ legacyModules; + # This internal module declare internal options under the `_module' # attribute. These options are fragile, as they are used by the # module system to change the interpretation of modules. + # + # When extended with extendModules or moduleType, a fresh instance of + # this module is used, to avoid conflicts and allow chaining of + # extendModules. internalModule = rec { _file = ./modules.nix; @@ -95,7 +145,7 @@ rec { _module.check = mkOption { type = types.bool; internal = true; - default = check; + default = true; description = "Whether to check whether all option definitions have matching declarations."; }; @@ -118,14 +168,17 @@ rec { }; config = { - _module.args = args; + _module.args = { + inherit extendModules; + moduleType = type; + }; }; }; merged = let collected = collectModules (specialArgs.modulesPath or "") - (modules ++ [ internalModule ]) + (regularModules ++ [ internalModule ]) ({ inherit lib options config specialArgs; } // specialArgs); in mergeModules prefix (reverseList collected); @@ -181,10 +234,28 @@ rec { else throw baseMsg else null; - result = builtins.seq checkUnmatched { - inherit options; - config = removeAttrs config [ "_module" ]; - inherit (config) _module; + checked = builtins.seq checkUnmatched; + + extendModules = extendArgs@{ + modules ? [], + specialArgs ? {}, + prefix ? [], + }: + evalModules (evalModulesArgs // { + modules = regularModules ++ modules; + specialArgs = evalModulesArgs.specialArgs or {} // specialArgs; + prefix = extendArgs.prefix or evalModulesArgs.prefix; + }); + + type = lib.types.submoduleWith { + inherit modules specialArgs; + }; + + result = withWarnings { + options = checked options; + config = checked (removeAttrs config [ "_module" ]); + _module = checked (config._module); + inherit extendModules type; }; in result; @@ -917,6 +988,26 @@ rec { use = id; }; + /* mkDerivedConfig : Option a -> (a -> Definition b) -> Definition b + + Create config definitions with the same priority as the definition of another option. + This should be used for option definitions where one option sets the value of another as a convenience. + For instance a config file could be set with a `text` or `source` option, where text translates to a `source` + value using `mkDerivedConfig options.text (pkgs.writeText "filename.conf")`. + + It takes care of setting the right priority using `mkOverride`. + */ + # TODO: make the module system error message include information about `opt` in + # error messages about conflicts. E.g. introduce a variation of `mkOverride` which + # adds extra location context to the definition object. This will allow context to be added + # to all messages that report option locations "this value was derived from <full option name> + # which was defined in <locations>". It can provide a trace of options that contributed + # to definitions. + mkDerivedConfig = opt: f: + mkOverride + (opt.highestPrio or defaultPriority) + (f opt.value); + doRename = { from, to, visible, warn, use, withPriority ? true }: { config, options, ... }: let diff --git a/lib/options.nix b/lib/options.nix index b3164181312..5d52f065af0 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -74,7 +74,7 @@ rec { apply ? null, # Whether the option is for NixOS developers only. internal ? null, - # Whether the option shows up in the manual. + # Whether the option shows up in the manual. Default: true. Use false to hide the option and any sub-options from submodules. Use "shallow" to hide only sub-options. visible ? null, # Whether the option can be set only once readOnly ? null, @@ -180,7 +180,10 @@ rec { description = opt.description or (lib.warn "Option `${name}' has no description." "This option has no description."); declarations = filter (x: x != unknownModule) opt.declarations; internal = opt.internal or false; - visible = opt.visible or true; + visible = + if (opt?visible && opt.visible == "shallow") + then true + else opt.visible or true; readOnly = opt.readOnly or false; type = opt.type.description or null; } @@ -192,8 +195,9 @@ rec { subOptions = let ss = opt.type.getSubOptions opt.loc; in if ss != {} then optionAttrSetToDocList' opt.loc ss else []; + subOptionsVisible = docOption.visible && opt.visible or null != "shallow"; in - [ docOption ] ++ optionals docOption.visible subOptions) (collect isOption options); + [ docOption ] ++ optionals subOptionsVisible subOptions) (collect isOption options); /* This function recursively removes all derivation attributes from diff --git a/lib/strings.nix b/lib/strings.nix index de135d1c274..b2fd495e4c8 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -369,7 +369,7 @@ rec { Example: escapeXML ''"test" 'test' < & >'' - => "\\[\\^a-z]\\*" + => ""test" 'test' < & >" */ escapeXML = builtins.replaceStrings ["\"" "'" "<" ">" "&"] diff --git a/lib/systems/examples.nix b/lib/systems/examples.nix index 8dfa22ac787..f2469f9bf7f 100644 --- a/lib/systems/examples.nix +++ b/lib/systems/examples.nix @@ -258,6 +258,12 @@ rec { platform = {}; }; + x86_64-darwin = { + config = "x86_64-apple-darwin"; + xcodePlatform = "MacOSX"; + platform = {}; + }; + # # Windows # diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh index b51db91f6b0..590937da5b8 100755 --- a/lib/tests/modules.sh +++ b/lib/tests/modules.sh @@ -1,8 +1,11 @@ -#!/bin/sh +#!/usr/bin/env bash # # This script is used to test that the module system is working as expected. # By default it test the version of nixpkgs which is defined in the NIX_PATH. +set -o errexit -o noclobber -o nounset -o pipefail +shopt -s failglob inherit_errexit + # https://stackoverflow.com/a/246128/6605742 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" @@ -13,101 +16,96 @@ fail=0 evalConfig() { local attr=$1 - shift; - local script="import ./default.nix { modules = [ $@ ];}" + shift + local script="import ./default.nix { modules = [ $* ];}" nix-instantiate --timeout 1 -E "$script" -A "$attr" --eval-only --show-trace --read-write-mode } reportFailure() { local attr=$1 - shift; - local script="import ./default.nix { modules = [ $@ ];}" + shift + local script="import ./default.nix { modules = [ $* ];}" echo 2>&1 "$ nix-instantiate -E '$script' -A '$attr' --eval-only" - evalConfig "$attr" "$@" - fail=$((fail + 1)) + evalConfig "$attr" "$@" || true + ((++fail)) } checkConfigOutput() { local outputContains=$1 - shift; + shift if evalConfig "$@" 2>/dev/null | grep --silent "$outputContains" ; then - pass=$((pass + 1)) - return 0; + ((++pass)) else echo 2>&1 "error: Expected result matching '$outputContains', while evaluating" reportFailure "$@" - return 1 fi } checkConfigError() { local errorContains=$1 local err="" - shift; - if err==$(evalConfig "$@" 2>&1 >/dev/null); then + shift + if err="$(evalConfig "$@" 2>&1 >/dev/null)"; then echo 2>&1 "error: Expected error code, got exit code 0, while evaluating" reportFailure "$@" - return 1 else if echo "$err" | grep -zP --silent "$errorContains" ; then - pass=$((pass + 1)) - return 0; + ((++pass)) else echo 2>&1 "error: Expected error matching '$errorContains', while evaluating" reportFailure "$@" - return 1 fi fi } # Check boolean option. -checkConfigOutput "false" config.enable ./declare-enable.nix -checkConfigError 'The option .* does not exist. Definition values:\n- In .*: true' config.enable ./define-enable.nix +checkConfigOutput '^false$' config.enable ./declare-enable.nix +checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./define-enable.nix # Check integer types. # unsigned -checkConfigOutput "42" config.value ./declare-int-unsigned-value.nix ./define-value-int-positive.nix -checkConfigError 'A definition for option .* is not of type.*unsigned integer.*. Definition values:\n- In .*: -23' config.value ./declare-int-unsigned-value.nix ./define-value-int-negative.nix +checkConfigOutput '^42$' config.value ./declare-int-unsigned-value.nix ./define-value-int-positive.nix +checkConfigError 'A definition for option .* is not of type.*unsigned integer.*. Definition values:\n\s*- In .*: -23' config.value ./declare-int-unsigned-value.nix ./define-value-int-negative.nix # positive -checkConfigError 'A definition for option .* is not of type.*positive integer.*. Definition values:\n- In .*: 0' config.value ./declare-int-positive-value.nix ./define-value-int-zero.nix +checkConfigError 'A definition for option .* is not of type.*positive integer.*. Definition values:\n\s*- In .*: 0' config.value ./declare-int-positive-value.nix ./define-value-int-zero.nix # between -checkConfigOutput "42" config.value ./declare-int-between-value.nix ./define-value-int-positive.nix -checkConfigError 'A definition for option .* is not of type.*between.*-21 and 43.*inclusive.*. Definition values:\n- In .*: -23' config.value ./declare-int-between-value.nix ./define-value-int-negative.nix +checkConfigOutput '^42$' config.value ./declare-int-between-value.nix ./define-value-int-positive.nix +checkConfigError 'A definition for option .* is not of type.*between.*-21 and 43.*inclusive.*. Definition values:\n\s*- In .*: -23' config.value ./declare-int-between-value.nix ./define-value-int-negative.nix # Check either types # types.either -checkConfigOutput "42" config.value ./declare-either.nix ./define-value-int-positive.nix -checkConfigOutput "\"24\"" config.value ./declare-either.nix ./define-value-string.nix +checkConfigOutput '^42$' config.value ./declare-either.nix ./define-value-int-positive.nix +checkConfigOutput '^"24"$' config.value ./declare-either.nix ./define-value-string.nix # types.oneOf -checkConfigOutput "42" config.value ./declare-oneOf.nix ./define-value-int-positive.nix -checkConfigOutput "[ ]" config.value ./declare-oneOf.nix ./define-value-list.nix -checkConfigOutput "\"24\"" config.value ./declare-oneOf.nix ./define-value-string.nix +checkConfigOutput '^42$' config.value ./declare-oneOf.nix ./define-value-int-positive.nix +checkConfigOutput '^\[ \]$' config.value ./declare-oneOf.nix ./define-value-list.nix +checkConfigOutput '^"24"$' config.value ./declare-oneOf.nix ./define-value-string.nix # Check mkForce without submodules. set -- config.enable ./declare-enable.nix ./define-enable.nix -checkConfigOutput "true" "$@" -checkConfigOutput "false" "$@" ./define-force-enable.nix -checkConfigOutput "false" "$@" ./define-enable-force.nix +checkConfigOutput '^true$' "$@" +checkConfigOutput '^false$' "$@" ./define-force-enable.nix +checkConfigOutput '^false$' "$@" ./define-enable-force.nix # Check mkForce with option and submodules. checkConfigError 'attribute .*foo.* .* not found' config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix -checkConfigOutput 'false' config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix +checkConfigOutput '^false$' config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix set -- config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo-enable.nix -checkConfigOutput 'true' "$@" -checkConfigOutput 'false' "$@" ./define-force-attrsOfSub-foo-enable.nix -checkConfigOutput 'false' "$@" ./define-attrsOfSub-force-foo-enable.nix -checkConfigOutput 'false' "$@" ./define-attrsOfSub-foo-force-enable.nix -checkConfigOutput 'false' "$@" ./define-attrsOfSub-foo-enable-force.nix +checkConfigOutput '^true$' "$@" +checkConfigOutput '^false$' "$@" ./define-force-attrsOfSub-foo-enable.nix +checkConfigOutput '^false$' "$@" ./define-attrsOfSub-force-foo-enable.nix +checkConfigOutput '^false$' "$@" ./define-attrsOfSub-foo-force-enable.nix +checkConfigOutput '^false$' "$@" ./define-attrsOfSub-foo-enable-force.nix # Check overriding effect of mkForce on submodule definitions. checkConfigError 'attribute .*bar.* .* not found' config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix -checkConfigOutput 'false' config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix ./define-attrsOfSub-bar.nix +checkConfigOutput '^false$' config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix ./define-attrsOfSub-bar.nix set -- config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix ./define-attrsOfSub-bar-enable.nix -checkConfigOutput 'true' "$@" +checkConfigOutput '^true$' "$@" checkConfigError 'attribute .*bar.* .* not found' "$@" ./define-force-attrsOfSub-foo-enable.nix checkConfigError 'attribute .*bar.* .* not found' "$@" ./define-attrsOfSub-force-foo-enable.nix -checkConfigOutput 'true' "$@" ./define-attrsOfSub-foo-force-enable.nix -checkConfigOutput 'true' "$@" ./define-attrsOfSub-foo-enable-force.nix +checkConfigOutput '^true$' "$@" ./define-attrsOfSub-foo-force-enable.nix +checkConfigOutput '^true$' "$@" ./define-attrsOfSub-foo-enable-force.nix # Check mkIf with submodules. checkConfigError 'attribute .*foo.* .* not found' config.attrsOfSub.foo.enable ./declare-enable.nix ./declare-attrsOfSub-any-enable.nix @@ -115,24 +113,24 @@ set -- config.attrsOfSub.foo.enable ./declare-enable.nix ./declare-attrsOfSub-an checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-if-attrsOfSub-foo-enable.nix checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-attrsOfSub-if-foo-enable.nix checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-attrsOfSub-foo-if-enable.nix -checkConfigOutput 'false' "$@" ./define-attrsOfSub-foo-enable-if.nix -checkConfigOutput 'true' "$@" ./define-enable.nix ./define-if-attrsOfSub-foo-enable.nix -checkConfigOutput 'true' "$@" ./define-enable.nix ./define-attrsOfSub-if-foo-enable.nix -checkConfigOutput 'true' "$@" ./define-enable.nix ./define-attrsOfSub-foo-if-enable.nix -checkConfigOutput 'true' "$@" ./define-enable.nix ./define-attrsOfSub-foo-enable-if.nix +checkConfigOutput '^false$' "$@" ./define-attrsOfSub-foo-enable-if.nix +checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-if-attrsOfSub-foo-enable.nix +checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-attrsOfSub-if-foo-enable.nix +checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-attrsOfSub-foo-if-enable.nix +checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-attrsOfSub-foo-enable-if.nix # Check disabledModules with config definitions and option declarations. set -- config.enable ./define-enable.nix ./declare-enable.nix -checkConfigOutput "true" "$@" -checkConfigOutput "false" "$@" ./disable-define-enable.nix -checkConfigError "The option .*enable.* does not exist. Definition values:\n- In .*: true" "$@" ./disable-declare-enable.nix +checkConfigOutput '^true$' "$@" +checkConfigOutput '^false$' "$@" ./disable-define-enable.nix +checkConfigError "The option .*enable.* does not exist. Definition values:\n\s*- In .*: true" "$@" ./disable-declare-enable.nix checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-define-enable.nix ./disable-declare-enable.nix checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-enable-modules.nix # Check _module.args. set -- config.enable ./declare-enable.nix ./define-enable-with-custom-arg.nix checkConfigError 'while evaluating the module argument .*custom.* in .*define-enable-with-custom-arg.nix.*:' "$@" -checkConfigOutput "true" "$@" ./define-_module-args-custom.nix +checkConfigOutput '^true$' "$@" ./define-_module-args-custom.nix # Check that using _module.args on imports cause infinite recursions, with # the proper error context. @@ -142,71 +140,78 @@ checkConfigError 'infinite recursion encountered' "$@" # Check _module.check. set -- config.enable ./declare-enable.nix ./define-enable.nix ./define-attrsOfSub-foo.nix -checkConfigError 'The option .* does not exist. Definition values:\n- In .*' "$@" -checkConfigOutput "true" "$@" ./define-module-check.nix +checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*' "$@" +checkConfigOutput '^true$' "$@" ./define-module-check.nix # Check coerced value. -checkConfigOutput "\"42\"" config.value ./declare-coerced-value.nix -checkConfigOutput "\"24\"" config.value ./declare-coerced-value.nix ./define-value-string.nix -checkConfigError 'A definition for option .* is not.*string or signed integer convertible to it.*. Definition values:\n- In .*: \[ \]' config.value ./declare-coerced-value.nix ./define-value-list.nix +checkConfigOutput '^"42"$' config.value ./declare-coerced-value.nix +checkConfigOutput '^"24"$' config.value ./declare-coerced-value.nix ./define-value-string.nix +checkConfigError 'A definition for option .* is not.*string or signed integer convertible to it.*. Definition values:\n\s*- In .*: \[ \]' config.value ./declare-coerced-value.nix ./define-value-list.nix # Check coerced value with unsound coercion -checkConfigOutput "12" config.value ./declare-coerced-value-unsound.nix -checkConfigError 'A definition for option .* is not of type .*. Definition values:\n- In .*: "1000"' config.value ./declare-coerced-value-unsound.nix ./define-value-string-bigint.nix -checkConfigError 'unrecognised JSON value' config.value ./declare-coerced-value-unsound.nix ./define-value-string-arbitrary.nix +checkConfigOutput '^12$' config.value ./declare-coerced-value-unsound.nix +checkConfigError 'A definition for option .* is not of type .*. Definition values:\n\s*- In .*: "1000"' config.value ./declare-coerced-value-unsound.nix ./define-value-string-bigint.nix +checkConfigError 'json.exception.parse_error' config.value ./declare-coerced-value-unsound.nix ./define-value-string-arbitrary.nix # Check mkAliasOptionModule. -checkConfigOutput "true" config.enable ./alias-with-priority.nix -checkConfigOutput "true" config.enableAlias ./alias-with-priority.nix -checkConfigOutput "false" config.enable ./alias-with-priority-can-override.nix -checkConfigOutput "false" config.enableAlias ./alias-with-priority-can-override.nix +checkConfigOutput '^true$' config.enable ./alias-with-priority.nix +checkConfigOutput '^true$' config.enableAlias ./alias-with-priority.nix +checkConfigOutput '^false$' config.enable ./alias-with-priority-can-override.nix +checkConfigOutput '^false$' config.enableAlias ./alias-with-priority-can-override.nix # submoduleWith ## specialArgs should work -checkConfigOutput "foo" config.submodule.foo ./declare-submoduleWith-special.nix +checkConfigOutput '^"foo"$' config.submodule.foo ./declare-submoduleWith-special.nix ## shorthandOnlyDefines config behaves as expected -checkConfigOutput "true" config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-shorthand.nix +checkConfigOutput '^true$' config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-shorthand.nix checkConfigError 'is not of type `boolean' config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-noshorthand.nix -checkConfigError "You're trying to declare a value of type \`bool'\nrather than an attribute-set for the option" config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-shorthand.nix -checkConfigOutput "true" config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-noshorthand.nix +checkConfigError "You're trying to declare a value of type \`bool'\n\s*rather than an attribute-set for the option" config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-shorthand.nix +checkConfigOutput '^true$' config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-noshorthand.nix ## submoduleWith should merge all modules in one swoop -checkConfigOutput "true" config.submodule.inner ./declare-submoduleWith-modules.nix -checkConfigOutput "true" config.submodule.outer ./declare-submoduleWith-modules.nix +checkConfigOutput '^true$' config.submodule.inner ./declare-submoduleWith-modules.nix +checkConfigOutput '^true$' config.submodule.outer ./declare-submoduleWith-modules.nix # Should also be able to evaluate the type name (which evaluates freeformType, # which evaluates all the modules defined by the type) -checkConfigOutput "submodule" options.submodule.type.description ./declare-submoduleWith-modules.nix +checkConfigOutput '^"submodule"$' options.submodule.type.description ./declare-submoduleWith-modules.nix + +## submodules can be declared using (evalModules {...}).type +checkConfigOutput '^true$' config.submodule.inner ./declare-submodule-via-evalModules.nix +checkConfigOutput '^true$' config.submodule.outer ./declare-submodule-via-evalModules.nix +# Should also be able to evaluate the type name (which evaluates freeformType, +# which evaluates all the modules defined by the type) +checkConfigOutput '^"submodule"$' options.submodule.type.description ./declare-submodule-via-evalModules.nix ## Paths should be allowed as values and work as expected -checkConfigOutput "true" config.submodule.enable ./declare-submoduleWith-path.nix +checkConfigOutput '^true$' config.submodule.enable ./declare-submoduleWith-path.nix # Check that disabledModules works recursively and correctly -checkConfigOutput "true" config.enable ./disable-recursive/main.nix -checkConfigOutput "true" config.enable ./disable-recursive/{main.nix,disable-foo.nix} -checkConfigOutput "true" config.enable ./disable-recursive/{main.nix,disable-bar.nix} -checkConfigError 'The option .* does not exist. Definition values:\n- In .*: true' config.enable ./disable-recursive/{main.nix,disable-foo.nix,disable-bar.nix} +checkConfigOutput '^true$' config.enable ./disable-recursive/main.nix +checkConfigOutput '^true$' config.enable ./disable-recursive/{main.nix,disable-foo.nix} +checkConfigOutput '^true$' config.enable ./disable-recursive/{main.nix,disable-bar.nix} +checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./disable-recursive/{main.nix,disable-foo.nix,disable-bar.nix} # Check that imports can depend on derivations -checkConfigOutput "true" config.enable ./import-from-store.nix +checkConfigOutput '^true$' config.enable ./import-from-store.nix # Check that configs can be conditional on option existence -checkConfigOutput true config.enable ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix -checkConfigOutput 360 config.value ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix -checkConfigOutput 7 config.value ./define-option-dependently.nix ./declare-int-positive-value.nix -checkConfigOutput true config.set.enable ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix -checkConfigOutput 360 config.set.value ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix -checkConfigOutput 7 config.set.value ./define-option-dependently-nested.nix ./declare-int-positive-value-nested.nix +checkConfigOutput '^true$' config.enable ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix +checkConfigOutput '^360$' config.value ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix +checkConfigOutput '^7$' config.value ./define-option-dependently.nix ./declare-int-positive-value.nix +checkConfigOutput '^true$' config.set.enable ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix +checkConfigOutput '^360$' config.set.value ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix +checkConfigOutput '^7$' config.set.value ./define-option-dependently-nested.nix ./declare-int-positive-value-nested.nix # Check attrsOf and lazyAttrsOf. Only lazyAttrsOf should be lazy, and only # attrsOf should work with conditional definitions # In addition, lazyAttrsOf should honor an options emptyValue checkConfigError "is not lazy" config.isLazy ./declare-attrsOf.nix ./attrsOf-lazy-check.nix -checkConfigOutput "true" config.isLazy ./declare-lazyAttrsOf.nix ./attrsOf-lazy-check.nix -checkConfigOutput "true" config.conditionalWorks ./declare-attrsOf.nix ./attrsOf-conditional-check.nix -checkConfigOutput "false" config.conditionalWorks ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix -checkConfigOutput "empty" config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix +checkConfigOutput '^true$' config.isLazy ./declare-lazyAttrsOf.nix ./attrsOf-lazy-check.nix +checkConfigOutput '^true$' config.conditionalWorks ./declare-attrsOf.nix ./attrsOf-conditional-check.nix +checkConfigOutput '^false$' config.conditionalWorks ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix +checkConfigOutput '^"empty"$' config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix # Even with multiple assignments, a type error should be thrown if any of them aren't valid @@ -215,64 +220,69 @@ checkConfigError 'A definition for option .* is not of type .*' \ ## Freeform modules # Assigning without a declared option should work -checkConfigOutput 24 config.value ./freeform-attrsOf.nix ./define-value-string.nix +checkConfigOutput '^"24"$' config.value ./freeform-attrsOf.nix ./define-value-string.nix # No freeform assigments shouldn't make it error -checkConfigOutput '{ }' config ./freeform-attrsOf.nix +checkConfigOutput '^{ }$' config ./freeform-attrsOf.nix # but only if the type matches checkConfigError 'A definition for option .* is not of type .*' config.value ./freeform-attrsOf.nix ./define-value-list.nix # and properties should be applied -checkConfigOutput yes config.value ./freeform-attrsOf.nix ./define-value-string-properties.nix +checkConfigOutput '^"yes"$' config.value ./freeform-attrsOf.nix ./define-value-string-properties.nix # Options should still be declarable, and be able to have a type that doesn't match the freeform type -checkConfigOutput false config.enable ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix -checkConfigOutput 24 config.value ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix +checkConfigOutput '^false$' config.enable ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix +checkConfigOutput '^"24"$' config.value ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix # and this should work too with nested values -checkConfigOutput false config.nest.foo ./freeform-attrsOf.nix ./freeform-nested.nix -checkConfigOutput bar config.nest.bar ./freeform-attrsOf.nix ./freeform-nested.nix +checkConfigOutput '^false$' config.nest.foo ./freeform-attrsOf.nix ./freeform-nested.nix +checkConfigOutput '^"bar"$' config.nest.bar ./freeform-attrsOf.nix ./freeform-nested.nix # Check whether a declared option can depend on an freeform-typed one -checkConfigOutput null config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix -checkConfigOutput 24 config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix ./define-value-string.nix +checkConfigOutput '^null$' config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix +checkConfigOutput '^"24"$' config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix ./define-value-string.nix # Check whether an freeform-typed value can depend on a declared option, this can only work with lazyAttrsOf checkConfigError 'infinite recursion encountered' config.foo ./freeform-attrsOf.nix ./freeform-unstr-dep-str.nix checkConfigError 'The option .* is used but not defined' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix -checkConfigOutput 24 config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix ./define-value-string.nix +checkConfigOutput '^"24"$' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix ./define-value-string.nix ## types.anything # Check that attribute sets are merged recursively -checkConfigOutput null config.value.foo ./types-anything/nested-attrs.nix -checkConfigOutput null config.value.l1.foo ./types-anything/nested-attrs.nix -checkConfigOutput null config.value.l1.l2.foo ./types-anything/nested-attrs.nix -checkConfigOutput null config.value.l1.l2.l3.foo ./types-anything/nested-attrs.nix +checkConfigOutput '^null$' config.value.foo ./types-anything/nested-attrs.nix +checkConfigOutput '^null$' config.value.l1.foo ./types-anything/nested-attrs.nix +checkConfigOutput '^null$' config.value.l1.l2.foo ./types-anything/nested-attrs.nix +checkConfigOutput '^null$' config.value.l1.l2.l3.foo ./types-anything/nested-attrs.nix # Attribute sets that are coercible to strings shouldn't be recursed into -checkConfigOutput foo config.value.outPath ./types-anything/attrs-coercible.nix +checkConfigOutput '^"foo"$' config.value.outPath ./types-anything/attrs-coercible.nix # Multiple lists aren't concatenated together checkConfigError 'The option .* has conflicting definitions' config.value ./types-anything/lists.nix # Check that all equalizable atoms can be used as long as all definitions are equal -checkConfigOutput 0 config.value.int ./types-anything/equal-atoms.nix -checkConfigOutput false config.value.bool ./types-anything/equal-atoms.nix -checkConfigOutput '""' config.value.string ./types-anything/equal-atoms.nix -checkConfigOutput / config.value.path ./types-anything/equal-atoms.nix -checkConfigOutput null config.value.null ./types-anything/equal-atoms.nix -checkConfigOutput 0.1 config.value.float ./types-anything/equal-atoms.nix +checkConfigOutput '^0$' config.value.int ./types-anything/equal-atoms.nix +checkConfigOutput '^false$' config.value.bool ./types-anything/equal-atoms.nix +checkConfigOutput '^""$' config.value.string ./types-anything/equal-atoms.nix +checkConfigOutput '^/$' config.value.path ./types-anything/equal-atoms.nix +checkConfigOutput '^null$' config.value.null ./types-anything/equal-atoms.nix +checkConfigOutput '^0.1$' config.value.float ./types-anything/equal-atoms.nix # Functions can't be merged together checkConfigError "The option .value.multiple-lambdas.<function body>. has conflicting option types" config.applied.multiple-lambdas ./types-anything/functions.nix -checkConfigOutput '<LAMBDA>' config.value.single-lambda ./types-anything/functions.nix -checkConfigOutput 'null' config.applied.merging-lambdas.x ./types-anything/functions.nix -checkConfigOutput 'null' config.applied.merging-lambdas.y ./types-anything/functions.nix +checkConfigOutput '^<LAMBDA>$' config.value.single-lambda ./types-anything/functions.nix +checkConfigOutput '^null$' config.applied.merging-lambdas.x ./types-anything/functions.nix +checkConfigOutput '^null$' config.applied.merging-lambdas.y ./types-anything/functions.nix # Check that all mk* modifiers are applied checkConfigError 'attribute .* not found' config.value.mkiffalse ./types-anything/mk-mods.nix -checkConfigOutput '{ }' config.value.mkiftrue ./types-anything/mk-mods.nix -checkConfigOutput 1 config.value.mkdefault ./types-anything/mk-mods.nix -checkConfigOutput '{ }' config.value.mkmerge ./types-anything/mk-mods.nix -checkConfigOutput true config.value.mkbefore ./types-anything/mk-mods.nix -checkConfigOutput 1 config.value.nested.foo ./types-anything/mk-mods.nix -checkConfigOutput baz config.value.nested.bar.baz ./types-anything/mk-mods.nix +checkConfigOutput '^{ }$' config.value.mkiftrue ./types-anything/mk-mods.nix +checkConfigOutput '^1$' config.value.mkdefault ./types-anything/mk-mods.nix +checkConfigOutput '^{ }$' config.value.mkmerge ./types-anything/mk-mods.nix +checkConfigOutput '^true$' config.value.mkbefore ./types-anything/mk-mods.nix +checkConfigOutput '^1$' config.value.nested.foo ./types-anything/mk-mods.nix +checkConfigOutput '^"baz"$' config.value.nested.bar.baz ./types-anything/mk-mods.nix ## types.functionTo -checkConfigOutput "input is input" config.result ./functionTo/trivial.nix -checkConfigOutput "a b" config.result ./functionTo/merging-list.nix -checkConfigError 'A definition for option .fun.\[function body\]. is not of type .string.. Definition values:\n- In .*wrong-type.nix' config.result ./functionTo/wrong-type.nix -checkConfigOutput "b a" config.result ./functionTo/list-order.nix -checkConfigOutput "a c" config.result ./functionTo/merging-attrs.nix +checkConfigOutput '^"input is input"$' config.result ./functionTo/trivial.nix +checkConfigOutput '^"a b"$' config.result ./functionTo/merging-list.nix +checkConfigError 'A definition for option .fun.\[function body\]. is not of type .string.. Definition values:\n\s*- In .*wrong-type.nix' config.result ./functionTo/wrong-type.nix +checkConfigOutput '^"b a"$' config.result ./functionTo/list-order.nix +checkConfigOutput '^"a c"$' config.result ./functionTo/merging-attrs.nix + +# moduleType +checkConfigOutput '^"a b"$' config.resultFoo ./declare-variants.nix ./define-variant.nix +checkConfigOutput '^"a y z"$' config.resultFooBar ./declare-variants.nix ./define-variant.nix +checkConfigOutput '^"a b c"$' config.resultFooFoo ./declare-variants.nix ./define-variant.nix cat <<EOF ====== module tests ====== @@ -280,7 +290,7 @@ $pass Pass $fail Fail EOF -if test $fail -ne 0; then +if [ "$fail" -ne 0 ]; then exit 1 fi exit 0 diff --git a/lib/tests/modules/declare-submodule-via-evalModules.nix b/lib/tests/modules/declare-submodule-via-evalModules.nix new file mode 100644 index 00000000000..2841c64a073 --- /dev/null +++ b/lib/tests/modules/declare-submodule-via-evalModules.nix @@ -0,0 +1,28 @@ +{ lib, ... }: { + options.submodule = lib.mkOption { + inherit (lib.evalModules { + modules = [ + { + options.inner = lib.mkOption { + type = lib.types.bool; + default = false; + }; + } + ]; + }) type; + default = {}; + }; + + config.submodule = lib.mkMerge [ + ({ lib, ... }: { + options.outer = lib.mkOption { + type = lib.types.bool; + default = false; + }; + }) + { + inner = true; + outer = true; + } + ]; +} diff --git a/lib/tests/modules/declare-variants.nix b/lib/tests/modules/declare-variants.nix new file mode 100644 index 00000000000..3ed6fa689e2 --- /dev/null +++ b/lib/tests/modules/declare-variants.nix @@ -0,0 +1,9 @@ +{ lib, moduleType, ... }: +let inherit (lib) mkOption types; +in +{ + options.variants = mkOption { + type = types.lazyAttrsOf moduleType; + default = {}; + }; +} diff --git a/lib/tests/modules/define-variant.nix b/lib/tests/modules/define-variant.nix new file mode 100644 index 00000000000..423cb0e37cb --- /dev/null +++ b/lib/tests/modules/define-variant.nix @@ -0,0 +1,22 @@ +{ config, lib, ... }: +let inherit (lib) types mkOption attrNames; +in +{ + options = { + attrs = mkOption { type = types.attrsOf lib.types.int; }; + result = mkOption { }; + resultFoo = mkOption { }; + resultFooBar = mkOption { }; + resultFooFoo = mkOption { }; + }; + config = { + attrs.a = 1; + variants.foo.attrs.b = 1; + variants.bar.attrs.y = 1; + variants.foo.variants.bar.attrs.z = 1; + variants.foo.variants.foo.attrs.c = 3; + resultFoo = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.attrs); + resultFooBar = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.variants.bar.attrs); + resultFooFoo = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.variants.foo.attrs); + }; +} diff --git a/lib/tests/release.nix b/lib/tests/release.nix index 77e0e1af755..815841e0a8f 100644 --- a/lib/tests/release.nix +++ b/lib/tests/release.nix @@ -23,6 +23,10 @@ pkgs.runCommand "nixpkgs-lib-tests" { export NIX_STORE_DIR=$TEST_ROOT/store export PAGER=cat cacheDir=$TEST_ROOT/binary-cache + + mkdir -p $NIX_CONF_DIR + echo "experimental-features = nix-command" >> $NIX_CONF_DIR/nix.conf + nix-store --init cp -r ${../.} lib diff --git a/lib/tests/sources.sh b/lib/tests/sources.sh index 71fee719cb2..a7f490a79d7 100755 --- a/lib/tests/sources.sh +++ b/lib/tests/sources.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -euo pipefail +shopt -s inherit_errexit # Use # || die @@ -9,27 +10,28 @@ die() { } if test -n "${TEST_LIB:-}"; then - export NIX_PATH=nixpkgs="$(dirname "$TEST_LIB")" + NIX_PATH=nixpkgs="$(dirname "$TEST_LIB")" else - export NIX_PATH=nixpkgs="$(cd $(dirname ${BASH_SOURCE[0]})/../..; pwd)" + NIX_PATH=nixpkgs="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.."; pwd)" fi +export NIX_PATH work="$(mktemp -d)" clean_up() { rm -rf "$work" } trap clean_up EXIT -cd $work +cd "$work" touch {README.md,module.o,foo.bar} # nix-instantiate doesn't write out the source, only computing the hash, so # this uses the experimental nix command instead. -dir="$(nix eval --raw '(with import <nixpkgs/lib>; "${ +dir="$(nix eval --impure --raw --expr '(with import <nixpkgs/lib>; "${ cleanSource ./. }")')" -(cd $dir; find) | sort -f | diff -U10 - <(cat <<EOF +(cd "$dir"; find) | sort -f | diff -U10 - <(cat <<EOF . ./foo.bar ./README.md @@ -37,20 +39,20 @@ EOF ) || die "cleanSource 1" -dir="$(nix eval --raw '(with import <nixpkgs/lib>; "${ +dir="$(nix eval --impure --raw --expr '(with import <nixpkgs/lib>; "${ cleanSourceWith { src = '"$work"'; filter = path: type: ! hasSuffix ".bar" path; } }")')" -(cd $dir; find) | sort -f | diff -U10 - <(cat <<EOF +(cd "$dir"; find) | sort -f | diff -U10 - <(cat <<EOF . ./module.o ./README.md EOF ) || die "cleanSourceWith 1" -dir="$(nix eval --raw '(with import <nixpkgs/lib>; "${ +dir="$(nix eval --impure --raw --expr '(with import <nixpkgs/lib>; "${ cleanSourceWith { src = cleanSource '"$work"'; filter = path: type: ! hasSuffix ".bar" path; } }")')" -(cd $dir; find) | sort -f | diff -U10 - <(cat <<EOF +(cd "$dir"; find) | sort -f | diff -U10 - <(cat <<EOF . ./README.md EOF diff --git a/lib/trivial.nix b/lib/trivial.nix index a389c7cdfac..33b553ac419 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -171,7 +171,7 @@ rec { On each release the first letter is bumped and a new animal is chosen starting with that new letter. */ - codeName = "Porcupine"; + codeName = "Quokka"; /* Returns the current nixpkgs version suffix as string. */ versionSuffix = diff --git a/lib/types.nix b/lib/types.nix index c2532065d7e..244cbb6b535 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -505,17 +505,36 @@ rec { then setFunctionArgs (args: unify (value args)) (functionArgs value) else unify (if shorthandOnlyDefinesConfig then { config = value; } else value); - allModules = defs: modules ++ imap1 (n: { value, file }: + allModules = defs: imap1 (n: { value, file }: 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; - freeformType = (evalModules { - inherit modules specialArgs; - args.name = "‹name›"; - })._module.freeformType; + base = evalModules { + inherit specialArgs; + modules = [{ + # This is a work-around for the fact that some sub-modules, + # such as the one included in an attribute set, expects an "args" + # attribute to be given to the sub-module. As the option + # evaluation does not have any specific attribute name yet, we + # provide a default for the documentation and the freeform type. + # + # This is necessary as some option declaration might use the + # "name" attribute given as argument of the submodule and use it + # as the default of option declarations. + # + # We use lookalike unicode single angle quotation marks because + # of the docbook transformation the options receive. In all uses + # > and < wouldn't be encoded correctly so the encoded values + # would be used, and use of `<` and `>` would break the XML document. + # It shouldn't cause an issue since this is cosmetic for the manual. + _module.args.name = lib.mkOptionDefault "‹name›"; + }] ++ modules; + }; + + freeformType = base._module.freeformType; in mkOptionType rec { @@ -523,32 +542,13 @@ rec { description = freeformType.description or name; check = x: isAttrs x || isFunction x || path.check x; merge = loc: defs: - (evalModules { - modules = allModules defs; - inherit specialArgs; - args.name = last loc; + (base.extendModules { + modules = [ { _module.args.name = last loc; } ] ++ allModules defs; prefix = loc; }).config; emptyValue = { value = {}; }; - getSubOptions = prefix: (evalModules - { inherit modules prefix specialArgs; - # This is a work-around due to the fact that some sub-modules, - # such as the one included in an attribute set, expects a "args" - # attribute to be given to the sub-module. As the option - # evaluation does not have any specific attribute name, we - # provide a default one for the documentation. - # - # This is mandatory as some option declaration might use the - # "name" attribute given as argument of the submodule and use it - # as the default of option declarations. - # - # Using lookalike unicode single angle quotation marks because - # of the docbook transformation the options receive. In all uses - # > and < wouldn't be encoded correctly so the encoded values - # would be used, and use of `<` and `>` would break the XML document. - # It shouldn't cause an issue since this is cosmetic for the manual. - args.name = "‹name›"; - }).options // optionalAttrs (freeformType != null) { + getSubOptions = prefix: (base.extendModules + { inherit prefix; }).options // optionalAttrs (freeformType != null) { # Expose the sub options of the freeform type. Note that the option # discovery doesn't care about the attribute name used here, so this # is just to avoid conflicts with potential options from the submodule |