nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at master 890 lines 63 kB view raw
1#!/usr/bin/env bash 2 3# This script is used to test that the module system is working as expected. 4# Executing it runs tests for `lib.modules`, `lib.options` and `lib.types`. 5# By default it test the version of nixpkgs which is defined in the NIX_PATH. 6# 7# Run: 8# [nixpkgs]$ lib/tests/modules.sh 9# or: 10# [nixpkgs]$ nix-build lib/tests/release.nix 11 12set -o errexit -o noclobber -o nounset -o pipefail 13shopt -s failglob inherit_errexit 14 15# https://stackoverflow.com/a/246128/6605742 16DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" 17 18cd "$DIR"/modules 19 20pass=0 21fail=0 22 23local-nix-instantiate() { 24 nix-instantiate --timeout 1 --eval-only --show-trace --read-write-mode --json "$@" 25} 26 27# loc 28# prints the location of the call of to the function that calls it 29# loc n 30# prints the location n levels up the call stack 31loc() { 32 local caller depth 33 depth=1 34 if [[ $# -gt 0 ]]; then 35 depth=$1 36 fi 37 # ( lineno fnname file ) of the caller 38 caller=( $(caller $depth) ) 39 echo "${caller[2]}:${caller[0]}" 40} 41 42line() { 43 echo "----------------------------------------" 44} 45logStartFailure() { 46 line 47} 48logEndFailure() { 49 line 50 echo 51} 52 53logFailure() { 54 # bold red 55 printf '\033[1;31mTEST FAILED\033[0m at %s\n' "$(loc 2)" 56} 57 58evalConfig() { 59 local attr=$1 60 shift 61 62 local nix_args=() 63 64 if [ "${ABORT_ON_WARN-0}" = "1" ]; then 65 nix_args+=(--option abort-on-warn true) 66 fi 67 68 if [ "${STRICT_EVAL-0}" = "1" ]; then 69 nix_args+=(--strict) 70 fi 71 72 local script="import ./default.nix { modules = [ $* ];}" 73 local-nix-instantiate "${nix_args[@]}" -E "$script" -A "$attr" 74} 75 76reportFailure() { 77 local attr=$1 78 shift 79 local script="import ./default.nix { modules = [ $* ];}" 80 echo "$ nix-instantiate -E '$script' -A '$attr' --eval-only --json" 81 evalConfig "$attr" "$@" || true 82 ((++fail)) 83} 84 85checkConfigOutput() { 86 local outputContains=$1 87 shift 88 if evalConfig "$@" 2>/dev/null | grep -E --silent "$outputContains" ; then 89 ((++pass)) 90 else 91 logStartFailure 92 echo "ACTUAL:" 93 reportFailure "$@" 94 echo "EXPECTED: result matching '$outputContains'" 95 logFailure 96 logEndFailure 97 fi 98} 99 100invertIfUnset() { 101 gate="$1" 102 shift 103 if [[ -n "${!gate:-}" ]]; then 104 "$@" 105 else 106 ! "$@" 107 fi 108} 109 110globalErrorLogCheck() { 111 invertIfUnset "REQUIRE_INFINITE_RECURSION_HINT" \ 112 grep -i 'if you get an infinite recursion here' \ 113 <<<"$err" >/dev/null \ 114 || { 115 if [[ -n "${REQUIRE_INFINITE_RECURSION_HINT:-}" ]]; then 116 echo "Unexpected infinite recursion hint" 117 else 118 echo "Expected infinite recursion hint, but none found" 119 fi 120 return 1 121 } 122} 123 124checkExpression() { 125 local path=$1 126 local output 127 { 128 output="$(local-nix-instantiate --strict "$path" 2>&1)" && ((++pass)) 129 } || { 130 logStartFailure 131 echo "$output" 132 ((++fail)) 133 logFailure 134 logEndFailure 135 } 136} 137 138checkConfigError() { 139 local errorContains=$1 140 local err="" 141 shift 142 if err="$(evalConfig "$@" 2>&1 >/dev/null)"; then 143 logStartFailure 144 echo "ACTUAL: exit code 0, output:" 145 reportFailure "$@" 146 echo "EXPECTED: non-zero exit code" 147 logFailure 148 logEndFailure 149 else 150 if ! globalErrorLogCheck "$err"; then 151 logStartFailure 152 echo "LOG:" 153 reportFailure "$@" 154 echo "GLOBAL ERROR LOG CHECK FAILED" 155 logFailure 156 logEndFailure 157 fi 158 if echo "$err" | grep -zP --silent "$errorContains" ; then 159 ((++pass)) 160 else 161 logStartFailure 162 echo "ACTUAL:" 163 reportFailure "$@" 164 echo "EXPECTED: error matching '$errorContains'" 165 logFailure 166 logEndFailure 167 fi 168 fi 169} 170 171# Shorthand meta attribute does not duplicate the config 172checkConfigOutput '^"one two"$' config.result ./shorthand-meta.nix 173 174checkConfigOutput '^true$' config.result ./test-mergeAttrDefinitionsWithPrio.nix 175 176# Check that a module argument is passed, also when a default is available 177# (but not needed) 178# 179# When the default is needed, we currently fail to do what the users expect, as 180# we pass our own argument anyway, even if it *turns out* not to exist. 181# 182# The reason for this is that we don't know at invocation time what is in the 183# _module.args option. That value is only available *after* all modules have been 184# invoked. 185# 186# Hypothetically, Nix could help support this by giving access to the default 187# values, through a new built-in function. 188# However the default values are allowed to depend on other arguments, so those 189# would have to be passed in somehow, making this not just a getter but 190# something more complicated. 191# 192# At that point we have to wonder whether the extra complexity is worth the cost. 193# Another - subjective - reason not to support it is that default values 194# contradict the notion that an option has a single value, where _module.args 195# is the option. 196checkConfigOutput '^true$' config.result ./module-argument-default.nix 197 198# gvariant 199checkConfigOutput '^true$' config.assertion ./gvariant.nix 200 201checkConfigOutput '"ok"' config.result ./specialArgs-lib.nix 202 203# https://github.com/NixOS/nixpkgs/pull/131205 204# We currently throw this error already in `config`, but throwing in `config.wrong1` would be acceptable. 205checkConfigError 'It seems as if you.re trying to declare an option by placing it into .config. rather than .options.' config.wrong1 ./error-mkOption-in-config.nix 206# We currently throw this error already in `config`, but throwing in `config.nest.wrong2` would be acceptable. 207checkConfigError 'It seems as if you.re trying to declare an option by placing it into .config. rather than .options.' config.nest.wrong2 ./error-mkOption-in-config.nix 208checkConfigError 'The option .sub.wrong2. does not exist. Definition values:' config.sub ./error-mkOption-in-submodule-config.nix 209checkConfigError '.*This can happen if you e.g. declared your options in .types.submodule.' config.sub ./error-mkOption-in-submodule-config.nix 210checkConfigError '.*A definition for option .bad. is not of type .non-empty .list of .submodule...\.' config.bad ./error-nonEmptyListOf-submodule.nix 211 212# types.attrTag 213checkConfigOutput '^true$' config.okChecks ./types-attrTag.nix 214checkConfigError 'A definition for option .intStrings\.syntaxError. is not of type .attribute-tagged union with choices: left, right' config.intStrings.syntaxError ./types-attrTag.nix 215checkConfigError 'A definition for option .intStrings\.syntaxError2. is not of type .attribute-tagged union with choices: left, right' config.intStrings.syntaxError2 ./types-attrTag.nix 216checkConfigError 'A definition for option .intStrings\.syntaxError3. is not of type .attribute-tagged union with choices: left, right' config.intStrings.syntaxError3 ./types-attrTag.nix 217checkConfigError 'A definition for option .intStrings\.syntaxError4. is not of type .attribute-tagged union with choices: left, right' config.intStrings.syntaxError4 ./types-attrTag.nix 218checkConfigError 'A definition for option .intStrings\.mergeError. is not of type .attribute-tagged union with choices: left, right' config.intStrings.mergeError ./types-attrTag.nix 219checkConfigError 'A definition for option .intStrings\.badTagError. is not of type .attribute-tagged union with choices: left, right' config.intStrings.badTagError ./types-attrTag.nix 220checkConfigError 'A definition for option .intStrings\.badTagTypeError\.left. is not of type .signed integer.' config.intStrings.badTagTypeError.left ./types-attrTag.nix 221checkConfigError 'A definition for option .nested\.right\.left. is not of type .signed integer.' config.nested.right.left ./types-attrTag.nix 222checkConfigError 'In attrTag, each tag value must be an option, but tag int was a bare type, not wrapped in mkOption.' config.opt.int ./types-attrTag-wrong-decl.nix 223 224# types 225checkConfigOutput '"ok"' config.assertions ./types.nix 226 227# types.pathInStore 228checkConfigOutput '".*/store/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv"' config.pathInStore.ok1 ./types.nix 229checkConfigOutput '".*/store/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15"' config.pathInStore.ok2 ./types.nix 230checkConfigOutput '".*/store/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15/bin/bash"' config.pathInStore.ok3 ./types.nix 231checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ""' config.pathInStore.bad1 ./types.nix 232checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store"' config.pathInStore.bad2 ./types.nix 233checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store/"' config.pathInStore.bad3 ./types.nix 234checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store/.links"' config.pathInStore.bad4 ./types.nix 235checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: "/foo/bar"' config.pathInStore.bad5 ./types.nix 236 237# types.externalPath 238checkConfigOutput '".*/foo/bar"' config.externalPath.ok1 ./types.nix 239checkConfigOutput '".*/"' config.externalPath.ok2 ./types.nix 240checkConfigError 'A definition for option .* is not of type .absolute path not in the Nix store.' config.externalPath.bad1 ./types.nix 241checkConfigError 'A definition for option .* is not of type .absolute path not in the Nix store.' config.externalPath.bad2 ./types.nix 242checkConfigError 'A definition for option .* is not of type .absolute path not in the Nix store.' config.externalPath.bad3 ./types.nix 243checkConfigError 'A definition for option .* is not of type .absolute path not in the Nix store.' config.externalPath.bad4 ./types.nix 244checkConfigError 'A definition for option .* is not of type .absolute path not in the Nix store.' config.externalPath.bad5 ./types.nix 245 246# types.fileset 247checkConfigOutput '^0$' config.filesetCardinal.ok1 ./fileset.nix 248checkConfigOutput '^1$' config.filesetCardinal.ok2 ./fileset.nix 249checkConfigOutput '^1$' config.filesetCardinal.ok3 ./fileset.nix 250checkConfigOutput '^1$' config.filesetCardinal.ok4 ./fileset.nix 251checkConfigOutput '^0$' config.filesetCardinal.ok5 ./fileset.nix 252checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err1 ./fileset.nix 253checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err2 ./fileset.nix 254checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err3 ./fileset.nix 255checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err4 ./fileset.nix 256 257# types.serializableValueWith 258checkConfigOutput '^null$' config.nullableValue.null ./types.nix 259checkConfigOutput '^true$' config.nullableValue.bool ./types.nix 260checkConfigOutput '^1$' config.nullableValue.int ./types.nix 261checkConfigOutput '^1.1$' config.nullableValue.float ./types.nix 262checkConfigOutput '^"foo"$' config.nullableValue.str ./types.nix 263checkConfigOutput '^".*/store.*"$' config.nullableValue.path ./types.nix 264STRICT_EVAL=1 checkConfigOutput '^\{"foo":1\}$' config.nullableValue.attrs ./types.nix 265STRICT_EVAL=1 checkConfigOutput '^\[\{"bar":\[1\]\}\]$' config.nullableValue.list ./types.nix 266 267checkConfigError 'A definition for option .* is not of type .VAL value.. .*' config.nullableValue.lambda ./types.nix 268checkConfigError 'A definition for option .* is not of type .VAL value.. .*' config.structuredValue.null ./types.nix 269 270# Check boolean option. 271checkConfigOutput '^false$' config.enable ./declare-enable.nix 272checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./define-enable.nix 273checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*' config.enable ./define-enable-throw.nix 274checkConfigError 'while evaluating a definition from `.*/define-enable-abort.nix' config.enable ./define-enable-abort.nix 275checkConfigError 'while evaluating the error message for definitions for .enable., which is an option that does not exist' config.enable ./define-enable-abort.nix 276 277# Check boolByOr type. 278checkConfigOutput '^false$' config.value.falseFalse ./boolByOr.nix 279checkConfigOutput '^true$' config.value.trueFalse ./boolByOr.nix 280checkConfigOutput '^true$' config.value.falseTrue ./boolByOr.nix 281checkConfigOutput '^true$' config.value.trueTrue ./boolByOr.nix 282 283checkConfigOutput '^1$' config.bare-submodule.nested ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix 284checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix 285checkConfigOutput '^42$' config.bare-submodule.nested ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix ./declare-bare-submodule-deep-option.nix ./define-bare-submodule-values.nix 286checkConfigOutput '^420$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix ./declare-bare-submodule-deep-option.nix ./define-bare-submodule-values.nix 287checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix ./define-shorthandOnlyDefinesConfig-true.nix 288checkConfigError 'The option .bare-submodule.deep. in .*/declare-bare-submodule-deep-option.nix. is already declared in .*/declare-bare-submodule-deep-option-duplicate.nix' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix ./declare-bare-submodule-deep-option-duplicate.nix 289 290# Check that strMatching can be merged 291checkConfigOutput '^"strMatching.*"$' options.sm.type.name ./strMatching-merge.nix 292 293# Check integer types. 294# unsigned 295checkConfigOutput '^42$' config.value ./declare-int-unsigned-value.nix ./define-value-int-positive.nix 296checkConfigError '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 297# positive 298checkConfigError '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 299# between 300checkConfigOutput '^42$' config.value ./declare-int-between-value.nix ./define-value-int-positive.nix 301checkConfigError '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 302 303# Check either types 304# types.either 305checkConfigOutput '^42$' config.value ./declare-either.nix ./define-value-int-positive.nix 306checkConfigOutput '^"24"$' config.value ./declare-either.nix ./define-value-string.nix 307# types.oneOf 308checkConfigOutput '^42$' config.value ./declare-oneOf.nix ./define-value-int-positive.nix 309checkConfigOutput '^\[\]$' config.value ./declare-oneOf.nix ./define-value-list.nix 310checkConfigOutput '^"24"$' config.value ./declare-oneOf.nix ./define-value-string.nix 311 312# Check mkForce without submodules. 313set -- config.enable ./declare-enable.nix ./define-enable.nix 314checkConfigOutput '^true$' "$@" 315checkConfigOutput '^false$' "$@" ./define-force-enable.nix 316checkConfigOutput '^false$' "$@" ./define-enable-force.nix 317 318# Check mkForce with option and submodules. 319checkConfigError 'attribute .*foo.* .* not found' config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix 320checkConfigOutput '^false$' config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix 321set -- config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo-enable.nix 322checkConfigOutput '^true$' "$@" 323checkConfigOutput '^false$' "$@" ./define-force-attrsOfSub-foo-enable.nix 324checkConfigOutput '^false$' "$@" ./define-attrsOfSub-force-foo-enable.nix 325checkConfigOutput '^false$' "$@" ./define-attrsOfSub-foo-force-enable.nix 326checkConfigOutput '^false$' "$@" ./define-attrsOfSub-foo-enable-force.nix 327 328# Check overriding effect of mkForce on submodule definitions. 329checkConfigError 'attribute .*bar.* .* not found' config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix 330checkConfigOutput '^false$' config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix ./define-attrsOfSub-bar.nix 331set -- config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix ./define-attrsOfSub-bar-enable.nix 332checkConfigOutput '^true$' "$@" 333checkConfigError 'attribute .*bar.* .* not found' "$@" ./define-force-attrsOfSub-foo-enable.nix 334checkConfigError 'attribute .*bar.* .* not found' "$@" ./define-attrsOfSub-force-foo-enable.nix 335checkConfigOutput '^true$' "$@" ./define-attrsOfSub-foo-force-enable.nix 336checkConfigOutput '^true$' "$@" ./define-attrsOfSub-foo-enable-force.nix 337 338# Check mkIf with submodules. 339checkConfigError 'attribute .*foo.* .* not found' config.attrsOfSub.foo.enable ./declare-enable.nix ./declare-attrsOfSub-any-enable.nix 340set -- config.attrsOfSub.foo.enable ./declare-enable.nix ./declare-attrsOfSub-any-enable.nix 341checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-if-attrsOfSub-foo-enable.nix 342checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-attrsOfSub-if-foo-enable.nix 343checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-attrsOfSub-foo-if-enable.nix 344checkConfigOutput '^false$' "$@" ./define-attrsOfSub-foo-enable-if.nix 345checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-if-attrsOfSub-foo-enable.nix 346checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-attrsOfSub-if-foo-enable.nix 347checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-attrsOfSub-foo-if-enable.nix 348checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-attrsOfSub-foo-enable-if.nix 349 350# Check importApply 351checkConfigOutput '"abc"' config.value ./importApply.nix 352# importApply does not set a key. 353# Disabling the function file is not sufficient, because importApply can't reasonably assume that the key is unique. 354# e.g. user may call it multiple times with different arguments and expect each of the module to apply. 355# While this is excusable for the disabledModules aspect, it is not for the deduplication of modules. 356checkConfigOutput '"abc"' config.value ./importApply-disabling.nix 357 358# Check disabledModules with config definitions and option declarations. 359set -- config.enable ./define-enable.nix ./declare-enable.nix 360checkConfigOutput '^true$' "$@" 361checkConfigOutput '^false$' "$@" ./disable-define-enable.nix 362checkConfigOutput '^false$' "$@" ./disable-define-enable-string-path.nix 363checkConfigError "The option .*enable.* does not exist. Definition values:\n\s*- In .*: true" "$@" ./disable-declare-enable.nix 364checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-define-enable.nix ./disable-declare-enable.nix 365checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-enable-modules.nix 366 367checkConfigOutput '^true$' 'config.positive.enable' ./disable-module-with-key.nix 368checkConfigOutput '^false$' 'config.negative.enable' ./disable-module-with-key.nix 369checkConfigError 'Module ..*disable-module-bad-key.nix. contains a disabledModules item that is an attribute set, presumably a module, that does not have a .key. attribute. .*' 'config.enable' ./disable-module-bad-key.nix 370 371# Not sure if we want to keep supporting module keys that aren't strings, paths or v?key, but we shouldn't remove support accidentally. 372checkConfigOutput '^true$' 'config.positive.enable' ./disable-module-with-toString-key.nix 373checkConfigOutput '^false$' 'config.negative.enable' ./disable-module-with-toString-key.nix 374 375# Check _module.args. 376set -- config.enable ./declare-enable.nix ./define-enable-with-custom-arg.nix 377checkConfigError 'while evaluating the module argument .*custom.* in .*define-enable-with-custom-arg.nix.*:' "$@" 378checkConfigOutput '^true$' "$@" ./define-_module-args-custom.nix 379 380# Check that using _module.args on imports cause infinite recursions, with 381# the proper error context. 382set -- "$@" ./define-_module-args-custom.nix ./import-custom-arg.nix 383REQUIRE_INFINITE_RECURSION_HINT=1 checkConfigError 'while evaluating the module argument .*custom.* in .*import-custom-arg.nix.*:' "$@" 384REQUIRE_INFINITE_RECURSION_HINT=1 checkConfigError 'infinite recursion encountered' "$@" 385 386# Check _module.check. 387set -- config.enable ./declare-enable.nix ./define-enable.nix ./define-attrsOfSub-foo.nix 388checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*' "$@" 389checkConfigOutput '^true$' "$@" ./define-module-check.nix 390 391# Check coerced value. 392set -- 393checkConfigOutput '^"42"$' config.value ./declare-coerced-value.nix 394checkConfigOutput '^"24"$' config.value ./declare-coerced-value.nix ./define-value-string.nix 395checkConfigError 'A definition for option .*. is not of type .*.\n\s*- In .*: \[ \]' config.value ./declare-coerced-value.nix ./define-value-list.nix 396 397# Check coerced option merging. 398checkConfigError 'The option .value. in .*/declare-coerced-value.nix. is already declared in .*/declare-coerced-value-no-default.nix.' config.value ./declare-coerced-value.nix ./declare-coerced-value-no-default.nix 399 400# Check coerced value with unsound coercion 401checkConfigOutput '^12$' config.value ./declare-coerced-value-unsound.nix 402checkConfigError 'A definition for option .* is not of type .*.\n\s*- In .*: "1000"' config.value ./declare-coerced-value-unsound.nix ./define-value-string-bigint.nix 403checkConfigError 'toInt: Could not convert .* to int' config.value ./declare-coerced-value-unsound.nix ./define-value-string-arbitrary.nix 404 405# Check `graph` attribute 406checkExpression './graph/test.nix' 407 408# Check mkAliasOptionModule. 409checkConfigOutput '^true$' config.enable ./alias-with-priority.nix 410checkConfigOutput '^true$' config.enableAlias ./alias-with-priority.nix 411checkConfigOutput '^false$' config.enable ./alias-with-priority-can-override.nix 412checkConfigOutput '^false$' config.enableAlias ./alias-with-priority-can-override.nix 413 414# Check mkPackageOption 415checkConfigOutput '^"hello"$' config.package.pname ./declare-mkPackageOption.nix 416checkConfigOutput '^"hello"$' config.namedPackage.pname ./declare-mkPackageOption.nix 417checkConfigOutput '^".*Hello.*"$' options.namedPackage.description ./declare-mkPackageOption.nix 418checkConfigOutput '^"literalExpression"$' options.namedPackage.defaultText._type ./declare-mkPackageOption.nix 419checkConfigOutput '^"pkgs\.hello"$' options.namedPackage.defaultText.text ./declare-mkPackageOption.nix 420checkConfigOutput '^"hello"$' config.namedPackageSingletonDefault.pname ./declare-mkPackageOption.nix 421checkConfigOutput '^".*Hello.*"$' options.namedPackageSingletonDefault.description ./declare-mkPackageOption.nix 422checkConfigOutput '^"pkgs\.hello"$' options.namedPackageSingletonDefault.defaultText.text ./declare-mkPackageOption.nix 423checkConfigOutput '^"hello"$' config.pathPackage.pname ./declare-mkPackageOption.nix 424checkConfigOutput '^"literalExpression"$' options.packageWithExample.example._type ./declare-mkPackageOption.nix 425checkConfigOutput '^"pkgs\.hello\.override \{ stdenv = pkgs\.clangStdenv; \}"$' options.packageWithExample.example.text ./declare-mkPackageOption.nix 426checkConfigOutput '^"literalExpression"$' options.packageWithPathExample.example._type ./declare-mkPackageOption.nix 427checkConfigOutput '^"pkgs\.hello"$' options.packageWithPathExample.example.text ./declare-mkPackageOption.nix 428checkConfigOutput '^".*Example extra description\..*"$' options.packageWithExtraDescription.description ./declare-mkPackageOption.nix 429checkConfigError 'The option .undefinedPackage. was accessed but has no value defined. Try setting the option.' config.undefinedPackage ./declare-mkPackageOption.nix 430checkConfigOutput '^null$' config.nullablePackage ./declare-mkPackageOption.nix 431checkConfigOutput '^"null or package"$' options.nullablePackage.type.description ./declare-mkPackageOption.nix 432checkConfigOutput '^"hello"$' config.nullablePackageWithDefault.pname ./declare-mkPackageOption.nix 433checkConfigOutput '^"myPkgs\.hello"$' options.packageWithPkgsText.defaultText.text ./declare-mkPackageOption.nix 434checkConfigOutput '^"hello-other"$' options.packageFromOtherSet.default.pname ./declare-mkPackageOption.nix 435checkConfigOutput '^"hello"$' config.packageInvalidIdentifier.pname ./declare-mkPackageOption.nix 436checkConfigOutput '^"pkgs\.\\"123\\"\.\\"with\\\\\\"quote\\"\.hello"$' options.packageInvalidIdentifier.defaultText.text ./declare-mkPackageOption.nix 437checkConfigOutput '^"pkgs\.\\"123\\"\.\\"with\\\\\\"quote\\"\.hello"$' options.packageInvalidIdentifierExample.example.text ./declare-mkPackageOption.nix 438 439# submoduleWith 440 441## specialArgs should work 442checkConfigOutput '^"foo"$' config.submodule.foo ./declare-submoduleWith-special.nix 443 444## shorthandOnlyDefines config behaves as expected 445checkConfigOutput '^true$' config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-shorthand.nix 446checkConfigError 'is not of type `boolean' config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-noshorthand.nix 447checkConfigError "In module ..*define-submoduleWith-shorthand.nix., you're trying to define 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 448checkConfigOutput '^true$' config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-noshorthand.nix 449 450## submoduleWith should merge all modules in one swoop 451checkConfigOutput '^true$' config.submodule.inner ./declare-submoduleWith-modules.nix 452checkConfigOutput '^true$' config.submodule.outer ./declare-submoduleWith-modules.nix 453# Should also be able to evaluate the type name (which evaluates freeformType, 454# which evaluates all the modules defined by the type) 455checkConfigOutput '^"submodule"$' options.submodule.type.description ./declare-submoduleWith-modules.nix 456 457## submodules can be declared using (evalModules {...}).type 458checkConfigOutput '^true$' config.submodule.inner ./declare-submodule-via-evalModules.nix 459checkConfigOutput '^true$' config.submodule.outer ./declare-submodule-via-evalModules.nix 460# Should also be able to evaluate the type name (which evaluates freeformType, 461# which evaluates all the modules defined by the type) 462checkConfigOutput '^"submodule"$' options.submodule.type.description ./declare-submodule-via-evalModules.nix 463 464## Paths should be allowed as values and work as expected 465checkConfigOutput '^true$' config.submodule.enable ./declare-submoduleWith-path.nix 466 467## _prefix module argument is available at import time and contains the prefix 468checkConfigOutput '^true$' config.foo.ok ./prefix-module-argument.nix 469 470## deferredModule 471# default module is merged into nodes.foo 472checkConfigOutput '"beta"' config.nodes.foo.settingsDict.c ./deferred-module.nix 473# errors from the default module are reported with accurate location 474checkConfigError 'In `the-file-that-contains-the-bad-config.nix, via option default'\'': "bogus"' config.nodes.foo.bottom ./deferred-module.nix 475checkConfigError '.*lib/tests/modules/deferred-module-error.nix, via option deferred [(]:anon-1:anon-1:anon-1[)] does not look like a module.' config.result ./deferred-module-error.nix 476 477# Check the file location information is propagated into submodules 478checkConfigOutput the-file.nix config.submodule.internalFiles.0 ./submoduleFiles.nix 479 480 481# Check that disabledModules works recursively and correctly 482checkConfigOutput '^true$' config.enable ./disable-recursive/main.nix 483checkConfigOutput '^true$' config.enable ./disable-recursive/{main.nix,disable-foo.nix} 484checkConfigOutput '^true$' config.enable ./disable-recursive/{main.nix,disable-bar.nix} 485checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./disable-recursive/{main.nix,disable-foo.nix,disable-bar.nix} 486 487# Check that imports can depend on derivations 488checkConfigOutput '^true$' config.enable ./import-from-store.nix 489 490# Check that configs can be conditional on option existence 491checkConfigOutput '^true$' config.enable ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix 492checkConfigOutput '^360$' config.value ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix 493checkConfigOutput '^7$' config.value ./define-option-dependently.nix ./declare-int-positive-value.nix 494checkConfigOutput '^true$' config.set.enable ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix 495checkConfigOutput '^360$' config.set.value ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix 496checkConfigOutput '^7$' config.set.value ./define-option-dependently-nested.nix ./declare-int-positive-value-nested.nix 497 498# Check attrsOf and lazyAttrsOf. Only lazyAttrsOf should be lazy, and only 499# attrsOf should work with conditional definitions 500# In addition, lazyAttrsOf should honor an options emptyValue 501checkConfigError "is not lazy" config.isLazy ./declare-attrsOf.nix ./attrsOf-lazy-check.nix 502checkConfigOutput '^true$' config.isLazy ./declare-lazyAttrsOf.nix ./attrsOf-lazy-check.nix 503checkConfigOutput '^true$' config.conditionalWorks ./declare-attrsOf.nix ./attrsOf-conditional-check.nix 504checkConfigOutput '^false$' config.conditionalWorks ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix 505checkConfigOutput '^"empty"$' config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix 506 507# Check attrsWith type merging 508checkConfigError 'The option `mergedLazyNonLazy'\'' in `.*'\'' is already declared in `.*'\''\.' options.mergedLazyNonLazy ./lazy-attrsWith.nix 509checkConfigOutput '^11$' config.lazyResult ./lazy-attrsWith.nix 510checkConfigError 'infinite recursion encountered' config.nonLazyResult ./lazy-attrsWith.nix 511 512# AttrsWith placeholder tests 513checkConfigOutput '^"mergedName.<id>.nested"$' config.result ./name-merge-attrsWith-1.nix 514checkConfigError 'The option .mergedName. in .*\.nix. is already declared in .*\.nix' config.mergedName ./name-merge-attrsWith-2.nix 515 516# Test type.functor.wrapped deprecation warning 517# should emit the warning on: 518# - merged types 519# - non-merged types 520# - nestedTypes elemType 521# attrsWith 522ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.attrsWith.type.functor.wrapped ./deprecated-wrapped.nix 523ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedAttrsWith.type.functor.wrapped ./deprecated-wrapped.nix 524 525ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.attrsWith.type.nestedTypes.elemType.functor.wrapped ./deprecated-wrapped.nix 526ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedAttrsWith.type.nestedTypes.elemType.functor.wrapped ./deprecated-wrapped.nix 527# listOf 528ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.listOf.type.functor.wrapped ./deprecated-wrapped.nix 529ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedListOf.type.functor.wrapped ./deprecated-wrapped.nix 530 531ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.listOf.type.nestedTypes.elemType.functor.wrapped ./deprecated-wrapped.nix 532ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedListOf.type.nestedTypes.elemType.functor.wrapped ./deprecated-wrapped.nix 533# unique / uniq 534ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.unique.type.functor.wrapped ./deprecated-wrapped.nix 535ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedUnique.type.functor.wrapped ./deprecated-wrapped.nix 536 537ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.unique.type.nestedTypes.elemType.functor.wrapped ./deprecated-wrapped.nix 538ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedUnique.type.nestedTypes.elemType.functor.wrapped ./deprecated-wrapped.nix 539# nullOr 540ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.nullOr.type.functor.wrapped ./deprecated-wrapped.nix 541ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedNullOr.type.functor.wrapped ./deprecated-wrapped.nix 542 543ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.nullOr.type.nestedTypes.elemType.functor.wrapped ./deprecated-wrapped.nix 544ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedNullOr.type.nestedTypes.elemType.functor.wrapped ./deprecated-wrapped.nix 545# functionTo 546ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.functionTo.type.functor.wrapped ./deprecated-wrapped.nix 547ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedFunctionTo.type.functor.wrapped ./deprecated-wrapped.nix 548 549ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.functionTo.type.nestedTypes.elemType.functor.wrapped ./deprecated-wrapped.nix 550ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedFunctionTo.type.nestedTypes.elemType.functor.wrapped ./deprecated-wrapped.nix 551 552# coercedTo 553# Note: test 'nestedTypes.finalType' and 'nestedTypes.coercedType' 554ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.coercedTo.type.functor.wrapped ./deprecated-wrapped.nix 555ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.coercedTo.type.nestedTypes.finalType.functor.wrapped ./deprecated-wrapped.nix 556ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.coercedTo.type.nestedTypes.coercedType.functor.wrapped ./deprecated-wrapped.nix 557# either 558ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.either.type.functor.wrapped ./deprecated-wrapped.nix 559ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedEither.type.functor.wrapped ./deprecated-wrapped.nix 560 561ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.either.type.nestedTypes.left.functor.wrapped ./deprecated-wrapped.nix 562ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.either.type.nestedTypes.right.functor.wrapped ./deprecated-wrapped.nix 563ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedEither.type.nestedTypes.left.functor.wrapped ./deprecated-wrapped.nix 564ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedEither.type.nestedTypes.right.functor.wrapped ./deprecated-wrapped.nix 565 566# Even with multiple assignments, a type error should be thrown if any of them aren't valid 567checkConfigError 'A definition for option .* is not of type .*' \ 568 config.value ./declare-int-unsigned-value.nix ./define-value-list.nix ./define-value-int-positive.nix 569 570## Freeform modules 571# Assigning without a declared option should work 572checkConfigOutput '^"24"$' config.value ./freeform-attrsOf.nix ./define-value-string.nix 573# Shorthand modules interpret `meta` and `class` as config items 574checkConfigOutput '^true$' options._module.args.value.result ./freeform-attrsOf.nix ./define-freeform-keywords-shorthand.nix 575# No freeform assignments shouldn't make it error 576checkConfigOutput '^{}$' config ./freeform-attrsOf.nix 577# but only if the type matches 578checkConfigError 'A definition for option .* is not of type .*' config.value ./freeform-attrsOf.nix ./define-value-list.nix 579# and properties should be applied 580checkConfigOutput '^"yes"$' config.value ./freeform-attrsOf.nix ./define-value-string-properties.nix 581# Options should still be declarable, and be able to have a type that doesn't match the freeform type 582checkConfigOutput '^false$' config.enable ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix 583checkConfigOutput '^"24"$' config.value ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix 584# and this should work too with nested values 585checkConfigOutput '^false$' config.nest.foo ./freeform-attrsOf.nix ./freeform-nested.nix 586checkConfigOutput '^"bar"$' config.nest.bar ./freeform-attrsOf.nix ./freeform-nested.nix 587# Check whether a declared option can depend on an freeform-typed one 588checkConfigOutput '^null$' config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix 589checkConfigOutput '^"24"$' config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix ./define-value-string.nix 590# Check whether an freeform-typed value can depend on a declared option, this can only work with lazyAttrsOf 591REQUIRE_INFINITE_RECURSION_HINT=1 checkConfigError 'infinite recursion encountered' config.foo ./freeform-attrsOf.nix ./freeform-unstr-dep-str.nix 592checkConfigError 'The option .* was accessed but has no value defined. Try setting the option.' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix 593checkConfigOutput '^"24"$' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix ./define-value-string.nix 594# submodules in freeformTypes should have their locations annotated 595checkConfigOutput '/freeform-submodules.nix"$' config.fooDeclarations.0 ./freeform-submodules.nix 596# freeformTypes can get merged using `types.type`, including submodules 597checkConfigOutput '^10$' config.free.xxx.foo ./freeform-submodules.nix 598checkConfigOutput '^10$' config.free.yyy.bar ./freeform-submodules.nix 599 600# Regression of either, due to freeform not beeing checked previously 601checkConfigOutput '^"foo"$' config.either.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix 602ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.either.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix 603checkConfigOutput '^"foo"$' config.eitherBehindNullor.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix 604ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.eitherBehindNullor.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix 605checkConfigOutput '^"foo"$' config.oneOf.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix 606ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.oneOf.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix 607checkConfigOutput '^"foo"$' config.number.str ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix 608ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.number.str ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong.nix 609 610checkConfigOutput '^42$' config.either.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix 611ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.either.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix 612checkConfigOutput '^42$' config.eitherBehindNullor.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix 613ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.eitherBehindNullor.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix 614checkConfigOutput '^42$' config.oneOf.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix 615ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.oneOf.int ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix 616checkConfigOutput '^42$' config.number.str ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix 617ABORT_ON_WARN=1 checkConfigError "One or more definitions did not pass the type-check of the \'either\' type" config.number.str ./freeform-deprecated-malicous.nix ./freeform-deprecated-malicous-wrong2.nix 618# Value OK: Fail if a warning is emitted 619ABORT_ON_WARN=1 checkConfigOutput "^42$" config.number.int ./freeform-attrsof-either.nix 620 621 622## types.anything 623# Check that attribute sets are merged recursively 624checkConfigOutput '^null$' config.value.foo ./types-anything/nested-attrs.nix 625checkConfigOutput '^null$' config.value.l1.foo ./types-anything/nested-attrs.nix 626checkConfigOutput '^null$' config.value.l1.l2.foo ./types-anything/nested-attrs.nix 627checkConfigOutput '^null$' config.value.l1.l2.l3.foo ./types-anything/nested-attrs.nix 628# Attribute sets that are coercible to strings shouldn't be recursed into 629checkConfigOutput '^"foo"$' config.value.outPath ./types-anything/attrs-coercible.nix 630# Multiple lists aren't concatenated together if their definitions are not equal 631checkConfigError 'The option .* has conflicting definition values' config.value ./types-anything/lists.nix 632# Check that all equalizable atoms can be used as long as all definitions are equal 633checkConfigOutput '^0$' config.value.int ./types-anything/equal-atoms.nix 634checkConfigOutput '^false$' config.value.bool ./types-anything/equal-atoms.nix 635checkConfigOutput '^""$' config.value.string ./types-anything/equal-atoms.nix 636checkConfigOutput '^"/[^"]+"$' config.value.path ./types-anything/equal-atoms.nix 637checkConfigOutput '^null$' config.value.null ./types-anything/equal-atoms.nix 638checkConfigOutput '^0.1$' config.value.float ./types-anything/equal-atoms.nix 639checkConfigOutput '^\[1,"a",{"x":null}\]$' config.value.list ./types-anything/equal-atoms.nix 640# Functions can't be merged together 641checkConfigError "The option .value.multiple-lambdas.<function body>. has conflicting option types" config.applied.multiple-lambdas ./types-anything/functions.nix 642checkConfigOutput '^true$' config.valueIsFunction.single-lambda ./types-anything/functions.nix 643checkConfigOutput '^null$' config.applied.merging-lambdas.x ./types-anything/functions.nix 644checkConfigOutput '^null$' config.applied.merging-lambdas.y ./types-anything/functions.nix 645# Check that all mk* modifiers are applied 646checkConfigError 'attribute .* not found' config.value.mkiffalse ./types-anything/mk-mods.nix 647checkConfigOutput '^{}$' config.value.mkiftrue ./types-anything/mk-mods.nix 648checkConfigOutput '^1$' config.value.mkdefault ./types-anything/mk-mods.nix 649checkConfigOutput '^{}$' config.value.mkmerge ./types-anything/mk-mods.nix 650checkConfigOutput '^true$' config.value.mkbefore ./types-anything/mk-mods.nix 651checkConfigOutput '^1$' config.value.nested.foo ./types-anything/mk-mods.nix 652checkConfigOutput '^"baz"$' config.value.nested.bar.baz ./types-anything/mk-mods.nix 653 654## types.functionTo 655checkConfigOutput '^"input is input"$' config.result ./functionTo/trivial.nix 656checkConfigOutput '^"a b"$' config.result ./functionTo/merging-list.nix 657checkConfigError '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 658checkConfigOutput '^"b a"$' config.result ./functionTo/list-order.nix 659checkConfigOutput '^"a c"$' config.result ./functionTo/merging-attrs.nix 660checkConfigOutput '^"a bee"$' config.result ./functionTo/submodule-options.nix 661checkConfigOutput '^"fun.<function body>.a fun.<function body>.b"$' config.optionsResult ./functionTo/submodule-options.nix 662 663# moduleType 664checkConfigOutput '^"a b"$' config.resultFoo ./declare-variants.nix ./define-variant.nix 665checkConfigOutput '^"a b y z"$' config.resultFooBar ./declare-variants.nix ./define-variant.nix 666checkConfigOutput '^"a b c"$' config.resultFooFoo ./declare-variants.nix ./define-variant.nix 667 668## emptyValue's 669checkConfigOutput "\[\]" config.list.a ./emptyValues.nix 670checkConfigOutput "{}" config.attrs.a ./emptyValues.nix 671checkConfigOutput "null" config.null.a ./emptyValues.nix 672checkConfigOutput "{}" config.submodule.a ./emptyValues.nix 673# These types don't have empty values 674checkConfigError 'The option .int.a. was accessed but has no value defined. Try setting the option.' config.int.a ./emptyValues.nix 675checkConfigError 'The option .nonEmptyList.a. was accessed but has no value defined. Try setting the option.' config.nonEmptyList.a ./emptyValues.nix 676 677# types.unique 678# requires a single definition 679checkConfigError 'The option .examples\.merged. is defined multiple times while it.s expected to be unique' config.examples.merged.a ./types-unique.nix 680# user message is printed 681checkConfigError 'We require a single definition, because seeing the whole value at once helps us maintain critical invariants of our system.' config.examples.merged.a ./types-unique.nix 682# let the inner merge function check the values (on demand) 683checkConfigError 'A definition for option .examples\.badLazyType\.a. is not of type .string.' config.examples.badLazyType.a ./types-unique.nix 684# overriding still works (unlike option uniqueness) 685checkConfigOutput '^"bee"$' config.examples.override.b ./types-unique.nix 686 687## types.raw 688checkConfigOutput '^true$' config.unprocessedNestingEvaluates.success ./raw.nix 689checkConfigOutput "10" config.processedToplevel ./raw.nix 690checkConfigError "The option .multiple. is defined multiple times" config.multiple ./raw.nix 691checkConfigOutput "bar" config.priorities ./raw.nix 692 693## Option collision 694checkConfigError \ 695 'The option .set. in module .*/declare-set.nix. would be a parent of the following options, but its type .attribute set of signed integer. does not support nested options.\n\s*- option[(]s[)] with prefix .set.enable. in module .*/declare-enable-nested.nix.' \ 696 config.set \ 697 ./declare-set.nix ./declare-enable-nested.nix 698 699# Options: accidental use of an option-type instead of option (or other tagged type; unlikely) 700checkConfigError 'In module .*/options-type-error-typical.nix: expected an option declaration at option path .result. but got an attribute set with type option-type' config.result ./options-type-error-typical.nix 701checkConfigError 'In module .*/options-type-error-typical-nested.nix: expected an option declaration at option path .result.here. but got an attribute set with type option-type' config.result.here ./options-type-error-typical-nested.nix 702checkConfigError 'In module .*/options-type-error-configuration.nix: expected an option declaration at option path .result. but got an attribute set with type configuration' config.result ./options-type-error-configuration.nix 703 704# Check that that merging of option collisions doesn't depend on type being set 705checkConfigError 'The option .group..*would be a parent of the following options, but its type .<no description>. does not support nested options.\n\s*- option.s. with prefix .group.enable..*' config.group.enable ./merge-typeless-option.nix 706 707# Test that types.optionType merges types correctly 708checkConfigOutput '^10$' config.theOption.int ./optionTypeMerging.nix 709checkConfigOutput '^"hello"$' config.theOption.str ./optionTypeMerging.nix 710 711# Test that types.optionType correctly annotates option locations 712checkConfigError 'The option .theOption.nested. in .other.nix. is already declared in .optionTypeFile.nix.' config.theOption.nested ./optionTypeFile.nix 713 714# Test that types.optionType leaves types untouched as long as they don't need to be merged 715checkConfigOutput 'ok' config.freeformItems.foo.bar ./adhoc-freeformType-survives-type-merge.nix 716 717# Test that specifying both functor.wrapped and functor.payload isn't allowed 718checkConfigError 'Type foo defines both `functor.payload` and `functor.wrapped` at the same time, which is not supported.' config.result ./default-type-merge-both.nix 719 720 721# Anonymous submodules don't get nixed by import resolution/deduplication 722# because of an `extendModules` bug, issue 168767. 723checkConfigOutput '^1$' config.sub.specialisation.value ./extendModules-168767-imports.nix 724 725# Class checks, evalModules 726checkConfigOutput '^{}$' config.ok.config ./class-check.nix 727checkConfigOutput '"nixos"' config.ok.class ./class-check.nix 728checkConfigError 'The module `.*/module-class-is-darwin.nix`.*?expects class "nixos".' config.fail.config ./class-check.nix 729checkConfigError 'The module `foo.nix#darwinModules.default`.*?expects class "nixos".' config.fail-anon.config ./class-check.nix 730 731# Class checks, submoduleWith 732checkConfigOutput '^{}$' config.sub.nixosOk ./class-check.nix 733checkConfigError 'The module `.*/module-class-is-darwin.nix`.*?expects class "nixos".' config.sub.nixosFail.config ./class-check.nix 734 735# submoduleWith type merge with different class 736checkConfigError 'A submoduleWith option is declared multiple times with conflicting class values "darwin" and "nixos".' config.sub.mergeFail.config ./class-check.nix 737 738# _type check 739checkConfigError 'Expected a module, but found a value of type .*"flake".*, while trying to load a module into .*/module-imports-_type-check.nix' config.ok.config ./module-imports-_type-check.nix 740checkConfigOutput '^true$' config.enable ./declare-enable.nix ./define-enable-with-top-level-mkIf.nix 741checkConfigError 'Expected a module, but found a value of type .*"configuration".*, while trying to load a module into .*/import-configuration.nix.' config ./import-configuration.nix 742checkConfigError 'please only import the modules that make up the configuration' config ./import-configuration.nix 743checkConfigError 'Expected a module, but found a value of type "configuration", while trying to load a module into .*/import-error-submodule.nix, while trying to load a module into .*foo.*\.' config.foo ./import-error-submodule.nix 744 745# doRename works when `warnings` does not exist. 746checkConfigOutput '^1234$' config.c.d.e ./doRename-basic.nix 747# doRename adds a warning. 748checkConfigOutput '^"The option `a\.b. defined in `.*/doRename-warnings\.nix. has been renamed to `c\.d\.e.\."$' \ 749 config.result \ 750 ./doRename-warnings.nix 751checkConfigOutput "^true$" config.result ./doRename-condition.nix ./doRename-condition-enable.nix 752checkConfigOutput "^true$" config.result ./doRename-condition.nix ./doRename-condition-no-enable.nix 753checkConfigOutput "^true$" config.result ./doRename-condition.nix ./doRename-condition-migrated.nix 754 755# Anonymous modules get deduplicated by key 756checkConfigOutput '^"pear"$' config.once.raw ./merge-module-with-key.nix 757checkConfigOutput '^"pear\\npear"$' config.twice.raw ./merge-module-with-key.nix 758 759# Declaration positions 760# Line should be present for direct options 761checkConfigOutput '^14$' options.imported.line14.declarationPositions.0.line ./declaration-positions.nix 762checkConfigOutput '/declaration-positions.nix"$' options.imported.line14.declarationPositions.0.file ./declaration-positions.nix 763# Generated options may not have line numbers but they will at least get the 764# right file 765checkConfigOutput '/declaration-positions.nix"$' options.generated.line22.declarationPositions.0.file ./declaration-positions.nix 766checkConfigOutput '^null$' options.generated.line22.declarationPositions.0.line ./declaration-positions.nix 767# Submodules don't break it 768checkConfigOutput '^45$' config.submoduleLine38.submodDeclLine45.0.line ./declaration-positions.nix 769checkConfigOutput '/declaration-positions.nix"$' config.submoduleLine38.submodDeclLine45.0.file ./declaration-positions.nix 770# New options under freeform submodules get collected into the parent submodule 771# (consistent with .declarations behaviour, but weird; notably appears in system.build) 772checkConfigOutput '^38|27$' options.submoduleLine38.declarationPositions.0.line ./declaration-positions.nix 773checkConfigOutput '^38|27$' options.submoduleLine38.declarationPositions.1.line ./declaration-positions.nix 774# nested options work 775checkConfigOutput '^34$' options.nested.nestedLine34.declarationPositions.0.line ./declaration-positions.nix 776 777# types.pathWith { inStore = true; } 778checkConfigOutput '".*/store/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv"' config.pathInStore.ok1 ./pathWith.nix 779checkConfigOutput '".*/store/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15"' config.pathInStore.ok2 ./pathWith.nix 780checkConfigOutput '".*/store/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15/bin/bash"' config.pathInStore.ok3 ./pathWith.nix 781checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ""' config.pathInStore.bad1 ./pathWith.nix 782checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store"' config.pathInStore.bad2 ./pathWith.nix 783checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store/"' config.pathInStore.bad3 ./pathWith.nix 784checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store/.links"' config.pathInStore.bad4 ./pathWith.nix 785checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: "/foo/bar"' config.pathInStore.bad5 ./pathWith.nix 786 787# types.pathWith { inStore = false; } 788checkConfigOutput '"/foo/bar"' config.pathNotInStore.ok1 ./pathWith.nix 789checkConfigOutput '".*/store"' config.pathNotInStore.ok2 ./pathWith.nix 790checkConfigOutput '".*/store/"' config.pathNotInStore.ok3 ./pathWith.nix 791checkConfigOutput '""' config.pathNotInStore.ok4 ./pathWith.nix 792checkConfigOutput '".*/store/.links"' config.pathNotInStore.ok5 ./pathWith.nix 793checkConfigError 'A definition for option .* is not of type .path not in the Nix store.. Definition values:\n\s*- In .*: ".*/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv"' config.pathNotInStore.bad1 ./pathWith.nix 794checkConfigError 'A definition for option .* is not of type .path not in the Nix store.. Definition values:\n\s*- In .*: ".*/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15"' config.pathNotInStore.bad2 ./pathWith.nix 795checkConfigError 'A definition for option .* is not of type .path not in the Nix store.. Definition values:\n\s*- In .*: ".*/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15/bin/bash"' config.pathNotInStore.bad3 ./pathWith.nix 796checkConfigError 'A definition for option .* is not of type .path not in the Nix store.. Definition values:\n\s*- In .*: .*/pathWith.nix' config.pathNotInStore.bad4 ./pathWith.nix 797 798# types.pathWith { } 799checkConfigOutput '"/this/is/absolute"' config.anyPath.ok1 ./pathWith.nix 800checkConfigOutput '"./this/is/relative"' config.anyPath.ok2 ./pathWith.nix 801checkConfigError 'A definition for option .anyPath.bad1. is not of type .path.' config.anyPath.bad1 ./pathWith.nix 802 803# types.pathWith { absolute = true; } 804checkConfigOutput '"/this/is/absolute"' config.absolutePathNotInStore.ok1 ./pathWith.nix 805checkConfigError 'A definition for option .absolutePathNotInStore.bad1. is not of type .absolute path not in the Nix store.' config.absolutePathNotInStore.bad1 ./pathWith.nix 806checkConfigError 'A definition for option .absolutePathNotInStore.bad2. is not of type .absolute path not in the Nix store.' config.absolutePathNotInStore.bad2 ./pathWith.nix 807 808# types.pathWith failed type merge 809checkConfigError 'The option .conflictingPathOptionType. in .*/pathWith.nix. is already declared in .*/pathWith.nix' config.conflictingPathOptionType ./pathWith.nix 810 811# types.pathWith { inStore = true; absolute = false; } 812checkConfigError 'In pathWith, inStore means the path must be absolute' config.impossiblePathOptionType ./pathWith.nix 813 814# mkDefinition 815# check that mkDefinition 'file' is printed in the error message 816checkConfigError 'Cannot merge definitions.*\n\s*- In .file.*\n\s*- In .other.*' config.conflict ./mkDefinition.nix 817checkConfigError 'A definition for option .viaOptionDefault. is not of type .boolean.*' config.viaOptionDefault ./mkDefinition.nix 818checkConfigOutput '^true$' config.viaConfig ./mkDefinition.nix 819checkConfigOutput '^true$' config.mkMerge ./mkDefinition.nix 820checkConfigOutput '^true$' config.mkForce ./mkDefinition.nix 821 822# specialArgs._class 823checkConfigOutput '"nixos"' config.nixos.config.foo ./specialArgs-class.nix 824checkConfigOutput '"bar"' config.conditionalImportAsNixos.config.foo ./specialArgs-class.nix 825checkConfigError 'attribute .*bar.* not found' config.conditionalImportAsNixos.config.bar ./specialArgs-class.nix 826checkConfigError 'attribute .*foo.* not found' config.conditionalImportAsDarwin.config.foo ./specialArgs-class.nix 827checkConfigOutput '"foo"' config.conditionalImportAsDarwin.config.bar ./specialArgs-class.nix 828checkConfigOutput '"nixos"' config.sub.nixos.foo ./specialArgs-class.nix 829checkConfigOutput '"bar"' config.sub.conditionalImportAsNixos.foo ./specialArgs-class.nix 830checkConfigError 'attribute .*bar.* not found' config.sub.conditionalImportAsNixos.bar ./specialArgs-class.nix 831checkConfigError 'attribute .*foo.* not found' config.sub.conditionalImportAsDarwin.foo ./specialArgs-class.nix 832checkConfigOutput '"foo"' config.sub.conditionalImportAsDarwin.bar ./specialArgs-class.nix 833# Check that some types expose the 'valueMeta' 834checkConfigOutput '\{\}' options.str.valueMeta ./types-valueMeta.nix 835checkConfigOutput '["foo", "bar"]' config.attrsOfResult ./types-valueMeta.nix 836checkConfigOutput '2' config.listOfResult ./types-valueMeta.nix 837 838# Check that composed types expose the 'valueMeta' 839# attrsOf submodule (also on merged options,types) 840checkConfigOutput '42' options.attrsOfModule.valueMeta.attrs.foo.configuration.options.bar.value ./composed-types-valueMeta.nix 841checkConfigOutput '42' options.mergedAttrsOfModule.valueMeta.attrs.foo.configuration.options.bar.value ./composed-types-valueMeta.nix 842 843# listOf submodule (also on merged options,types) 844checkConfigOutput '42' config.listResult ./composed-types-valueMeta.nix 845checkConfigOutput '42' config.mergedListResult ./composed-types-valueMeta.nix 846 847# Add check 848checkConfigOutput '^0$' config.v1CheckedPass ./add-check.nix 849checkConfigError 'A definition for option .* is not of type .signed integer.*' config.v1CheckedFail ./add-check.nix 850checkConfigOutput '^true$' config.v2checkedPass ./add-check.nix 851checkConfigError 'A definition for option .* is not of type .attribute set of signed integer.*' config.v2checkedFail ./add-check.nix 852 853# v2 merge check coherence 854# Tests checkV2MergeCoherence call in modules.nix (mergeDefinitions for lazyAttrsOf) 855checkConfigError 'ad-hoc.*override.*incompatible' config.adhocFail.foo ./v2-check-coherence.nix 856# Tests checkV2MergeCoherence call in modules.nix (mergeDefinitions for lazyAttrsOf) 857checkConfigError 'ad-hoc.*override.*incompatible' config.adhocOuterFail.bar ./v2-check-coherence.nix 858# Tests checkV2MergeCoherence call in types.nix (either t1) 859checkConfigError 'ad-hoc.*override.*incompatible' config.eitherLeftFail ./v2-check-coherence.nix 860# Tests checkV2MergeCoherence call in types.nix (either t2) 861checkConfigError 'ad-hoc.*override.*incompatible' config.eitherRightFail ./v2-check-coherence.nix 862# Tests checkV2MergeCoherence call in types.nix (coercedTo coercedType) 863checkConfigError 'ad-hoc.*override.*incompatible' config.coercedFromFail.bar ./v2-check-coherence.nix 864# Tests checkV2MergeCoherence call in types.nix (coercedTo finalType) 865checkConfigError 'ad-hoc.*override.*incompatible' config.coercedToFail.foo ./v2-check-coherence.nix 866# Tests checkV2MergeCoherence call in types.nix (addCheck elemType) 867checkConfigError 'ad-hoc.*override.*incompatible' config.addCheckNested.foo ./v2-check-coherence.nix 868checkConfigError 'Please use.*lib.types.addCheck.*instead' config.adhocFail.foo ./v2-check-coherence.nix 869checkConfigError 'A definition for option .* is not of type .*' config.addCheckFail.bar.baz ./v2-check-coherence.nix 870checkConfigOutput '^true$' config.result ./v2-check-coherence.nix 871 872 873# Option name suggestions 874checkConfigError 'Did you mean .set\.enable.\?' config.set ./error-typo-nested.nix 875checkConfigError 'Did you mean .set.\?' config ./error-typo-outside-with-nested.nix 876checkConfigError 'Did you mean .bar., .baz. or .foo.\?' config ./error-typo-multiple-suggestions.nix 877checkConfigError 'Did you mean .enable., .ebe. or .enabled.\?' config ./error-typo-large-attrset.nix 878checkConfigError 'Did you mean .services\.myservice\.port. or .services\.myservice\.enable.\?' config.services.myservice ./error-typo-submodule.nix 879checkConfigError 'Did you mean .services\.nginx\.virtualHosts\."example\.com"\.ssl\.certificate. or .services\.nginx\.virtualHosts\."example\.com"\.ssl\.certificateKey.\?' config.services.nginx.virtualHosts.\"example.com\" ./error-typo-deeply-nested.nix 880 881cat <<EOF 882====== module tests ====== 883$pass Pass 884$fail Fail 885EOF 886 887if [ "$fail" -ne 0 ]; then 888 exit 1 889fi 890exit 0