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.
8 # [nixpkgs]$ lib/tests/modules.sh
10 # [nixpkgs]$ nix-build lib/tests/release.nix
12 set -o errexit
-o noclobber
-o nounset
-o pipefail
13 shopt -s failglob inherit_errexit
15 # https://stackoverflow.com/a/246128/6605742
16 DIR
="$( cd "$
( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
26 local script="import ./default.nix { modules = [ $* ];}"
27 nix-instantiate
--timeout 1 -E "$script" -A "$attr" --eval-only --show-trace --read-write-mode
33 local script="import ./default.nix { modules = [ $* ];}"
34 echo 2>&1 "$ nix-instantiate -E '$script' -A '$attr' --eval-only"
35 evalConfig
"$attr" "$@" || true
40 local outputContains
=$1
42 if evalConfig
"$@" 2>/dev
/null |
grep -E --silent "$outputContains" ; then
45 echo 2>&1 "error: Expected result matching '$outputContains', while evaluating"
51 local errorContains
=$1
54 if err
="$(evalConfig "$@
" 2>&1 >/dev/null)"; then
55 echo 2>&1 "error: Expected error code, got exit code 0, while evaluating"
58 if echo "$err" |
grep -zP --silent "$errorContains" ; then
61 echo 2>&1 "error: Expected error matching '$errorContains', while evaluating"
67 # Shorthand meta attribute does not duplicate the config
68 checkConfigOutput
'^"one two"$' config.result .
/shorthand-meta.nix
70 checkConfigOutput
'^true$' config.result .
/test-mergeAttrDefinitionsWithPrio.nix
72 # Check that a module argument is passed, also when a default is available
75 # When the default is needed, we currently fail to do what the users expect, as
76 # we pass our own argument anyway, even if it *turns out* not to exist.
78 # The reason for this is that we don't know at invocation time what is in the
79 # _module.args option. That value is only available *after* all modules have been
82 # Hypothetically, Nix could help support this by giving access to the default
83 # values, through a new built-in function.
84 # However the default values are allowed to depend on other arguments, so those
85 # would have to be passed in somehow, making this not just a getter but
86 # something more complicated.
88 # At that point we have to wonder whether the extra complexity is worth the cost.
89 # Another - subjective - reason not to support it is that default values
90 # contradict the notion that an option has a single value, where _module.args
92 checkConfigOutput
'^true$' config.result .
/module-argument-default.nix
95 checkConfigOutput
'^true$' config.assertion .
/gvariant.nix
98 checkConfigOutput
'".*/store/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv"' config.pathInStore.ok1 .
/types.nix
99 checkConfigOutput
'".*/store/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15"' config.pathInStore.ok2 .
/types.nix
100 checkConfigOutput
'".*/store/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15/bin/bash"' config.pathInStore.ok3 .
/types.nix
101 checkConfigError
'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ""' config.pathInStore.bad1 .
/types.nix
102 checkConfigError
'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store"' config.pathInStore.bad2 .
/types.nix
103 checkConfigError
'A definition for option .* is not of type .path in the Nix store.. Definition values:\n\s*- In .*: ".*/store/"' config.pathInStore.bad3 .
/types.nix
104 checkConfigError
'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
105 checkConfigError
'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
107 # Check boolean option.
108 checkConfigOutput
'^false$' config.
enable .
/declare-enable.nix
109 checkConfigError
'The option .* does not exist. Definition values:\n\s*- In .*: true' config.
enable .
/define-enable.nix
110 checkConfigError
'The option .* does not exist. Definition values:\n\s*- In .*' config.
enable .
/define-enable-throw.nix
111 checkConfigError
'while evaluating a definition from `.*/define-enable-abort.nix' config.
enable .
/define-enable-abort.nix
112 checkConfigError
'while evaluating the error message for definitions for .enable., which is an option that does not exist' config.
enable .
/define-enable-abort.nix
114 checkConfigOutput
'^1$' config.bare-submodule.nested .
/declare-bare-submodule.nix .
/declare-bare-submodule-nested-option.nix
115 checkConfigOutput
'^2$' config.bare-submodule.deep .
/declare-bare-submodule.nix .
/declare-bare-submodule-deep-option.nix
116 checkConfigOutput
'^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
117 checkConfigOutput
'^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
118 checkConfigOutput
'^2$' config.bare-submodule.deep .
/declare-bare-submodule.nix .
/declare-bare-submodule-deep-option.nix .
/define-shorthandOnlyDefinesConfig-true.nix
119 checkConfigError
'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
121 # Check integer types.
123 checkConfigOutput
'^42$' config.value .
/declare-int-unsigned-value.nix .
/define-value-int-positive.nix
124 checkConfigError
'A definition for option .* is not of type.*unsigned integer.*. Definition values:\n\s*- In .*: -23' config.value .
/declare-int-unsigned-value.nix .
/define-value-int-negative.nix
126 checkConfigError
'A definition for option .* is not of type.*positive integer.*. Definition values:\n\s*- In .*: 0' config.value .
/declare-int-positive-value.nix .
/define-value-int-zero.nix
128 checkConfigOutput
'^42$' config.value .
/declare-int-between-value.nix .
/define-value-int-positive.nix
129 checkConfigError
'A definition for option .* is not of type.*between.*-21 and 43.*inclusive.*. Definition values:\n\s*- In .*: -23' config.value .
/declare-int-between-value.nix .
/define-value-int-negative.nix
133 checkConfigOutput
'^42$' config.value .
/declare-either.nix .
/define-value-int-positive.nix
134 checkConfigOutput
'^"24"$' config.value .
/declare-either.nix .
/define-value-string.nix
136 checkConfigOutput
'^42$' config.value .
/declare-oneOf.nix .
/define-value-int-positive.nix
137 checkConfigOutput
'^\[ \]$' config.value .
/declare-oneOf.nix .
/define-value-list.nix
138 checkConfigOutput
'^"24"$' config.value .
/declare-oneOf.nix .
/define-value-string.nix
140 # Check mkForce without submodules.
141 set -- config.
enable .
/declare-enable.nix .
/define-enable.nix
142 checkConfigOutput
'^true$' "$@"
143 checkConfigOutput
'^false$' "$@" .
/define-force-enable.nix
144 checkConfigOutput
'^false$' "$@" .
/define-enable-force.nix
146 # Check mkForce with option and submodules.
147 checkConfigError
'attribute .*foo.* .* not found' config.attrsOfSub.foo.
enable .
/declare-attrsOfSub-any-enable.nix
148 checkConfigOutput
'^false$' config.attrsOfSub.foo.
enable .
/declare-attrsOfSub-any-enable.nix .
/define-attrsOfSub-foo.nix
149 set -- config.attrsOfSub.foo.
enable .
/declare-attrsOfSub-any-enable.nix .
/define-attrsOfSub-foo-enable.nix
150 checkConfigOutput
'^true$' "$@"
151 checkConfigOutput
'^false$' "$@" .
/define-force-attrsOfSub-foo-enable.nix
152 checkConfigOutput
'^false$' "$@" .
/define-attrsOfSub-force-foo-enable.nix
153 checkConfigOutput
'^false$' "$@" .
/define-attrsOfSub-foo-force-enable.nix
154 checkConfigOutput
'^false$' "$@" .
/define-attrsOfSub-foo-enable-force.nix
156 # Check overriding effect of mkForce on submodule definitions.
157 checkConfigError
'attribute .*bar.* .* not found' config.attrsOfSub.bar.
enable .
/declare-attrsOfSub-any-enable.nix .
/define-attrsOfSub-foo.nix
158 checkConfigOutput
'^false$' config.attrsOfSub.bar.
enable .
/declare-attrsOfSub-any-enable.nix .
/define-attrsOfSub-foo.nix .
/define-attrsOfSub-bar.nix
159 set -- config.attrsOfSub.bar.
enable .
/declare-attrsOfSub-any-enable.nix .
/define-attrsOfSub-foo.nix .
/define-attrsOfSub-bar-enable.nix
160 checkConfigOutput
'^true$' "$@"
161 checkConfigError
'attribute .*bar.* .* not found' "$@" .
/define-force-attrsOfSub-foo-enable.nix
162 checkConfigError
'attribute .*bar.* .* not found' "$@" .
/define-attrsOfSub-force-foo-enable.nix
163 checkConfigOutput
'^true$' "$@" .
/define-attrsOfSub-foo-force-enable.nix
164 checkConfigOutput
'^true$' "$@" .
/define-attrsOfSub-foo-enable-force.nix
166 # Check mkIf with submodules.
167 checkConfigError
'attribute .*foo.* .* not found' config.attrsOfSub.foo.
enable .
/declare-enable.nix .
/declare-attrsOfSub-any-enable.nix
168 set -- config.attrsOfSub.foo.
enable .
/declare-enable.nix .
/declare-attrsOfSub-any-enable.nix
169 checkConfigError
'attribute .*foo.* .* not found' "$@" .
/define-if-attrsOfSub-foo-enable.nix
170 checkConfigError
'attribute .*foo.* .* not found' "$@" .
/define-attrsOfSub-if-foo-enable.nix
171 checkConfigError
'attribute .*foo.* .* not found' "$@" .
/define-attrsOfSub-foo-if-enable.nix
172 checkConfigOutput
'^false$' "$@" .
/define-attrsOfSub-foo-enable-if.nix
173 checkConfigOutput
'^true$' "$@" .
/define-enable.nix .
/define-if-attrsOfSub-foo-enable.nix
174 checkConfigOutput
'^true$' "$@" .
/define-enable.nix .
/define-attrsOfSub-if-foo-enable.nix
175 checkConfigOutput
'^true$' "$@" .
/define-enable.nix .
/define-attrsOfSub-foo-if-enable.nix
176 checkConfigOutput
'^true$' "$@" .
/define-enable.nix .
/define-attrsOfSub-foo-enable-if.nix
178 # Check disabledModules with config definitions and option declarations.
179 set -- config.
enable .
/define-enable.nix .
/declare-enable.nix
180 checkConfigOutput
'^true$' "$@"
181 checkConfigOutput
'^false$' "$@" .
/disable-define-enable.nix
182 checkConfigOutput
'^false$' "$@" .
/disable-define-enable-string-path.nix
183 checkConfigError
"The option .*enable.* does not exist. Definition values:\n\s*- In .*: true" "$@" .
/disable-declare-enable.nix
184 checkConfigError
"attribute .*enable.* in selection path .*config.enable.* not found" "$@" .
/disable-define-enable.nix .
/disable-declare-enable.nix
185 checkConfigError
"attribute .*enable.* in selection path .*config.enable.* not found" "$@" .
/disable-enable-modules.nix
187 checkConfigOutput
'^true$' 'config.positive.enable' .
/disable-module-with-key.nix
188 checkConfigOutput
'^false$' 'config.negative.enable' .
/disable-module-with-key.nix
189 checkConfigError
'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
191 # 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.
192 checkConfigOutput
'^true$' 'config.positive.enable' .
/disable-module-with-toString-key.nix
193 checkConfigOutput
'^false$' 'config.negative.enable' .
/disable-module-with-toString-key.nix
195 # Check _module.args.
196 set -- config.
enable .
/declare-enable.nix .
/define-enable-with-custom-arg.nix
197 checkConfigError
'while evaluating the module argument .*custom.* in .*define-enable-with-custom-arg.nix.*:' "$@"
198 checkConfigOutput
'^true$' "$@" .
/define-_module-args-custom.nix
200 # Check that using _module.args on imports cause infinite recursions, with
201 # the proper error context.
202 set -- "$@" .
/define-_module-args-custom.nix .
/import-custom-arg.nix
203 checkConfigError
'while evaluating the module argument .*custom.* in .*import-custom-arg.nix.*:' "$@"
204 checkConfigError
'infinite recursion encountered' "$@"
206 # Check _module.check.
207 set -- config.
enable .
/declare-enable.nix .
/define-enable.nix .
/define-attrsOfSub-foo.nix
208 checkConfigError
'The option .* does not exist. Definition values:\n\s*- In .*' "$@"
209 checkConfigOutput
'^true$' "$@" .
/define-module-check.nix
211 # Check coerced value.
213 checkConfigOutput
'^"42"$' config.value .
/declare-coerced-value.nix
214 checkConfigOutput
'^"24"$' config.value .
/declare-coerced-value.nix .
/define-value-string.nix
215 checkConfigError
'A definition for option .* is not.*string or signed integer convertible to it.*. Definition values:\n\s*- In .*: \[ \]' config.value .
/declare-coerced-value.nix .
/define-value-list.nix
217 # Check coerced value with unsound coercion
218 checkConfigOutput
'^12$' config.value .
/declare-coerced-value-unsound.nix
219 checkConfigError
'A definition for option .* is not of type .*. Definition values:\n\s*- In .*: "1000"' config.value .
/declare-coerced-value-unsound.nix .
/define-value-string-bigint.nix
220 checkConfigError
'toInt: Could not convert .* to int' config.value .
/declare-coerced-value-unsound.nix .
/define-value-string-arbitrary.nix
222 # Check mkAliasOptionModule.
223 checkConfigOutput
'^true$' config.
enable .
/alias-with-priority.nix
224 checkConfigOutput
'^true$' config.enableAlias .
/alias-with-priority.nix
225 checkConfigOutput
'^false$' config.
enable .
/alias-with-priority-can-override.nix
226 checkConfigOutput
'^false$' config.enableAlias .
/alias-with-priority-can-override.nix
228 # Check mkPackageOption
229 checkConfigOutput
'^"hello"$' config.package.pname .
/declare-mkPackageOption.nix
230 checkConfigOutput
'^"hello"$' config.namedPackage.pname .
/declare-mkPackageOption.nix
231 checkConfigOutput
'^".*Hello.*"$' options.namedPackage.description .
/declare-mkPackageOption.nix
232 checkConfigOutput
'^"hello"$' config.pathPackage.pname .
/declare-mkPackageOption.nix
233 checkConfigOutput
'^"pkgs\.hello\.override \{ stdenv = pkgs\.clangStdenv; \}"$' options.packageWithExample.example.text .
/declare-mkPackageOption.nix
234 checkConfigOutput
'^".*Example extra description\..*"$' options.packageWithExtraDescription.description .
/declare-mkPackageOption.nix
235 checkConfigError
'The option .undefinedPackage. is used but not defined' config.undefinedPackage .
/declare-mkPackageOption.nix
236 checkConfigOutput
'^null$' config.nullablePackage .
/declare-mkPackageOption.nix
237 checkConfigOutput
'^"null or package"$' options.nullablePackageWithDefault.
type.description .
/declare-mkPackageOption.nix
238 checkConfigOutput
'^"myPkgs\.hello"$' options.packageWithPkgsText.defaultText.text .
/declare-mkPackageOption.nix
239 checkConfigOutput
'^"hello-other"$' options.packageFromOtherSet.default.pname .
/declare-mkPackageOption.nix
243 ## specialArgs should work
244 checkConfigOutput
'^"foo"$' config.submodule.foo .
/declare-submoduleWith-special.nix
246 ## shorthandOnlyDefines config behaves as expected
247 checkConfigOutput
'^true$' config.submodule.config .
/declare-submoduleWith-shorthand.nix .
/define-submoduleWith-shorthand.nix
248 checkConfigError
'is not of type `boolean' config.submodule.config .
/declare-submoduleWith-shorthand.nix .
/define-submoduleWith-noshorthand.nix
249 checkConfigError
"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
250 checkConfigOutput
'^true$' config.submodule.config .
/declare-submoduleWith-noshorthand.nix .
/define-submoduleWith-noshorthand.nix
252 ## submoduleWith should merge all modules in one swoop
253 checkConfigOutput
'^true$' config.submodule.inner .
/declare-submoduleWith-modules.nix
254 checkConfigOutput
'^true$' config.submodule.outer .
/declare-submoduleWith-modules.nix
255 # Should also be able to evaluate the type name (which evaluates freeformType,
256 # which evaluates all the modules defined by the type)
257 checkConfigOutput
'^"submodule"$' options.submodule.
type.description .
/declare-submoduleWith-modules.nix
259 ## submodules can be declared using (evalModules {...}).type
260 checkConfigOutput
'^true$' config.submodule.inner .
/declare-submodule-via-evalModules.nix
261 checkConfigOutput
'^true$' config.submodule.outer .
/declare-submodule-via-evalModules.nix
262 # Should also be able to evaluate the type name (which evaluates freeformType,
263 # which evaluates all the modules defined by the type)
264 checkConfigOutput
'^"submodule"$' options.submodule.
type.description .
/declare-submodule-via-evalModules.nix
266 ## Paths should be allowed as values and work as expected
267 checkConfigOutput
'^true$' config.submodule.
enable .
/declare-submoduleWith-path.nix
270 # default module is merged into nodes.foo
271 checkConfigOutput
'"beta"' config.nodes.foo.settingsDict.c .
/deferred-module.nix
272 # errors from the default module are reported with accurate location
273 checkConfigError
'In `the-file-that-contains-the-bad-config.nix, via option default'\'': "bogus"' config.nodes.foo.bottom .
/deferred-module.nix
274 checkConfigError
'.*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
276 # Check the file location information is propagated into submodules
277 checkConfigOutput the-file.nix config.submodule.internalFiles
.0 .
/submoduleFiles.nix
280 # Check that disabledModules works recursively and correctly
281 checkConfigOutput
'^true$' config.
enable .
/disable-recursive
/main.nix
282 checkConfigOutput
'^true$' config.
enable .
/disable-recursive
/{main.nix
,disable-foo.nix
}
283 checkConfigOutput
'^true$' config.
enable .
/disable-recursive
/{main.nix
,disable-bar.nix
}
284 checkConfigError
'The option .* does not exist. Definition values:\n\s*- In .*: true' config.
enable .
/disable-recursive
/{main.nix
,disable-foo.nix
,disable-bar.nix
}
286 # Check that imports can depend on derivations
287 checkConfigOutput
'^true$' config.
enable .
/import-from-store.nix
289 # Check that configs can be conditional on option existence
290 checkConfigOutput
'^true$' config.
enable .
/define-option-dependently.nix .
/declare-enable.nix .
/declare-int-positive-value.nix
291 checkConfigOutput
'^360$' config.value .
/define-option-dependently.nix .
/declare-enable.nix .
/declare-int-positive-value.nix
292 checkConfigOutput
'^7$' config.value .
/define-option-dependently.nix .
/declare-int-positive-value.nix
293 checkConfigOutput
'^true$' config.
set.
enable .
/define-option-dependently-nested.nix .
/declare-enable-nested.nix .
/declare-int-positive-value-nested.nix
294 checkConfigOutput
'^360$' config.
set.value .
/define-option-dependently-nested.nix .
/declare-enable-nested.nix .
/declare-int-positive-value-nested.nix
295 checkConfigOutput
'^7$' config.
set.value .
/define-option-dependently-nested.nix .
/declare-int-positive-value-nested.nix
297 # Check attrsOf and lazyAttrsOf. Only lazyAttrsOf should be lazy, and only
298 # attrsOf should work with conditional definitions
299 # In addition, lazyAttrsOf should honor an options emptyValue
300 checkConfigError
"is not lazy" config.isLazy .
/declare-attrsOf.nix .
/attrsOf-lazy-check.nix
301 checkConfigOutput
'^true$' config.isLazy .
/declare-lazyAttrsOf.nix .
/attrsOf-lazy-check.nix
302 checkConfigOutput
'^true$' config.conditionalWorks .
/declare-attrsOf.nix .
/attrsOf-conditional-check.nix
303 checkConfigOutput
'^false$' config.conditionalWorks .
/declare-lazyAttrsOf.nix .
/attrsOf-conditional-check.nix
304 checkConfigOutput
'^"empty"$' config.value.foo .
/declare-lazyAttrsOf.nix .
/attrsOf-conditional-check.nix
307 # Even with multiple assignments, a type error should be thrown if any of them aren't valid
308 checkConfigError
'A definition for option .* is not of type .*' \
309 config.value .
/declare-int-unsigned-value.nix .
/define-value-list.nix .
/define-value-int-positive.nix
312 # Assigning without a declared option should work
313 checkConfigOutput
'^"24"$' config.value .
/freeform-attrsOf.nix .
/define-value-string.nix
314 # Shorthand modules interpret `meta` and `class` as config items
315 checkConfigOutput
'^true$' options._module.args.value.result .
/freeform-attrsOf.nix .
/define-freeform-keywords-shorthand.nix
316 # No freeform assignments shouldn't make it error
317 checkConfigOutput
'^{ }$' config .
/freeform-attrsOf.nix
318 # but only if the type matches
319 checkConfigError
'A definition for option .* is not of type .*' config.value .
/freeform-attrsOf.nix .
/define-value-list.nix
320 # and properties should be applied
321 checkConfigOutput
'^"yes"$' config.value .
/freeform-attrsOf.nix .
/define-value-string-properties.nix
322 # Options should still be declarable, and be able to have a type that doesn't match the freeform type
323 checkConfigOutput
'^false$' config.
enable .
/freeform-attrsOf.nix .
/define-value-string.nix .
/declare-enable.nix
324 checkConfigOutput
'^"24"$' config.value .
/freeform-attrsOf.nix .
/define-value-string.nix .
/declare-enable.nix
325 # and this should work too with nested values
326 checkConfigOutput
'^false$' config.nest.foo .
/freeform-attrsOf.nix .
/freeform-nested.nix
327 checkConfigOutput
'^"bar"$' config.nest.bar .
/freeform-attrsOf.nix .
/freeform-nested.nix
328 # Check whether a declared option can depend on an freeform-typed one
329 checkConfigOutput
'^null$' config.foo .
/freeform-attrsOf.nix .
/freeform-str-dep-unstr.nix
330 checkConfigOutput
'^"24"$' config.foo .
/freeform-attrsOf.nix .
/freeform-str-dep-unstr.nix .
/define-value-string.nix
331 # Check whether an freeform-typed value can depend on a declared option, this can only work with lazyAttrsOf
332 checkConfigError
'infinite recursion encountered' config.foo .
/freeform-attrsOf.nix .
/freeform-unstr-dep-str.nix
333 checkConfigError
'The option .* is used but not defined' config.foo .
/freeform-lazyAttrsOf.nix .
/freeform-unstr-dep-str.nix
334 checkConfigOutput
'^"24"$' config.foo .
/freeform-lazyAttrsOf.nix .
/freeform-unstr-dep-str.nix .
/define-value-string.nix
335 # submodules in freeformTypes should have their locations annotated
336 checkConfigOutput
'/freeform-submodules.nix"$' config.fooDeclarations
.0 .
/freeform-submodules.nix
337 # freeformTypes can get merged using `types.type`, including submodules
338 checkConfigOutput
'^10$' config.free.xxx.foo .
/freeform-submodules.nix
339 checkConfigOutput
'^10$' config.free.yyy.bar .
/freeform-submodules.nix
342 # Check that attribute sets are merged recursively
343 checkConfigOutput
'^null$' config.value.foo .
/types-anything
/nested-attrs.nix
344 checkConfigOutput
'^null$' config.value.l1.foo .
/types-anything
/nested-attrs.nix
345 checkConfigOutput
'^null$' config.value.l1.l2.foo .
/types-anything
/nested-attrs.nix
346 checkConfigOutput
'^null$' config.value.l1.l2.l3.foo .
/types-anything
/nested-attrs.nix
347 # Attribute sets that are coercible to strings shouldn't be recursed into
348 checkConfigOutput
'^"foo"$' config.value.outPath .
/types-anything
/attrs-coercible.nix
349 # Multiple lists aren't concatenated together
350 checkConfigError
'The option .* has conflicting definitions' config.value .
/types-anything
/lists.nix
351 # Check that all equalizable atoms can be used as long as all definitions are equal
352 checkConfigOutput
'^0$' config.value.int .
/types-anything
/equal-atoms.nix
353 checkConfigOutput
'^false$' config.value.bool .
/types-anything
/equal-atoms.nix
354 checkConfigOutput
'^""$' config.value.string .
/types-anything
/equal-atoms.nix
355 checkConfigOutput
'^/$' config.value.path .
/types-anything
/equal-atoms.nix
356 checkConfigOutput
'^null$' config.value.null .
/types-anything
/equal-atoms.nix
357 checkConfigOutput
'^0.1$' config.value.float .
/types-anything
/equal-atoms.nix
358 # Functions can't be merged together
359 checkConfigError
"The option .value.multiple-lambdas.<function body>. has conflicting option types" config.applied.multiple-lambdas .
/types-anything
/functions.nix
360 checkConfigOutput
'^<LAMBDA>$' config.value.single-lambda .
/types-anything
/functions.nix
361 checkConfigOutput
'^null$' config.applied.merging-lambdas.x .
/types-anything
/functions.nix
362 checkConfigOutput
'^null$' config.applied.merging-lambdas.y .
/types-anything
/functions.nix
363 # Check that all mk* modifiers are applied
364 checkConfigError
'attribute .* not found' config.value.mkiffalse .
/types-anything
/mk-mods.nix
365 checkConfigOutput
'^{ }$' config.value.mkiftrue .
/types-anything
/mk-mods.nix
366 checkConfigOutput
'^1$' config.value.mkdefault .
/types-anything
/mk-mods.nix
367 checkConfigOutput
'^{ }$' config.value.mkmerge .
/types-anything
/mk-mods.nix
368 checkConfigOutput
'^true$' config.value.mkbefore .
/types-anything
/mk-mods.nix
369 checkConfigOutput
'^1$' config.value.nested.foo .
/types-anything
/mk-mods.nix
370 checkConfigOutput
'^"baz"$' config.value.nested.bar.baz .
/types-anything
/mk-mods.nix
373 checkConfigOutput
'^"input is input"$' config.result .
/functionTo
/trivial.nix
374 checkConfigOutput
'^"a b"$' config.result .
/functionTo
/merging-list.nix
375 checkConfigError
'A definition for option .fun.<function body>. is not of type .string.. Definition values:\n\s*- In .*wrong-type.nix' config.result .
/functionTo
/wrong-type.nix
376 checkConfigOutput
'^"b a"$' config.result .
/functionTo
/list-order.nix
377 checkConfigOutput
'^"a c"$' config.result .
/functionTo
/merging-attrs.nix
378 checkConfigOutput
'^"a bee"$' config.result .
/functionTo
/submodule-options.nix
379 checkConfigOutput
'^"fun.<function body>.a fun.<function body>.b"$' config.optionsResult .
/functionTo
/submodule-options.nix
382 checkConfigOutput
'^"a b"$' config.resultFoo .
/declare-variants.nix .
/define-variant.nix
383 checkConfigOutput
'^"a b y z"$' config.resultFooBar .
/declare-variants.nix .
/define-variant.nix
384 checkConfigOutput
'^"a b c"$' config.resultFooFoo .
/declare-variants.nix .
/define-variant.nix
387 checkConfigOutput
"[ ]" config.list.a .
/emptyValues.nix
388 checkConfigOutput
"{ }" config.attrs.a .
/emptyValues.nix
389 checkConfigOutput
"null" config.null.a .
/emptyValues.nix
390 checkConfigOutput
"{ }" config.submodule.a .
/emptyValues.nix
391 # These types don't have empty values
392 checkConfigError
'The option .int.a. is used but not defined' config.int.a .
/emptyValues.nix
393 checkConfigError
'The option .nonEmptyList.a. is used but not defined' config.nonEmptyList.a .
/emptyValues.nix
396 checkConfigOutput
"{ foo = <CODE>; }" config.unprocessedNesting .
/raw.nix
397 checkConfigOutput
"10" config.processedToplevel .
/raw.nix
398 checkConfigError
"The option .multiple. is defined multiple times" config.multiple .
/raw.nix
399 checkConfigOutput
"bar" config.priorities .
/raw.nix
403 '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.' \
405 .
/declare-set.nix .
/declare-enable-nested.nix
407 # Options: accidental use of an option-type instead of option (or other tagged type; unlikely)
408 checkConfigError
'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
409 checkConfigError
'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
410 checkConfigError
'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
412 # Check that that merging of option collisions doesn't depend on type being set
413 checkConfigError
'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
415 # Test that types.optionType merges types correctly
416 checkConfigOutput
'^10$' config.theOption.int .
/optionTypeMerging.nix
417 checkConfigOutput
'^"hello"$' config.theOption.str .
/optionTypeMerging.nix
419 # Test that types.optionType correctly annotates option locations
420 checkConfigError
'The option .theOption.nested. in .other.nix. is already declared in .optionTypeFile.nix.' config.theOption.nested .
/optionTypeFile.nix
422 # Test that types.optionType leaves types untouched as long as they don't need to be merged
423 checkConfigOutput
'ok' config.freeformItems.foo.bar .
/adhoc-freeformType-survives-type-merge.nix
425 # Anonymous submodules don't get nixed by import resolution/deduplication
426 # because of an `extendModules` bug, issue 168767.
427 checkConfigOutput
'^1$' config.sub.specialisation.value .
/extendModules-168767-imports.nix
429 # Class checks, evalModules
430 checkConfigOutput
'^{ }$' config.ok.config .
/class-check.nix
431 checkConfigOutput
'"nixos"' config.ok.class .
/class-check.nix
432 checkConfigError
'The module .*/module-class-is-darwin.nix was imported into nixos instead of darwin.' config.fail.config .
/class-check.nix
433 checkConfigError
'The module foo.nix#darwinModules.default was imported into nixos instead of darwin.' config.fail-anon.config .
/class-check.nix
435 # Class checks, submoduleWith
436 checkConfigOutput
'^{ }$' config.sub.nixosOk .
/class-check.nix
437 checkConfigError
'The module .*/module-class-is-darwin.nix was imported into nixos instead of darwin.' config.sub.nixosFail.config .
/class-check.nix
439 # submoduleWith type merge with different class
440 checkConfigError
'A submoduleWith option is declared multiple times with conflicting class values "darwin" and "nixos".' config.sub.mergeFail.config .
/class-check.nix
443 checkConfigError
'Could not load a value as a module, because it is of type "flake", in file .*/module-imports-_type-check.nix' config.ok.config .
/module-imports-_type-check.nix
444 checkConfigOutput
'^true$' "$@" config.
enable .
/declare-enable.nix .
/define-enable-with-top-level-mkIf.nix
445 checkConfigError
'Could not load a value as a module, because it is of type "configuration", in file .*/import-configuration.nix.*please only import the modules that make up the configuration.*' config .
/import-configuration.nix
447 # doRename works when `warnings` does not exist.
448 checkConfigOutput
'^1234$' config.c.d.e .
/doRename-basic.nix
449 # doRename adds a warning.
450 checkConfigOutput
'^"The option `a\.b. defined in `.*/doRename-warnings\.nix. has been renamed to `c\.d\.e.\."$' \
452 .
/doRename-warnings.nix
454 # Anonymous modules get deduplicated by key
455 checkConfigOutput
'^"pear"$' config.once.raw .
/merge-module-with-key.nix
456 checkConfigOutput
'^"pear\\npear"$' config.twice.raw .
/merge-module-with-key.nix
458 # Declaration positions
459 # Line should be present for direct options
460 checkConfigOutput
'^10$' options.imported.line10.declarationPositions
.0.line .
/declaration-positions.nix
461 checkConfigOutput
'/declaration-positions.nix"$' options.imported.line10.declarationPositions
.0.
file .
/declaration-positions.nix
462 # Generated options may not have line numbers but they will at least get the
464 checkConfigOutput
'/declaration-positions.nix"$' options.generated.line18.declarationPositions
.0.
file .
/declaration-positions.nix
465 checkConfigOutput
'^null$' options.generated.line18.declarationPositions
.0.line .
/declaration-positions.nix
466 # Submodules don't break it
467 checkConfigOutput
'^39$' config.submoduleLine34.submodDeclLine39.0.line .
/declaration-positions.nix
468 checkConfigOutput
'/declaration-positions.nix"$' config.submoduleLine34.submodDeclLine39.0.
file .
/declaration-positions.nix
469 # New options under freeform submodules get collected into the parent submodule
470 # (consistent with .declarations behaviour, but weird; notably appears in system.build)
471 checkConfigOutput
'^34|23$' options.submoduleLine34.declarationPositions
.0.line .
/declaration-positions.nix
472 checkConfigOutput
'^34|23$' options.submoduleLine34.declarationPositions
.1.line .
/declaration-positions.nix
473 # nested options work
474 checkConfigOutput
'^30$' options.nested.nestedLine30.declarationPositions
.0.line .
/declaration-positions.nix
477 ====== module tests ======
482 if [ "$fail" -ne 0 ]; then