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
23# loc
24# prints the location of the call of to the function that calls it
25# loc n
26# prints the location n levels up the call stack
27loc() {
28 local caller depth
29 depth=1
30 if [[ $# -gt 0 ]]; then
31 depth=$1
32 fi
33 # ( lineno fnname file ) of the caller
34 caller=( $(caller $depth) )
35 echo "${caller[2]}:${caller[0]}"
36}
37
38line() {
39 echo "----------------------------------------"
40}
41logStartFailure() {
42 line
43}
44logEndFailure() {
45 line
46 echo
47}
48
49logFailure() {
50 # bold red
51 printf '\033[1;31mTEST FAILED\033[0m at %s\n' "$(loc 2)"
52}
53
54evalConfig() {
55 local attr=$1
56 shift
57 local script="import ./default.nix { modules = [ $* ];}"
58 nix-instantiate --timeout 1 -E "$script" -A "$attr" --eval-only --show-trace --read-write-mode --json
59}
60
61reportFailure() {
62 local attr=$1
63 shift
64 local script="import ./default.nix { modules = [ $* ];}"
65 echo "$ nix-instantiate -E '$script' -A '$attr' --eval-only --json"
66 evalConfig "$attr" "$@" || true
67 ((++fail))
68}
69
70checkConfigOutput() {
71 local outputContains=$1
72 shift
73 if evalConfig "$@" 2>/dev/null | grep -E --silent "$outputContains" ; then
74 ((++pass))
75 else
76 logStartFailure
77 echo "ACTUAL:"
78 reportFailure "$@"
79 echo "EXPECTED: result matching '$outputContains'"
80 logFailure
81 logEndFailure
82 fi
83}
84
85checkConfigError() {
86 local errorContains=$1
87 local err=""
88 shift
89 if err="$(evalConfig "$@" 2>&1 >/dev/null)"; then
90 logStartFailure
91 echo "ACTUAL: exit code 0, output:"
92 reportFailure "$@"
93 echo "EXPECTED: non-zero exit code"
94 logFailure
95 logEndFailure
96 else
97 if echo "$err" | grep -zP --silent "$errorContains" ; then
98 ((++pass))
99 else
100 logStartFailure
101 echo "ACTUAL:"
102 reportFailure "$@"
103 echo "EXPECTED: error matching '$errorContains'"
104 logFailure
105 logEndFailure
106 fi
107 fi
108}
109
110# Shorthand meta attribute does not duplicate the config
111checkConfigOutput '^"one two"$' config.result ./shorthand-meta.nix
112
113checkConfigOutput '^true$' config.result ./test-mergeAttrDefinitionsWithPrio.nix
114
115# Check that a module argument is passed, also when a default is available
116# (but not needed)
117#
118# When the default is needed, we currently fail to do what the users expect, as
119# we pass our own argument anyway, even if it *turns out* not to exist.
120#
121# The reason for this is that we don't know at invocation time what is in the
122# _module.args option. That value is only available *after* all modules have been
123# invoked.
124#
125# Hypothetically, Nix could help support this by giving access to the default
126# values, through a new built-in function.
127# However the default values are allowed to depend on other arguments, so those
128# would have to be passed in somehow, making this not just a getter but
129# something more complicated.
130#
131# At that point we have to wonder whether the extra complexity is worth the cost.
132# Another - subjective - reason not to support it is that default values
133# contradict the notion that an option has a single value, where _module.args
134# is the option.
135checkConfigOutput '^true$' config.result ./module-argument-default.nix
136
137# gvariant
138checkConfigOutput '^true$' config.assertion ./gvariant.nix
139
140checkConfigOutput '"ok"' config.result ./specialArgs-lib.nix
141
142# https://github.com/NixOS/nixpkgs/pull/131205
143# We currently throw this error already in `config`, but throwing in `config.wrong1` would be acceptable.
144checkConfigError '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
145# We currently throw this error already in `config`, but throwing in `config.nest.wrong2` would be acceptable.
146checkConfigError '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
147checkConfigError 'The option .sub.wrong2. does not exist. Definition values:' config.sub ./error-mkOption-in-submodule-config.nix
148checkConfigError '.*This can happen if you e.g. declared your options in .types.submodule.' config.sub ./error-mkOption-in-submodule-config.nix
149checkConfigError '.*A definition for option .bad. is not of type .non-empty .list of .submodule...\.' config.bad ./error-nonEmptyListOf-submodule.nix
150
151# types.attrTag
152checkConfigOutput '^true$' config.okChecks ./types-attrTag.nix
153checkConfigError 'A definition for option .intStrings\.syntaxError. is not of type .attribute-tagged union' config.intStrings.syntaxError ./types-attrTag.nix
154checkConfigError 'A definition for option .intStrings\.syntaxError2. is not of type .attribute-tagged union' config.intStrings.syntaxError2 ./types-attrTag.nix
155checkConfigError 'A definition for option .intStrings\.syntaxError3. is not of type .attribute-tagged union' config.intStrings.syntaxError3 ./types-attrTag.nix
156checkConfigError 'A definition for option .intStrings\.syntaxError4. is not of type .attribute-tagged union' config.intStrings.syntaxError4 ./types-attrTag.nix
157checkConfigError 'A definition for option .intStrings\.mergeError. is not of type .attribute-tagged union' config.intStrings.mergeError ./types-attrTag.nix
158checkConfigError 'A definition for option .intStrings\.badTagError. is not of type .attribute-tagged union' config.intStrings.badTagError ./types-attrTag.nix
159checkConfigError 'A definition for option .intStrings\.badTagTypeError\.left. is not of type .signed integer.' config.intStrings.badTagTypeError.left ./types-attrTag.nix
160checkConfigError 'A definition for option .nested\.right\.left. is not of type .signed integer.' config.nested.right.left ./types-attrTag.nix
161checkConfigError '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
162
163# types.pathInStore
164checkConfigOutput '".*/store/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv"' config.pathInStore.ok1 ./types.nix
165checkConfigOutput '".*/store/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15"' config.pathInStore.ok2 ./types.nix
166checkConfigOutput '".*/store/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15/bin/bash"' config.pathInStore.ok3 ./types.nix
167checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ""' config.pathInStore.bad1 ./types.nix
168checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store"' config.pathInStore.bad2 ./types.nix
169checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store/"' config.pathInStore.bad3 ./types.nix
170checkConfigError '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
171checkConfigError '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
172
173# Check boolean option.
174checkConfigOutput '^false$' config.enable ./declare-enable.nix
175checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./define-enable.nix
176checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*' config.enable ./define-enable-throw.nix
177checkConfigError 'while evaluating a definition from `.*/define-enable-abort.nix' config.enable ./define-enable-abort.nix
178checkConfigError 'while evaluating the error message for definitions for .enable., which is an option that does not exist' config.enable ./define-enable-abort.nix
179
180# Check boolByOr type.
181checkConfigOutput '^false$' config.value.falseFalse ./boolByOr.nix
182checkConfigOutput '^true$' config.value.trueFalse ./boolByOr.nix
183checkConfigOutput '^true$' config.value.falseTrue ./boolByOr.nix
184checkConfigOutput '^true$' config.value.trueTrue ./boolByOr.nix
185
186checkConfigOutput '^1$' config.bare-submodule.nested ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix
187checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix
188checkConfigOutput '^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
189checkConfigOutput '^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
190checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix ./define-shorthandOnlyDefinesConfig-true.nix
191checkConfigError '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
192
193# Check that strMatching can be merged
194checkConfigOutput '^"strMatching.*"$' options.sm.type.name ./strMatching-merge.nix
195
196# Check integer types.
197# unsigned
198checkConfigOutput '^42$' config.value ./declare-int-unsigned-value.nix ./define-value-int-positive.nix
199checkConfigError '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
200# positive
201checkConfigError '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
202# between
203checkConfigOutput '^42$' config.value ./declare-int-between-value.nix ./define-value-int-positive.nix
204checkConfigError '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
205
206# Check either types
207# types.either
208checkConfigOutput '^42$' config.value ./declare-either.nix ./define-value-int-positive.nix
209checkConfigOutput '^"24"$' config.value ./declare-either.nix ./define-value-string.nix
210# types.oneOf
211checkConfigOutput '^42$' config.value ./declare-oneOf.nix ./define-value-int-positive.nix
212checkConfigOutput '^\[\]$' config.value ./declare-oneOf.nix ./define-value-list.nix
213checkConfigOutput '^"24"$' config.value ./declare-oneOf.nix ./define-value-string.nix
214
215# Check mkForce without submodules.
216set -- config.enable ./declare-enable.nix ./define-enable.nix
217checkConfigOutput '^true$' "$@"
218checkConfigOutput '^false$' "$@" ./define-force-enable.nix
219checkConfigOutput '^false$' "$@" ./define-enable-force.nix
220
221# Check mkForce with option and submodules.
222checkConfigError 'attribute .*foo.* .* not found' config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix
223checkConfigOutput '^false$' config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix
224set -- config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo-enable.nix
225checkConfigOutput '^true$' "$@"
226checkConfigOutput '^false$' "$@" ./define-force-attrsOfSub-foo-enable.nix
227checkConfigOutput '^false$' "$@" ./define-attrsOfSub-force-foo-enable.nix
228checkConfigOutput '^false$' "$@" ./define-attrsOfSub-foo-force-enable.nix
229checkConfigOutput '^false$' "$@" ./define-attrsOfSub-foo-enable-force.nix
230
231# Check overriding effect of mkForce on submodule definitions.
232checkConfigError 'attribute .*bar.* .* not found' config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix
233checkConfigOutput '^false$' config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix ./define-attrsOfSub-bar.nix
234set -- config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix ./define-attrsOfSub-bar-enable.nix
235checkConfigOutput '^true$' "$@"
236checkConfigError 'attribute .*bar.* .* not found' "$@" ./define-force-attrsOfSub-foo-enable.nix
237checkConfigError 'attribute .*bar.* .* not found' "$@" ./define-attrsOfSub-force-foo-enable.nix
238checkConfigOutput '^true$' "$@" ./define-attrsOfSub-foo-force-enable.nix
239checkConfigOutput '^true$' "$@" ./define-attrsOfSub-foo-enable-force.nix
240
241# Check mkIf with submodules.
242checkConfigError 'attribute .*foo.* .* not found' config.attrsOfSub.foo.enable ./declare-enable.nix ./declare-attrsOfSub-any-enable.nix
243set -- config.attrsOfSub.foo.enable ./declare-enable.nix ./declare-attrsOfSub-any-enable.nix
244checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-if-attrsOfSub-foo-enable.nix
245checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-attrsOfSub-if-foo-enable.nix
246checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-attrsOfSub-foo-if-enable.nix
247checkConfigOutput '^false$' "$@" ./define-attrsOfSub-foo-enable-if.nix
248checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-if-attrsOfSub-foo-enable.nix
249checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-attrsOfSub-if-foo-enable.nix
250checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-attrsOfSub-foo-if-enable.nix
251checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-attrsOfSub-foo-enable-if.nix
252
253# Check importApply
254checkConfigOutput '"abc"' config.value ./importApply.nix
255# importApply does not set a key.
256# Disabling the function file is not sufficient, because importApply can't reasonably assume that the key is unique.
257# e.g. user may call it multiple times with different arguments and expect each of the module to apply.
258# While this is excusable for the disabledModules aspect, it is not for the deduplication of modules.
259checkConfigOutput '"abc"' config.value ./importApply-disabling.nix
260
261# Check disabledModules with config definitions and option declarations.
262set -- config.enable ./define-enable.nix ./declare-enable.nix
263checkConfigOutput '^true$' "$@"
264checkConfigOutput '^false$' "$@" ./disable-define-enable.nix
265checkConfigOutput '^false$' "$@" ./disable-define-enable-string-path.nix
266checkConfigError "The option .*enable.* does not exist. Definition values:\n\s*- In .*: true" "$@" ./disable-declare-enable.nix
267checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-define-enable.nix ./disable-declare-enable.nix
268checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-enable-modules.nix
269
270checkConfigOutput '^true$' 'config.positive.enable' ./disable-module-with-key.nix
271checkConfigOutput '^false$' 'config.negative.enable' ./disable-module-with-key.nix
272checkConfigError '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
273
274# 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.
275checkConfigOutput '^true$' 'config.positive.enable' ./disable-module-with-toString-key.nix
276checkConfigOutput '^false$' 'config.negative.enable' ./disable-module-with-toString-key.nix
277
278# Check _module.args.
279set -- config.enable ./declare-enable.nix ./define-enable-with-custom-arg.nix
280checkConfigError 'while evaluating the module argument .*custom.* in .*define-enable-with-custom-arg.nix.*:' "$@"
281checkConfigOutput '^true$' "$@" ./define-_module-args-custom.nix
282
283# Check that using _module.args on imports cause infinite recursions, with
284# the proper error context.
285set -- "$@" ./define-_module-args-custom.nix ./import-custom-arg.nix
286checkConfigError 'while evaluating the module argument .*custom.* in .*import-custom-arg.nix.*:' "$@"
287checkConfigError 'infinite recursion encountered' "$@"
288
289# Check _module.check.
290set -- config.enable ./declare-enable.nix ./define-enable.nix ./define-attrsOfSub-foo.nix
291checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*' "$@"
292checkConfigOutput '^true$' "$@" ./define-module-check.nix
293
294# Check coerced value.
295set --
296checkConfigOutput '^"42"$' config.value ./declare-coerced-value.nix
297checkConfigOutput '^"24"$' config.value ./declare-coerced-value.nix ./define-value-string.nix
298checkConfigError '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
299
300# Check coerced option merging.
301checkConfigError '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
302
303# Check coerced value with unsound coercion
304checkConfigOutput '^12$' config.value ./declare-coerced-value-unsound.nix
305checkConfigError '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
306checkConfigError 'toInt: Could not convert .* to int' config.value ./declare-coerced-value-unsound.nix ./define-value-string-arbitrary.nix
307
308# Check mkAliasOptionModule.
309checkConfigOutput '^true$' config.enable ./alias-with-priority.nix
310checkConfigOutput '^true$' config.enableAlias ./alias-with-priority.nix
311checkConfigOutput '^false$' config.enable ./alias-with-priority-can-override.nix
312checkConfigOutput '^false$' config.enableAlias ./alias-with-priority-can-override.nix
313
314# Check mkPackageOption
315checkConfigOutput '^"hello"$' config.package.pname ./declare-mkPackageOption.nix
316checkConfigOutput '^"hello"$' config.namedPackage.pname ./declare-mkPackageOption.nix
317checkConfigOutput '^".*Hello.*"$' options.namedPackage.description ./declare-mkPackageOption.nix
318checkConfigOutput '^"literalExpression"$' options.namedPackage.defaultText._type ./declare-mkPackageOption.nix
319checkConfigOutput '^"pkgs\.hello"$' options.namedPackage.defaultText.text ./declare-mkPackageOption.nix
320checkConfigOutput '^"hello"$' config.namedPackageSingletonDefault.pname ./declare-mkPackageOption.nix
321checkConfigOutput '^".*Hello.*"$' options.namedPackageSingletonDefault.description ./declare-mkPackageOption.nix
322checkConfigOutput '^"pkgs\.hello"$' options.namedPackageSingletonDefault.defaultText.text ./declare-mkPackageOption.nix
323checkConfigOutput '^"hello"$' config.pathPackage.pname ./declare-mkPackageOption.nix
324checkConfigOutput '^"literalExpression"$' options.packageWithExample.example._type ./declare-mkPackageOption.nix
325checkConfigOutput '^"pkgs\.hello\.override \{ stdenv = pkgs\.clangStdenv; \}"$' options.packageWithExample.example.text ./declare-mkPackageOption.nix
326checkConfigOutput '^"literalExpression"$' options.packageWithPathExample.example._type ./declare-mkPackageOption.nix
327checkConfigOutput '^"pkgs\.hello"$' options.packageWithPathExample.example.text ./declare-mkPackageOption.nix
328checkConfigOutput '^".*Example extra description\..*"$' options.packageWithExtraDescription.description ./declare-mkPackageOption.nix
329checkConfigError 'The option .undefinedPackage. was accessed but has no value defined. Try setting the option.' config.undefinedPackage ./declare-mkPackageOption.nix
330checkConfigOutput '^null$' config.nullablePackage ./declare-mkPackageOption.nix
331checkConfigOutput '^"null or package"$' options.nullablePackage.type.description ./declare-mkPackageOption.nix
332checkConfigOutput '^"hello"$' config.nullablePackageWithDefault.pname ./declare-mkPackageOption.nix
333checkConfigOutput '^"myPkgs\.hello"$' options.packageWithPkgsText.defaultText.text ./declare-mkPackageOption.nix
334checkConfigOutput '^"hello-other"$' options.packageFromOtherSet.default.pname ./declare-mkPackageOption.nix
335checkConfigOutput '^"hello"$' config.packageInvalidIdentifier.pname ./declare-mkPackageOption.nix
336checkConfigOutput '^"pkgs\.\\"123\\"\.\\"with\\\\\\"quote\\"\.hello"$' options.packageInvalidIdentifier.defaultText.text ./declare-mkPackageOption.nix
337checkConfigOutput '^"pkgs\.\\"123\\"\.\\"with\\\\\\"quote\\"\.hello"$' options.packageInvalidIdentifierExample.example.text ./declare-mkPackageOption.nix
338
339# submoduleWith
340
341## specialArgs should work
342checkConfigOutput '^"foo"$' config.submodule.foo ./declare-submoduleWith-special.nix
343
344## shorthandOnlyDefines config behaves as expected
345checkConfigOutput '^true$' config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-shorthand.nix
346checkConfigError 'is not of type `boolean' config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-noshorthand.nix
347checkConfigError "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
348checkConfigOutput '^true$' config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-noshorthand.nix
349
350## submoduleWith should merge all modules in one swoop
351checkConfigOutput '^true$' config.submodule.inner ./declare-submoduleWith-modules.nix
352checkConfigOutput '^true$' config.submodule.outer ./declare-submoduleWith-modules.nix
353# Should also be able to evaluate the type name (which evaluates freeformType,
354# which evaluates all the modules defined by the type)
355checkConfigOutput '^"submodule"$' options.submodule.type.description ./declare-submoduleWith-modules.nix
356
357## submodules can be declared using (evalModules {...}).type
358checkConfigOutput '^true$' config.submodule.inner ./declare-submodule-via-evalModules.nix
359checkConfigOutput '^true$' config.submodule.outer ./declare-submodule-via-evalModules.nix
360# Should also be able to evaluate the type name (which evaluates freeformType,
361# which evaluates all the modules defined by the type)
362checkConfigOutput '^"submodule"$' options.submodule.type.description ./declare-submodule-via-evalModules.nix
363
364## Paths should be allowed as values and work as expected
365checkConfigOutput '^true$' config.submodule.enable ./declare-submoduleWith-path.nix
366
367## _prefix module argument is available at import time and contains the prefix
368checkConfigOutput '^true$' config.foo.ok ./prefix-module-argument.nix
369
370## deferredModule
371# default module is merged into nodes.foo
372checkConfigOutput '"beta"' config.nodes.foo.settingsDict.c ./deferred-module.nix
373# errors from the default module are reported with accurate location
374checkConfigError 'In `the-file-that-contains-the-bad-config.nix, via option default'\'': "bogus"' config.nodes.foo.bottom ./deferred-module.nix
375checkConfigError '.*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
376
377# Check the file location information is propagated into submodules
378checkConfigOutput the-file.nix config.submodule.internalFiles.0 ./submoduleFiles.nix
379
380
381# Check that disabledModules works recursively and correctly
382checkConfigOutput '^true$' config.enable ./disable-recursive/main.nix
383checkConfigOutput '^true$' config.enable ./disable-recursive/{main.nix,disable-foo.nix}
384checkConfigOutput '^true$' config.enable ./disable-recursive/{main.nix,disable-bar.nix}
385checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./disable-recursive/{main.nix,disable-foo.nix,disable-bar.nix}
386
387# Check that imports can depend on derivations
388checkConfigOutput '^true$' config.enable ./import-from-store.nix
389
390# Check that configs can be conditional on option existence
391checkConfigOutput '^true$' config.enable ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix
392checkConfigOutput '^360$' config.value ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix
393checkConfigOutput '^7$' config.value ./define-option-dependently.nix ./declare-int-positive-value.nix
394checkConfigOutput '^true$' config.set.enable ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix
395checkConfigOutput '^360$' config.set.value ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix
396checkConfigOutput '^7$' config.set.value ./define-option-dependently-nested.nix ./declare-int-positive-value-nested.nix
397
398# Check attrsOf and lazyAttrsOf. Only lazyAttrsOf should be lazy, and only
399# attrsOf should work with conditional definitions
400# In addition, lazyAttrsOf should honor an options emptyValue
401checkConfigError "is not lazy" config.isLazy ./declare-attrsOf.nix ./attrsOf-lazy-check.nix
402checkConfigOutput '^true$' config.isLazy ./declare-lazyAttrsOf.nix ./attrsOf-lazy-check.nix
403checkConfigOutput '^true$' config.conditionalWorks ./declare-attrsOf.nix ./attrsOf-conditional-check.nix
404checkConfigOutput '^false$' config.conditionalWorks ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix
405checkConfigOutput '^"empty"$' config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix
406
407# Check attrsWith type merging
408checkConfigError 'The option `mergedLazyNonLazy'\'' in `.*'\'' is already declared in `.*'\''\.' options.mergedLazyNonLazy ./lazy-attrsWith.nix
409checkConfigOutput '^11$' config.lazyResult ./lazy-attrsWith.nix
410checkConfigError 'infinite recursion encountered' config.nonLazyResult ./lazy-attrsWith.nix
411
412# AttrsWith placeholder tests
413checkConfigOutput '^"mergedName.<id>.nested"$' config.result ./name-merge-attrsWith-1.nix
414checkConfigError 'The option .mergedName. in .*\.nix. is already declared in .*\.nix' config.mergedName ./name-merge-attrsWith-2.nix
415
416# Test type.functor.wrapped deprecation warning
417# should emit the warning on:
418# - merged types
419# - non-merged types
420# - nestedTypes elemType
421# attrsWith
422NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.attrsWith.type.functor.wrapped ./deprecated-wrapped.nix
423NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedAttrsWith.type.functor.wrapped ./deprecated-wrapped.nix
424
425NIX_ABORT_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
426NIX_ABORT_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
427# listOf
428NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.listOf.type.functor.wrapped ./deprecated-wrapped.nix
429NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedListOf.type.functor.wrapped ./deprecated-wrapped.nix
430
431NIX_ABORT_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
432NIX_ABORT_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
433# unique / uniq
434NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.unique.type.functor.wrapped ./deprecated-wrapped.nix
435NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedUnique.type.functor.wrapped ./deprecated-wrapped.nix
436
437NIX_ABORT_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
438NIX_ABORT_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
439# nullOr
440NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.nullOr.type.functor.wrapped ./deprecated-wrapped.nix
441NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedNullOr.type.functor.wrapped ./deprecated-wrapped.nix
442
443NIX_ABORT_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
444NIX_ABORT_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
445# functionTo
446NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.functionTo.type.functor.wrapped ./deprecated-wrapped.nix
447NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedFunctionTo.type.functor.wrapped ./deprecated-wrapped.nix
448
449NIX_ABORT_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
450NIX_ABORT_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
451
452# coercedTo
453# Note: test 'nestedTypes.finalType' and 'nestedTypes.coercedType'
454NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.coercedTo.type.functor.wrapped ./deprecated-wrapped.nix
455NIX_ABORT_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
456NIX_ABORT_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
457# either
458NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.either.type.functor.wrapped ./deprecated-wrapped.nix
459NIX_ABORT_ON_WARN=1 checkConfigError 'The deprecated `.*functor.wrapped` attribute .*is accessed, use `.*nestedTypes.elemType` instead.' options.mergedEither.type.functor.wrapped ./deprecated-wrapped.nix
460
461NIX_ABORT_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
462NIX_ABORT_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
463NIX_ABORT_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
464NIX_ABORT_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
465
466# Even with multiple assignments, a type error should be thrown if any of them aren't valid
467checkConfigError 'A definition for option .* is not of type .*' \
468 config.value ./declare-int-unsigned-value.nix ./define-value-list.nix ./define-value-int-positive.nix
469
470## Freeform modules
471# Assigning without a declared option should work
472checkConfigOutput '^"24"$' config.value ./freeform-attrsOf.nix ./define-value-string.nix
473# Shorthand modules interpret `meta` and `class` as config items
474checkConfigOutput '^true$' options._module.args.value.result ./freeform-attrsOf.nix ./define-freeform-keywords-shorthand.nix
475# No freeform assignments shouldn't make it error
476checkConfigOutput '^{}$' config ./freeform-attrsOf.nix
477# but only if the type matches
478checkConfigError 'A definition for option .* is not of type .*' config.value ./freeform-attrsOf.nix ./define-value-list.nix
479# and properties should be applied
480checkConfigOutput '^"yes"$' config.value ./freeform-attrsOf.nix ./define-value-string-properties.nix
481# Options should still be declarable, and be able to have a type that doesn't match the freeform type
482checkConfigOutput '^false$' config.enable ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix
483checkConfigOutput '^"24"$' config.value ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix
484# and this should work too with nested values
485checkConfigOutput '^false$' config.nest.foo ./freeform-attrsOf.nix ./freeform-nested.nix
486checkConfigOutput '^"bar"$' config.nest.bar ./freeform-attrsOf.nix ./freeform-nested.nix
487# Check whether a declared option can depend on an freeform-typed one
488checkConfigOutput '^null$' config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix
489checkConfigOutput '^"24"$' config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix ./define-value-string.nix
490# Check whether an freeform-typed value can depend on a declared option, this can only work with lazyAttrsOf
491checkConfigError 'infinite recursion encountered' config.foo ./freeform-attrsOf.nix ./freeform-unstr-dep-str.nix
492checkConfigError 'The option .* was accessed but has no value defined. Try setting the option.' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix
493checkConfigOutput '^"24"$' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix ./define-value-string.nix
494# submodules in freeformTypes should have their locations annotated
495checkConfigOutput '/freeform-submodules.nix"$' config.fooDeclarations.0 ./freeform-submodules.nix
496# freeformTypes can get merged using `types.type`, including submodules
497checkConfigOutput '^10$' config.free.xxx.foo ./freeform-submodules.nix
498checkConfigOutput '^10$' config.free.yyy.bar ./freeform-submodules.nix
499
500## types.anything
501# Check that attribute sets are merged recursively
502checkConfigOutput '^null$' config.value.foo ./types-anything/nested-attrs.nix
503checkConfigOutput '^null$' config.value.l1.foo ./types-anything/nested-attrs.nix
504checkConfigOutput '^null$' config.value.l1.l2.foo ./types-anything/nested-attrs.nix
505checkConfigOutput '^null$' config.value.l1.l2.l3.foo ./types-anything/nested-attrs.nix
506# Attribute sets that are coercible to strings shouldn't be recursed into
507checkConfigOutput '^"foo"$' config.value.outPath ./types-anything/attrs-coercible.nix
508# Multiple lists aren't concatenated together if their definitions are not equal
509checkConfigError 'The option .* has conflicting definition values' config.value ./types-anything/lists.nix
510# Check that all equalizable atoms can be used as long as all definitions are equal
511checkConfigOutput '^0$' config.value.int ./types-anything/equal-atoms.nix
512checkConfigOutput '^false$' config.value.bool ./types-anything/equal-atoms.nix
513checkConfigOutput '^""$' config.value.string ./types-anything/equal-atoms.nix
514checkConfigOutput '^"/[^"]+"$' config.value.path ./types-anything/equal-atoms.nix
515checkConfigOutput '^null$' config.value.null ./types-anything/equal-atoms.nix
516checkConfigOutput '^0.1$' config.value.float ./types-anything/equal-atoms.nix
517checkConfigOutput '^\[1,"a",{"x":null}\]$' config.value.list ./types-anything/equal-atoms.nix
518# Functions can't be merged together
519checkConfigError "The option .value.multiple-lambdas.<function body>. has conflicting option types" config.applied.multiple-lambdas ./types-anything/functions.nix
520checkConfigOutput '^true$' config.valueIsFunction.single-lambda ./types-anything/functions.nix
521checkConfigOutput '^null$' config.applied.merging-lambdas.x ./types-anything/functions.nix
522checkConfigOutput '^null$' config.applied.merging-lambdas.y ./types-anything/functions.nix
523# Check that all mk* modifiers are applied
524checkConfigError 'attribute .* not found' config.value.mkiffalse ./types-anything/mk-mods.nix
525checkConfigOutput '^{}$' config.value.mkiftrue ./types-anything/mk-mods.nix
526checkConfigOutput '^1$' config.value.mkdefault ./types-anything/mk-mods.nix
527checkConfigOutput '^{}$' config.value.mkmerge ./types-anything/mk-mods.nix
528checkConfigOutput '^true$' config.value.mkbefore ./types-anything/mk-mods.nix
529checkConfigOutput '^1$' config.value.nested.foo ./types-anything/mk-mods.nix
530checkConfigOutput '^"baz"$' config.value.nested.bar.baz ./types-anything/mk-mods.nix
531
532## types.functionTo
533checkConfigOutput '^"input is input"$' config.result ./functionTo/trivial.nix
534checkConfigOutput '^"a b"$' config.result ./functionTo/merging-list.nix
535checkConfigError '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
536checkConfigOutput '^"b a"$' config.result ./functionTo/list-order.nix
537checkConfigOutput '^"a c"$' config.result ./functionTo/merging-attrs.nix
538checkConfigOutput '^"a bee"$' config.result ./functionTo/submodule-options.nix
539checkConfigOutput '^"fun.<function body>.a fun.<function body>.b"$' config.optionsResult ./functionTo/submodule-options.nix
540
541# moduleType
542checkConfigOutput '^"a b"$' config.resultFoo ./declare-variants.nix ./define-variant.nix
543checkConfigOutput '^"a b y z"$' config.resultFooBar ./declare-variants.nix ./define-variant.nix
544checkConfigOutput '^"a b c"$' config.resultFooFoo ./declare-variants.nix ./define-variant.nix
545
546## emptyValue's
547checkConfigOutput "\[\]" config.list.a ./emptyValues.nix
548checkConfigOutput "{}" config.attrs.a ./emptyValues.nix
549checkConfigOutput "null" config.null.a ./emptyValues.nix
550checkConfigOutput "{}" config.submodule.a ./emptyValues.nix
551# These types don't have empty values
552checkConfigError 'The option .int.a. was accessed but has no value defined. Try setting the option.' config.int.a ./emptyValues.nix
553checkConfigError 'The option .nonEmptyList.a. was accessed but has no value defined. Try setting the option.' config.nonEmptyList.a ./emptyValues.nix
554
555# types.unique
556# requires a single definition
557checkConfigError 'The option .examples\.merged. is defined multiple times while it.s expected to be unique' config.examples.merged.a ./types-unique.nix
558# user message is printed
559checkConfigError '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
560# let the inner merge function check the values (on demand)
561checkConfigError 'A definition for option .examples\.badLazyType\.a. is not of type .string.' config.examples.badLazyType.a ./types-unique.nix
562# overriding still works (unlike option uniqueness)
563checkConfigOutput '^"bee"$' config.examples.override.b ./types-unique.nix
564
565## types.raw
566checkConfigOutput '^true$' config.unprocessedNestingEvaluates.success ./raw.nix
567checkConfigOutput "10" config.processedToplevel ./raw.nix
568checkConfigError "The option .multiple. is defined multiple times" config.multiple ./raw.nix
569checkConfigOutput "bar" config.priorities ./raw.nix
570
571## Option collision
572checkConfigError \
573 '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.' \
574 config.set \
575 ./declare-set.nix ./declare-enable-nested.nix
576
577# Options: accidental use of an option-type instead of option (or other tagged type; unlikely)
578checkConfigError '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
579checkConfigError '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
580checkConfigError '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
581
582# Check that that merging of option collisions doesn't depend on type being set
583checkConfigError '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
584
585# Test that types.optionType merges types correctly
586checkConfigOutput '^10$' config.theOption.int ./optionTypeMerging.nix
587checkConfigOutput '^"hello"$' config.theOption.str ./optionTypeMerging.nix
588
589# Test that types.optionType correctly annotates option locations
590checkConfigError 'The option .theOption.nested. in .other.nix. is already declared in .optionTypeFile.nix.' config.theOption.nested ./optionTypeFile.nix
591
592# Test that types.optionType leaves types untouched as long as they don't need to be merged
593checkConfigOutput 'ok' config.freeformItems.foo.bar ./adhoc-freeformType-survives-type-merge.nix
594
595# Test that specifying both functor.wrapped and functor.payload isn't allowed
596checkConfigError 'Type foo defines both `functor.payload` and `functor.wrapped` at the same time, which is not supported.' config.result ./default-type-merge-both.nix
597
598
599# Anonymous submodules don't get nixed by import resolution/deduplication
600# because of an `extendModules` bug, issue 168767.
601checkConfigOutput '^1$' config.sub.specialisation.value ./extendModules-168767-imports.nix
602
603# Class checks, evalModules
604checkConfigOutput '^{}$' config.ok.config ./class-check.nix
605checkConfigOutput '"nixos"' config.ok.class ./class-check.nix
606checkConfigError 'The module `.*/module-class-is-darwin.nix`.*?expects class "nixos".' config.fail.config ./class-check.nix
607checkConfigError 'The module `foo.nix#darwinModules.default`.*?expects class "nixos".' config.fail-anon.config ./class-check.nix
608
609# Class checks, submoduleWith
610checkConfigOutput '^{}$' config.sub.nixosOk ./class-check.nix
611checkConfigError 'The module `.*/module-class-is-darwin.nix`.*?expects class "nixos".' config.sub.nixosFail.config ./class-check.nix
612
613# submoduleWith type merge with different class
614checkConfigError 'A submoduleWith option is declared multiple times with conflicting class values "darwin" and "nixos".' config.sub.mergeFail.config ./class-check.nix
615
616# _type check
617checkConfigError '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
618checkConfigOutput '^true$' config.enable ./declare-enable.nix ./define-enable-with-top-level-mkIf.nix
619checkConfigError 'Expected a module, but found a value of type .*"configuration".*, while trying to load a module into .*/import-configuration.nix.' config ./import-configuration.nix
620checkConfigError 'please only import the modules that make up the configuration' config ./import-configuration.nix
621checkConfigError '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
622
623# doRename works when `warnings` does not exist.
624checkConfigOutput '^1234$' config.c.d.e ./doRename-basic.nix
625# doRename adds a warning.
626checkConfigOutput '^"The option `a\.b. defined in `.*/doRename-warnings\.nix. has been renamed to `c\.d\.e.\."$' \
627 config.result \
628 ./doRename-warnings.nix
629checkConfigOutput "^true$" config.result ./doRename-condition.nix ./doRename-condition-enable.nix
630checkConfigOutput "^true$" config.result ./doRename-condition.nix ./doRename-condition-no-enable.nix
631checkConfigOutput "^true$" config.result ./doRename-condition.nix ./doRename-condition-migrated.nix
632
633# Anonymous modules get deduplicated by key
634checkConfigOutput '^"pear"$' config.once.raw ./merge-module-with-key.nix
635checkConfigOutput '^"pear\\npear"$' config.twice.raw ./merge-module-with-key.nix
636
637# Declaration positions
638# Line should be present for direct options
639checkConfigOutput '^14$' options.imported.line14.declarationPositions.0.line ./declaration-positions.nix
640checkConfigOutput '/declaration-positions.nix"$' options.imported.line14.declarationPositions.0.file ./declaration-positions.nix
641# Generated options may not have line numbers but they will at least get the
642# right file
643checkConfigOutput '/declaration-positions.nix"$' options.generated.line22.declarationPositions.0.file ./declaration-positions.nix
644checkConfigOutput '^null$' options.generated.line22.declarationPositions.0.line ./declaration-positions.nix
645# Submodules don't break it
646checkConfigOutput '^45$' config.submoduleLine38.submodDeclLine45.0.line ./declaration-positions.nix
647checkConfigOutput '/declaration-positions.nix"$' config.submoduleLine38.submodDeclLine45.0.file ./declaration-positions.nix
648# New options under freeform submodules get collected into the parent submodule
649# (consistent with .declarations behaviour, but weird; notably appears in system.build)
650checkConfigOutput '^38|27$' options.submoduleLine38.declarationPositions.0.line ./declaration-positions.nix
651checkConfigOutput '^38|27$' options.submoduleLine38.declarationPositions.1.line ./declaration-positions.nix
652# nested options work
653checkConfigOutput '^34$' options.nested.nestedLine34.declarationPositions.0.line ./declaration-positions.nix
654
655# types.pathWith { inStore = true; }
656checkConfigOutput '".*/store/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv"' config.pathInStore.ok1 ./pathWith.nix
657checkConfigOutput '".*/store/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15"' config.pathInStore.ok2 ./pathWith.nix
658checkConfigOutput '".*/store/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15/bin/bash"' config.pathInStore.ok3 ./pathWith.nix
659checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ""' config.pathInStore.bad1 ./pathWith.nix
660checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store"' config.pathInStore.bad2 ./pathWith.nix
661checkConfigError 'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store/"' config.pathInStore.bad3 ./pathWith.nix
662checkConfigError '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
663checkConfigError '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
664
665# types.pathWith { inStore = false; }
666checkConfigOutput '"/foo/bar"' config.pathNotInStore.ok1 ./pathWith.nix
667checkConfigOutput '".*/store"' config.pathNotInStore.ok2 ./pathWith.nix
668checkConfigOutput '".*/store/"' config.pathNotInStore.ok3 ./pathWith.nix
669checkConfigOutput '""' config.pathNotInStore.ok4 ./pathWith.nix
670checkConfigOutput '".*/store/.links"' config.pathNotInStore.ok5 ./pathWith.nix
671checkConfigError '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
672checkConfigError '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
673checkConfigError '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
674checkConfigError '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
675
676# types.pathWith { }
677checkConfigOutput '"/this/is/absolute"' config.anyPath.ok1 ./pathWith.nix
678checkConfigOutput '"./this/is/relative"' config.anyPath.ok2 ./pathWith.nix
679checkConfigError 'A definition for option .anyPath.bad1. is not of type .path.' config.anyPath.bad1 ./pathWith.nix
680
681# types.pathWith { absolute = true; }
682checkConfigOutput '"/this/is/absolute"' config.absolutePathNotInStore.ok1 ./pathWith.nix
683checkConfigError 'A definition for option .absolutePathNotInStore.bad1. is not of type .absolute path not in the Nix store.' config.absolutePathNotInStore.bad1 ./pathWith.nix
684checkConfigError 'A definition for option .absolutePathNotInStore.bad2. is not of type .absolute path not in the Nix store.' config.absolutePathNotInStore.bad2 ./pathWith.nix
685
686# types.pathWith failed type merge
687checkConfigError 'The option .conflictingPathOptionType. in .*/pathWith.nix. is already declared in .*/pathWith.nix' config.conflictingPathOptionType ./pathWith.nix
688
689# types.pathWith { inStore = true; absolute = false; }
690checkConfigError 'In pathWith, inStore means the path must be absolute' config.impossiblePathOptionType ./pathWith.nix
691
692# mkDefinition
693# check that mkDefinition 'file' is printed in the error message
694checkConfigError 'Cannot merge definitions.*\n\s*- In .file.*\n\s*- In .other.*' config.conflict ./mkDefinition.nix
695checkConfigError 'A definition for option .viaOptionDefault. is not of type .boolean.*' config.viaOptionDefault ./mkDefinition.nix
696checkConfigOutput '^true$' config.viaConfig ./mkDefinition.nix
697checkConfigOutput '^true$' config.mkMerge ./mkDefinition.nix
698checkConfigOutput '^true$' config.mkForce ./mkDefinition.nix
699
700# specialArgs._class
701checkConfigOutput '"nixos"' config.nixos.config.foo ./specialArgs-class.nix
702checkConfigOutput '"bar"' config.conditionalImportAsNixos.config.foo ./specialArgs-class.nix
703checkConfigError 'attribute .*bar.* not found' config.conditionalImportAsNixos.config.bar ./specialArgs-class.nix
704checkConfigError 'attribute .*foo.* not found' config.conditionalImportAsDarwin.config.foo ./specialArgs-class.nix
705checkConfigOutput '"foo"' config.conditionalImportAsDarwin.config.bar ./specialArgs-class.nix
706checkConfigOutput '"nixos"' config.sub.nixos.foo ./specialArgs-class.nix
707checkConfigOutput '"bar"' config.sub.conditionalImportAsNixos.foo ./specialArgs-class.nix
708checkConfigError 'attribute .*bar.* not found' config.sub.conditionalImportAsNixos.bar ./specialArgs-class.nix
709checkConfigError 'attribute .*foo.* not found' config.sub.conditionalImportAsDarwin.foo ./specialArgs-class.nix
710checkConfigOutput '"foo"' config.sub.conditionalImportAsDarwin.bar ./specialArgs-class.nix
711
712cat <<EOF
713====== module tests ======
714$pass Pass
715$fail Fail
716EOF
717
718if [ "$fail" -ne 0 ]; then
719 exit 1
720fi
721exit 0