uboot: (firmwareOdroidC2/C4) don't invoke patch tool, use patches = [] instead
https://github.com/NixOS/nixpkgs/blob/master/pkgs/stdenv/generic/setup.sh#L948 this can do it nicely. Signed-off-by: Anton Arapov <anton@deadbeef.mx>
This commit is contained in:
commit
56de2bcd43
30691 changed files with 3076956 additions and 0 deletions
7
lib/tests/check-eval.nix
Normal file
7
lib/tests/check-eval.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Throws an error if any of our lib tests fail.
|
||||
|
||||
let tests = [ "misc" "systems" ];
|
||||
all = builtins.concatLists (map (f: import (./. + "/${f}.nix")) tests);
|
||||
in if all == []
|
||||
then null
|
||||
else throw (builtins.toJSON all)
|
||||
80
lib/tests/maintainers.nix
Normal file
80
lib/tests/maintainers.nix
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
# to run these tests (and the others)
|
||||
# nix-build nixpkgs/lib/tests/release.nix
|
||||
{ # The pkgs used for dependencies for the testing itself
|
||||
pkgs
|
||||
, lib
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (lib) types;
|
||||
|
||||
maintainerModule = { config, ... }: {
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
email = lib.mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
matrix = lib.mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
};
|
||||
github = lib.mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
};
|
||||
githubId = lib.mkOption {
|
||||
type = types.nullOr types.ints.unsigned;
|
||||
default = null;
|
||||
};
|
||||
keys = lib.mkOption {
|
||||
type = types.listOf (types.submodule {
|
||||
options.longkeyid = lib.mkOption { type = types.str; };
|
||||
options.fingerprint = lib.mkOption { type = types.str; };
|
||||
});
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
checkMaintainer = handle: uncheckedAttrs:
|
||||
let
|
||||
prefix = [ "lib" "maintainers" handle ];
|
||||
checkedAttrs = (lib.modules.evalModules {
|
||||
inherit prefix;
|
||||
modules = [
|
||||
maintainerModule
|
||||
{
|
||||
_file = toString ../../maintainers/maintainer-list.nix;
|
||||
config = uncheckedAttrs;
|
||||
}
|
||||
];
|
||||
}).config;
|
||||
|
||||
checkGithubId = lib.optional (checkedAttrs.github != null && checkedAttrs.githubId == null) ''
|
||||
echo ${lib.escapeShellArg (lib.showOption prefix)}': If `github` is specified, `githubId` must be too.'
|
||||
# Calling this too often would hit non-authenticated API limits, but this
|
||||
# shouldn't happen since such errors will get fixed rather quickly
|
||||
info=$(curl -sS https://api.github.com/users/${checkedAttrs.github})
|
||||
id=$(jq -r '.id' <<< "$info")
|
||||
echo "The GitHub ID for GitHub user ${checkedAttrs.github} is $id:"
|
||||
echo -e " githubId = $id;\n"
|
||||
'';
|
||||
in lib.deepSeq checkedAttrs checkGithubId;
|
||||
|
||||
missingGithubIds = lib.concatLists (lib.mapAttrsToList checkMaintainer lib.maintainers);
|
||||
|
||||
success = pkgs.runCommand "checked-maintainers-success" {} ">$out";
|
||||
|
||||
failure = pkgs.runCommand "checked-maintainers-failure" {
|
||||
nativeBuildInputs = [ pkgs.curl pkgs.jq ];
|
||||
outputHash = "sha256:${lib.fakeSha256}";
|
||||
outputHAlgo = "sha256";
|
||||
outputHashMode = "flat";
|
||||
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
|
||||
} ''
|
||||
${lib.concatStringsSep "\n" missingGithubIds}
|
||||
exit 1
|
||||
'';
|
||||
in if missingGithubIds == [] then success else failure
|
||||
1209
lib/tests/misc.nix
Normal file
1209
lib/tests/misc.nix
Normal file
File diff suppressed because it is too large
Load diff
345
lib/tests/modules.sh
Executable file
345
lib/tests/modules.sh
Executable file
|
|
@ -0,0 +1,345 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# This script is used to test that the module system is working as expected.
|
||||
# By default it test the version of nixpkgs which is defined in the NIX_PATH.
|
||||
|
||||
set -o errexit -o noclobber -o nounset -o pipefail
|
||||
shopt -s failglob inherit_errexit
|
||||
|
||||
# https://stackoverflow.com/a/246128/6605742
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
|
||||
cd "$DIR"/modules
|
||||
|
||||
pass=0
|
||||
fail=0
|
||||
|
||||
evalConfig() {
|
||||
local attr=$1
|
||||
shift
|
||||
local script="import ./default.nix { modules = [ $* ];}"
|
||||
nix-instantiate --timeout 1 -E "$script" -A "$attr" --eval-only --show-trace --read-write-mode
|
||||
}
|
||||
|
||||
reportFailure() {
|
||||
local attr=$1
|
||||
shift
|
||||
local script="import ./default.nix { modules = [ $* ];}"
|
||||
echo 2>&1 "$ nix-instantiate -E '$script' -A '$attr' --eval-only"
|
||||
evalConfig "$attr" "$@" || true
|
||||
((++fail))
|
||||
}
|
||||
|
||||
checkConfigOutput() {
|
||||
local outputContains=$1
|
||||
shift
|
||||
if evalConfig "$@" 2>/dev/null | grep --silent "$outputContains" ; then
|
||||
((++pass))
|
||||
else
|
||||
echo 2>&1 "error: Expected result matching '$outputContains', while evaluating"
|
||||
reportFailure "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
checkConfigError() {
|
||||
local errorContains=$1
|
||||
local err=""
|
||||
shift
|
||||
if err="$(evalConfig "$@" 2>&1 >/dev/null)"; then
|
||||
echo 2>&1 "error: Expected error code, got exit code 0, while evaluating"
|
||||
reportFailure "$@"
|
||||
else
|
||||
if echo "$err" | grep -zP --silent "$errorContains" ; then
|
||||
((++pass))
|
||||
else
|
||||
echo 2>&1 "error: Expected error matching '$errorContains', while evaluating"
|
||||
reportFailure "$@"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Check boolean option.
|
||||
checkConfigOutput '^false$' config.enable ./declare-enable.nix
|
||||
checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./define-enable.nix
|
||||
|
||||
checkConfigOutput '^1$' config.bare-submodule.nested ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix
|
||||
checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix
|
||||
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
|
||||
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
|
||||
checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix ./define-shorthandOnlyDefinesConfig-true.nix
|
||||
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
|
||||
|
||||
# Check integer types.
|
||||
# unsigned
|
||||
checkConfigOutput '^42$' config.value ./declare-int-unsigned-value.nix ./define-value-int-positive.nix
|
||||
checkConfigError 'A definition for option .* is not of type.*unsigned integer.*. Definition values:\n\s*- In .*: -23' config.value ./declare-int-unsigned-value.nix ./define-value-int-negative.nix
|
||||
# positive
|
||||
checkConfigError 'A definition for option .* is not of type.*positive integer.*. Definition values:\n\s*- In .*: 0' config.value ./declare-int-positive-value.nix ./define-value-int-zero.nix
|
||||
# between
|
||||
checkConfigOutput '^42$' config.value ./declare-int-between-value.nix ./define-value-int-positive.nix
|
||||
checkConfigError 'A definition for option .* is not of type.*between.*-21 and 43.*inclusive.*. Definition values:\n\s*- In .*: -23' config.value ./declare-int-between-value.nix ./define-value-int-negative.nix
|
||||
|
||||
# Check either types
|
||||
# types.either
|
||||
checkConfigOutput '^42$' config.value ./declare-either.nix ./define-value-int-positive.nix
|
||||
checkConfigOutput '^"24"$' config.value ./declare-either.nix ./define-value-string.nix
|
||||
# types.oneOf
|
||||
checkConfigOutput '^42$' config.value ./declare-oneOf.nix ./define-value-int-positive.nix
|
||||
checkConfigOutput '^\[ \]$' config.value ./declare-oneOf.nix ./define-value-list.nix
|
||||
checkConfigOutput '^"24"$' config.value ./declare-oneOf.nix ./define-value-string.nix
|
||||
|
||||
# Check mkForce without submodules.
|
||||
set -- config.enable ./declare-enable.nix ./define-enable.nix
|
||||
checkConfigOutput '^true$' "$@"
|
||||
checkConfigOutput '^false$' "$@" ./define-force-enable.nix
|
||||
checkConfigOutput '^false$' "$@" ./define-enable-force.nix
|
||||
|
||||
# Check mkForce with option and submodules.
|
||||
checkConfigError 'attribute .*foo.* .* not found' config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix
|
||||
checkConfigOutput '^false$' config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix
|
||||
set -- config.attrsOfSub.foo.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo-enable.nix
|
||||
checkConfigOutput '^true$' "$@"
|
||||
checkConfigOutput '^false$' "$@" ./define-force-attrsOfSub-foo-enable.nix
|
||||
checkConfigOutput '^false$' "$@" ./define-attrsOfSub-force-foo-enable.nix
|
||||
checkConfigOutput '^false$' "$@" ./define-attrsOfSub-foo-force-enable.nix
|
||||
checkConfigOutput '^false$' "$@" ./define-attrsOfSub-foo-enable-force.nix
|
||||
|
||||
# Check overriding effect of mkForce on submodule definitions.
|
||||
checkConfigError 'attribute .*bar.* .* not found' config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix
|
||||
checkConfigOutput '^false$' config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix ./define-attrsOfSub-bar.nix
|
||||
set -- config.attrsOfSub.bar.enable ./declare-attrsOfSub-any-enable.nix ./define-attrsOfSub-foo.nix ./define-attrsOfSub-bar-enable.nix
|
||||
checkConfigOutput '^true$' "$@"
|
||||
checkConfigError 'attribute .*bar.* .* not found' "$@" ./define-force-attrsOfSub-foo-enable.nix
|
||||
checkConfigError 'attribute .*bar.* .* not found' "$@" ./define-attrsOfSub-force-foo-enable.nix
|
||||
checkConfigOutput '^true$' "$@" ./define-attrsOfSub-foo-force-enable.nix
|
||||
checkConfigOutput '^true$' "$@" ./define-attrsOfSub-foo-enable-force.nix
|
||||
|
||||
# Check mkIf with submodules.
|
||||
checkConfigError 'attribute .*foo.* .* not found' config.attrsOfSub.foo.enable ./declare-enable.nix ./declare-attrsOfSub-any-enable.nix
|
||||
set -- config.attrsOfSub.foo.enable ./declare-enable.nix ./declare-attrsOfSub-any-enable.nix
|
||||
checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-if-attrsOfSub-foo-enable.nix
|
||||
checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-attrsOfSub-if-foo-enable.nix
|
||||
checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-attrsOfSub-foo-if-enable.nix
|
||||
checkConfigOutput '^false$' "$@" ./define-attrsOfSub-foo-enable-if.nix
|
||||
checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-if-attrsOfSub-foo-enable.nix
|
||||
checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-attrsOfSub-if-foo-enable.nix
|
||||
checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-attrsOfSub-foo-if-enable.nix
|
||||
checkConfigOutput '^true$' "$@" ./define-enable.nix ./define-attrsOfSub-foo-enable-if.nix
|
||||
|
||||
# Check disabledModules with config definitions and option declarations.
|
||||
set -- config.enable ./define-enable.nix ./declare-enable.nix
|
||||
checkConfigOutput '^true$' "$@"
|
||||
checkConfigOutput '^false$' "$@" ./disable-define-enable.nix
|
||||
checkConfigError "The option .*enable.* does not exist. Definition values:\n\s*- In .*: true" "$@" ./disable-declare-enable.nix
|
||||
checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-define-enable.nix ./disable-declare-enable.nix
|
||||
checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-enable-modules.nix
|
||||
|
||||
# Check _module.args.
|
||||
set -- config.enable ./declare-enable.nix ./define-enable-with-custom-arg.nix
|
||||
checkConfigError 'while evaluating the module argument .*custom.* in .*define-enable-with-custom-arg.nix.*:' "$@"
|
||||
checkConfigOutput '^true$' "$@" ./define-_module-args-custom.nix
|
||||
|
||||
# Check that using _module.args on imports cause infinite recursions, with
|
||||
# the proper error context.
|
||||
set -- "$@" ./define-_module-args-custom.nix ./import-custom-arg.nix
|
||||
checkConfigError 'while evaluating the module argument .*custom.* in .*import-custom-arg.nix.*:' "$@"
|
||||
checkConfigError 'infinite recursion encountered' "$@"
|
||||
|
||||
# Check _module.check.
|
||||
set -- config.enable ./declare-enable.nix ./define-enable.nix ./define-attrsOfSub-foo.nix
|
||||
checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*' "$@"
|
||||
checkConfigOutput '^true$' "$@" ./define-module-check.nix
|
||||
|
||||
# Check coerced value.
|
||||
checkConfigOutput '^"42"$' config.value ./declare-coerced-value.nix
|
||||
checkConfigOutput '^"24"$' config.value ./declare-coerced-value.nix ./define-value-string.nix
|
||||
checkConfigError 'A definition for option .* is not.*string or signed integer convertible to it.*. Definition values:\n\s*- In .*: \[ \]' config.value ./declare-coerced-value.nix ./define-value-list.nix
|
||||
|
||||
# Check coerced value with unsound coercion
|
||||
checkConfigOutput '^12$' config.value ./declare-coerced-value-unsound.nix
|
||||
checkConfigError 'A definition for option .* is not of type .*. Definition values:\n\s*- In .*: "1000"' config.value ./declare-coerced-value-unsound.nix ./define-value-string-bigint.nix
|
||||
checkConfigError 'json.exception.parse_error' config.value ./declare-coerced-value-unsound.nix ./define-value-string-arbitrary.nix
|
||||
|
||||
# Check mkAliasOptionModule.
|
||||
checkConfigOutput '^true$' config.enable ./alias-with-priority.nix
|
||||
checkConfigOutput '^true$' config.enableAlias ./alias-with-priority.nix
|
||||
checkConfigOutput '^false$' config.enable ./alias-with-priority-can-override.nix
|
||||
checkConfigOutput '^false$' config.enableAlias ./alias-with-priority-can-override.nix
|
||||
|
||||
# submoduleWith
|
||||
|
||||
## specialArgs should work
|
||||
checkConfigOutput '^"foo"$' config.submodule.foo ./declare-submoduleWith-special.nix
|
||||
|
||||
## shorthandOnlyDefines config behaves as expected
|
||||
checkConfigOutput '^true$' config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-shorthand.nix
|
||||
checkConfigError 'is not of type `boolean' config.submodule.config ./declare-submoduleWith-shorthand.nix ./define-submoduleWith-noshorthand.nix
|
||||
checkConfigError "You're trying to declare a value of type \`bool'\n\s*rather than an attribute-set for the option" config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-shorthand.nix
|
||||
checkConfigOutput '^true$' config.submodule.config ./declare-submoduleWith-noshorthand.nix ./define-submoduleWith-noshorthand.nix
|
||||
|
||||
## submoduleWith should merge all modules in one swoop
|
||||
checkConfigOutput '^true$' config.submodule.inner ./declare-submoduleWith-modules.nix
|
||||
checkConfigOutput '^true$' config.submodule.outer ./declare-submoduleWith-modules.nix
|
||||
# Should also be able to evaluate the type name (which evaluates freeformType,
|
||||
# which evaluates all the modules defined by the type)
|
||||
checkConfigOutput '^"submodule"$' options.submodule.type.description ./declare-submoduleWith-modules.nix
|
||||
|
||||
## submodules can be declared using (evalModules {...}).type
|
||||
checkConfigOutput '^true$' config.submodule.inner ./declare-submodule-via-evalModules.nix
|
||||
checkConfigOutput '^true$' config.submodule.outer ./declare-submodule-via-evalModules.nix
|
||||
# Should also be able to evaluate the type name (which evaluates freeformType,
|
||||
# which evaluates all the modules defined by the type)
|
||||
checkConfigOutput '^"submodule"$' options.submodule.type.description ./declare-submodule-via-evalModules.nix
|
||||
|
||||
## Paths should be allowed as values and work as expected
|
||||
checkConfigOutput '^true$' config.submodule.enable ./declare-submoduleWith-path.nix
|
||||
|
||||
# Check that disabledModules works recursively and correctly
|
||||
checkConfigOutput '^true$' config.enable ./disable-recursive/main.nix
|
||||
checkConfigOutput '^true$' config.enable ./disable-recursive/{main.nix,disable-foo.nix}
|
||||
checkConfigOutput '^true$' config.enable ./disable-recursive/{main.nix,disable-bar.nix}
|
||||
checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./disable-recursive/{main.nix,disable-foo.nix,disable-bar.nix}
|
||||
|
||||
# Check that imports can depend on derivations
|
||||
checkConfigOutput '^true$' config.enable ./import-from-store.nix
|
||||
|
||||
# Check that configs can be conditional on option existence
|
||||
checkConfigOutput '^true$' config.enable ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix
|
||||
checkConfigOutput '^360$' config.value ./define-option-dependently.nix ./declare-enable.nix ./declare-int-positive-value.nix
|
||||
checkConfigOutput '^7$' config.value ./define-option-dependently.nix ./declare-int-positive-value.nix
|
||||
checkConfigOutput '^true$' config.set.enable ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix
|
||||
checkConfigOutput '^360$' config.set.value ./define-option-dependently-nested.nix ./declare-enable-nested.nix ./declare-int-positive-value-nested.nix
|
||||
checkConfigOutput '^7$' config.set.value ./define-option-dependently-nested.nix ./declare-int-positive-value-nested.nix
|
||||
|
||||
# Check attrsOf and lazyAttrsOf. Only lazyAttrsOf should be lazy, and only
|
||||
# attrsOf should work with conditional definitions
|
||||
# In addition, lazyAttrsOf should honor an options emptyValue
|
||||
checkConfigError "is not lazy" config.isLazy ./declare-attrsOf.nix ./attrsOf-lazy-check.nix
|
||||
checkConfigOutput '^true$' config.isLazy ./declare-lazyAttrsOf.nix ./attrsOf-lazy-check.nix
|
||||
checkConfigOutput '^true$' config.conditionalWorks ./declare-attrsOf.nix ./attrsOf-conditional-check.nix
|
||||
checkConfigOutput '^false$' config.conditionalWorks ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix
|
||||
checkConfigOutput '^"empty"$' config.value.foo ./declare-lazyAttrsOf.nix ./attrsOf-conditional-check.nix
|
||||
|
||||
|
||||
# Even with multiple assignments, a type error should be thrown if any of them aren't valid
|
||||
checkConfigError 'A definition for option .* is not of type .*' \
|
||||
config.value ./declare-int-unsigned-value.nix ./define-value-list.nix ./define-value-int-positive.nix
|
||||
|
||||
## Freeform modules
|
||||
# Assigning without a declared option should work
|
||||
checkConfigOutput '^"24"$' config.value ./freeform-attrsOf.nix ./define-value-string.nix
|
||||
# No freeform assigments shouldn't make it error
|
||||
checkConfigOutput '^{ }$' config ./freeform-attrsOf.nix
|
||||
# but only if the type matches
|
||||
checkConfigError 'A definition for option .* is not of type .*' config.value ./freeform-attrsOf.nix ./define-value-list.nix
|
||||
# and properties should be applied
|
||||
checkConfigOutput '^"yes"$' config.value ./freeform-attrsOf.nix ./define-value-string-properties.nix
|
||||
# Options should still be declarable, and be able to have a type that doesn't match the freeform type
|
||||
checkConfigOutput '^false$' config.enable ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix
|
||||
checkConfigOutput '^"24"$' config.value ./freeform-attrsOf.nix ./define-value-string.nix ./declare-enable.nix
|
||||
# and this should work too with nested values
|
||||
checkConfigOutput '^false$' config.nest.foo ./freeform-attrsOf.nix ./freeform-nested.nix
|
||||
checkConfigOutput '^"bar"$' config.nest.bar ./freeform-attrsOf.nix ./freeform-nested.nix
|
||||
# Check whether a declared option can depend on an freeform-typed one
|
||||
checkConfigOutput '^null$' config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix
|
||||
checkConfigOutput '^"24"$' config.foo ./freeform-attrsOf.nix ./freeform-str-dep-unstr.nix ./define-value-string.nix
|
||||
# Check whether an freeform-typed value can depend on a declared option, this can only work with lazyAttrsOf
|
||||
checkConfigError 'infinite recursion encountered' config.foo ./freeform-attrsOf.nix ./freeform-unstr-dep-str.nix
|
||||
checkConfigError 'The option .* is used but not defined' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix
|
||||
checkConfigOutput '^"24"$' config.foo ./freeform-lazyAttrsOf.nix ./freeform-unstr-dep-str.nix ./define-value-string.nix
|
||||
# submodules in freeformTypes should have their locations annotated
|
||||
checkConfigOutput '/freeform-submodules.nix"$' config.fooDeclarations.0 ./freeform-submodules.nix
|
||||
# freeformTypes can get merged using `types.type`, including submodules
|
||||
checkConfigOutput '^10$' config.free.xxx.foo ./freeform-submodules.nix
|
||||
checkConfigOutput '^10$' config.free.yyy.bar ./freeform-submodules.nix
|
||||
|
||||
## types.anything
|
||||
# Check that attribute sets are merged recursively
|
||||
checkConfigOutput '^null$' config.value.foo ./types-anything/nested-attrs.nix
|
||||
checkConfigOutput '^null$' config.value.l1.foo ./types-anything/nested-attrs.nix
|
||||
checkConfigOutput '^null$' config.value.l1.l2.foo ./types-anything/nested-attrs.nix
|
||||
checkConfigOutput '^null$' config.value.l1.l2.l3.foo ./types-anything/nested-attrs.nix
|
||||
# Attribute sets that are coercible to strings shouldn't be recursed into
|
||||
checkConfigOutput '^"foo"$' config.value.outPath ./types-anything/attrs-coercible.nix
|
||||
# Multiple lists aren't concatenated together
|
||||
checkConfigError 'The option .* has conflicting definitions' config.value ./types-anything/lists.nix
|
||||
# Check that all equalizable atoms can be used as long as all definitions are equal
|
||||
checkConfigOutput '^0$' config.value.int ./types-anything/equal-atoms.nix
|
||||
checkConfigOutput '^false$' config.value.bool ./types-anything/equal-atoms.nix
|
||||
checkConfigOutput '^""$' config.value.string ./types-anything/equal-atoms.nix
|
||||
checkConfigOutput '^/$' config.value.path ./types-anything/equal-atoms.nix
|
||||
checkConfigOutput '^null$' config.value.null ./types-anything/equal-atoms.nix
|
||||
checkConfigOutput '^0.1$' config.value.float ./types-anything/equal-atoms.nix
|
||||
# Functions can't be merged together
|
||||
checkConfigError "The option .value.multiple-lambdas.<function body>. has conflicting option types" config.applied.multiple-lambdas ./types-anything/functions.nix
|
||||
checkConfigOutput '^<LAMBDA>$' config.value.single-lambda ./types-anything/functions.nix
|
||||
checkConfigOutput '^null$' config.applied.merging-lambdas.x ./types-anything/functions.nix
|
||||
checkConfigOutput '^null$' config.applied.merging-lambdas.y ./types-anything/functions.nix
|
||||
# Check that all mk* modifiers are applied
|
||||
checkConfigError 'attribute .* not found' config.value.mkiffalse ./types-anything/mk-mods.nix
|
||||
checkConfigOutput '^{ }$' config.value.mkiftrue ./types-anything/mk-mods.nix
|
||||
checkConfigOutput '^1$' config.value.mkdefault ./types-anything/mk-mods.nix
|
||||
checkConfigOutput '^{ }$' config.value.mkmerge ./types-anything/mk-mods.nix
|
||||
checkConfigOutput '^true$' config.value.mkbefore ./types-anything/mk-mods.nix
|
||||
checkConfigOutput '^1$' config.value.nested.foo ./types-anything/mk-mods.nix
|
||||
checkConfigOutput '^"baz"$' config.value.nested.bar.baz ./types-anything/mk-mods.nix
|
||||
|
||||
## types.functionTo
|
||||
checkConfigOutput '^"input is input"$' config.result ./functionTo/trivial.nix
|
||||
checkConfigOutput '^"a b"$' config.result ./functionTo/merging-list.nix
|
||||
checkConfigError 'A definition for option .fun.\[function body\]. is not of type .string.. Definition values:\n\s*- In .*wrong-type.nix' config.result ./functionTo/wrong-type.nix
|
||||
checkConfigOutput '^"b a"$' config.result ./functionTo/list-order.nix
|
||||
checkConfigOutput '^"a c"$' config.result ./functionTo/merging-attrs.nix
|
||||
checkConfigOutput '^"a bee"$' config.result ./functionTo/submodule-options.nix
|
||||
checkConfigOutput '^"fun.\[function body\].a fun.\[function body\].b"$' config.optionsResult ./functionTo/submodule-options.nix
|
||||
|
||||
# moduleType
|
||||
checkConfigOutput '^"a b"$' config.resultFoo ./declare-variants.nix ./define-variant.nix
|
||||
checkConfigOutput '^"a b y z"$' config.resultFooBar ./declare-variants.nix ./define-variant.nix
|
||||
checkConfigOutput '^"a b c"$' config.resultFooFoo ./declare-variants.nix ./define-variant.nix
|
||||
|
||||
## emptyValue's
|
||||
checkConfigOutput "[ ]" config.list.a ./emptyValues.nix
|
||||
checkConfigOutput "{ }" config.attrs.a ./emptyValues.nix
|
||||
checkConfigOutput "null" config.null.a ./emptyValues.nix
|
||||
checkConfigOutput "{ }" config.submodule.a ./emptyValues.nix
|
||||
# These types don't have empty values
|
||||
checkConfigError 'The option .int.a. is used but not defined' config.int.a ./emptyValues.nix
|
||||
checkConfigError 'The option .nonEmptyList.a. is used but not defined' config.nonEmptyList.a ./emptyValues.nix
|
||||
|
||||
## types.raw
|
||||
checkConfigOutput "{ foo = <CODE>; }" config.unprocessedNesting ./raw.nix
|
||||
checkConfigOutput "10" config.processedToplevel ./raw.nix
|
||||
checkConfigError "The option .multiple. is defined multiple times" config.multiple ./raw.nix
|
||||
checkConfigOutput "bar" config.priorities ./raw.nix
|
||||
|
||||
## Option collision
|
||||
checkConfigError \
|
||||
'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.' \
|
||||
config.set \
|
||||
./declare-set.nix ./declare-enable-nested.nix
|
||||
|
||||
# Test that types.optionType merges types correctly
|
||||
checkConfigOutput '^10$' config.theOption.int ./optionTypeMerging.nix
|
||||
checkConfigOutput '^"hello"$' config.theOption.str ./optionTypeMerging.nix
|
||||
|
||||
# Test that types.optionType correctly annotates option locations
|
||||
checkConfigError 'The option .theOption.nested. in .other.nix. is already declared in .optionTypeFile.nix.' config.theOption.nested ./optionTypeFile.nix
|
||||
|
||||
# Test that types.optionType leaves types untouched as long as they don't need to be merged
|
||||
checkConfigOutput 'ok' config.freeformItems.foo.bar ./adhoc-freeformType-survives-type-merge.nix
|
||||
|
||||
# Anonymous submodules don't get nixed by import resolution/deduplication
|
||||
# because of an `extendModules` bug, issue 168767.
|
||||
checkConfigOutput '^1$' config.sub.specialisation.value ./extendModules-168767-imports.nix
|
||||
|
||||
cat <<EOF
|
||||
====== module tests ======
|
||||
$pass Pass
|
||||
$fail Fail
|
||||
EOF
|
||||
|
||||
if [ "$fail" -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
14
lib/tests/modules/adhoc-freeformType-survives-type-merge.nix
Normal file
14
lib/tests/modules/adhoc-freeformType-survives-type-merge.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{ lib, ... }: {
|
||||
options.dummy = lib.mkOption { type = lib.types.anything; default = {}; };
|
||||
freeformType =
|
||||
let
|
||||
a = lib.types.attrsOf (lib.types.submodule { options.bar = lib.mkOption { }; });
|
||||
in
|
||||
# modifying types like this breaks type merging.
|
||||
# This test makes sure that type merging is not performed when only a single declaration exists.
|
||||
# Don't modify types in practice!
|
||||
a // {
|
||||
merge = loc: defs: { freeformItems = a.merge loc defs; };
|
||||
};
|
||||
config.foo.bar = "ok";
|
||||
}
|
||||
55
lib/tests/modules/alias-with-priority-can-override.nix
Normal file
55
lib/tests/modules/alias-with-priority-can-override.nix
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
# This is a test to show that mkAliasOptionModule sets the priority correctly
|
||||
# for aliased options.
|
||||
#
|
||||
# This test shows that an alias with a high priority is able to override
|
||||
# a non-aliased option.
|
||||
|
||||
{ config, lib, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
options = {
|
||||
# A simple boolean option that can be enabled or disabled.
|
||||
enable = lib.mkOption {
|
||||
type = types.nullOr types.bool;
|
||||
default = null;
|
||||
example = true;
|
||||
description = ''
|
||||
Some descriptive text
|
||||
'';
|
||||
};
|
||||
|
||||
# mkAliasOptionModule sets warnings, so this has to be defined.
|
||||
warnings = mkOption {
|
||||
internal = true;
|
||||
default = [];
|
||||
type = types.listOf types.str;
|
||||
example = [ "The `foo' service is deprecated and will go away soon!" ];
|
||||
description = ''
|
||||
This option allows modules to show warnings to users during
|
||||
the evaluation of the system configuration.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
imports = [
|
||||
# Create an alias for the "enable" option.
|
||||
(mkAliasOptionModule [ "enableAlias" ] [ "enable" ])
|
||||
|
||||
# Disable the aliased option with a high priority so it
|
||||
# should override the next import.
|
||||
( { config, lib, ... }:
|
||||
{
|
||||
enableAlias = lib.mkForce false;
|
||||
}
|
||||
)
|
||||
|
||||
# Enable the normal (non-aliased) option.
|
||||
( { config, lib, ... }:
|
||||
{
|
||||
enable = true;
|
||||
}
|
||||
)
|
||||
];
|
||||
}
|
||||
55
lib/tests/modules/alias-with-priority.nix
Normal file
55
lib/tests/modules/alias-with-priority.nix
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
# This is a test to show that mkAliasOptionModule sets the priority correctly
|
||||
# for aliased options.
|
||||
#
|
||||
# This test shows that an alias with a low priority is able to be overridden
|
||||
# with a non-aliased option.
|
||||
|
||||
{ config, lib, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
options = {
|
||||
# A simple boolean option that can be enabled or disabled.
|
||||
enable = lib.mkOption {
|
||||
type = types.nullOr types.bool;
|
||||
default = null;
|
||||
example = true;
|
||||
description = ''
|
||||
Some descriptive text
|
||||
'';
|
||||
};
|
||||
|
||||
# mkAliasOptionModule sets warnings, so this has to be defined.
|
||||
warnings = mkOption {
|
||||
internal = true;
|
||||
default = [];
|
||||
type = types.listOf types.str;
|
||||
example = [ "The `foo' service is deprecated and will go away soon!" ];
|
||||
description = ''
|
||||
This option allows modules to show warnings to users during
|
||||
the evaluation of the system configuration.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
imports = [
|
||||
# Create an alias for the "enable" option.
|
||||
(mkAliasOptionModule [ "enableAlias" ] [ "enable" ])
|
||||
|
||||
# Disable the aliased option, but with a default (low) priority so it
|
||||
# should be able to be overridden by the next import.
|
||||
( { config, lib, ... }:
|
||||
{
|
||||
enableAlias = lib.mkDefault false;
|
||||
}
|
||||
)
|
||||
|
||||
# Enable the normal (non-aliased) option.
|
||||
( { config, lib, ... }:
|
||||
{
|
||||
enable = true;
|
||||
}
|
||||
)
|
||||
];
|
||||
}
|
||||
7
lib/tests/modules/attrsOf-conditional-check.nix
Normal file
7
lib/tests/modules/attrsOf-conditional-check.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{ lib, config, ... }: {
|
||||
options.conditionalWorks = lib.mkOption {
|
||||
default = ! config.value ? foo;
|
||||
};
|
||||
|
||||
config.value.foo = lib.mkIf false "should not be defined";
|
||||
}
|
||||
7
lib/tests/modules/attrsOf-lazy-check.nix
Normal file
7
lib/tests/modules/attrsOf-lazy-check.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{ lib, config, ... }: {
|
||||
options.isLazy = lib.mkOption {
|
||||
default = ! config.value ? foo;
|
||||
};
|
||||
|
||||
config.value.bar = throw "is not lazy";
|
||||
}
|
||||
13
lib/tests/modules/declare-attrsOf.nix
Normal file
13
lib/tests/modules/declare-attrsOf.nix
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
deathtrapArgs = lib.mapAttrs
|
||||
(k: _: throw "The module system is too strict, accessing an unused option's ${k} mkOption-attribute.")
|
||||
(lib.functionArgs lib.mkOption);
|
||||
in
|
||||
{
|
||||
options.value = lib.mkOption {
|
||||
type = lib.types.attrsOf lib.types.str;
|
||||
default = {};
|
||||
};
|
||||
options.testing-laziness-so-don't-read-me = lib.mkOption deathtrapArgs;
|
||||
}
|
||||
29
lib/tests/modules/declare-attrsOfSub-any-enable.nix
Normal file
29
lib/tests/modules/declare-attrsOfSub-any-enable.nix
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{ lib, ... }:
|
||||
|
||||
let
|
||||
submod = { ... }: {
|
||||
options = {
|
||||
enable = lib.mkOption {
|
||||
default = false;
|
||||
example = true;
|
||||
type = lib.types.bool;
|
||||
description = ''
|
||||
Some descriptive text
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
|
||||
{
|
||||
options = {
|
||||
attrsOfSub = lib.mkOption {
|
||||
default = {};
|
||||
example = {};
|
||||
type = lib.types.attrsOf (lib.types.submodule [ submod ]);
|
||||
description = ''
|
||||
Some descriptive text
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
in
|
||||
{
|
||||
options.bare-submodule.deep = mkOption {
|
||||
type = types.int;
|
||||
default = 2;
|
||||
};
|
||||
}
|
||||
10
lib/tests/modules/declare-bare-submodule-deep-option.nix
Normal file
10
lib/tests/modules/declare-bare-submodule-deep-option.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
in
|
||||
{
|
||||
options.bare-submodule.deep = mkOption {
|
||||
type = types.int;
|
||||
default = 2;
|
||||
};
|
||||
}
|
||||
19
lib/tests/modules/declare-bare-submodule-nested-option.nix
Normal file
19
lib/tests/modules/declare-bare-submodule-nested-option.nix
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{ config, lib, ... }:
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
in
|
||||
{
|
||||
options.bare-submodule = mkOption {
|
||||
type = types.submoduleWith {
|
||||
shorthandOnlyDefinesConfig = config.shorthandOnlyDefinesConfig;
|
||||
modules = [
|
||||
{
|
||||
options.nested = mkOption {
|
||||
type = types.int;
|
||||
default = 1;
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
18
lib/tests/modules/declare-bare-submodule.nix
Normal file
18
lib/tests/modules/declare-bare-submodule.nix
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{ config, lib, ... }:
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
in
|
||||
{
|
||||
options.bare-submodule = mkOption {
|
||||
type = types.submoduleWith {
|
||||
modules = [ ];
|
||||
shorthandOnlyDefinesConfig = config.shorthandOnlyDefinesConfig;
|
||||
};
|
||||
default = {};
|
||||
};
|
||||
|
||||
# config-dependent options: won't recommend, but useful for making this test parameterized
|
||||
options.shorthandOnlyDefinesConfig = mkOption {
|
||||
default = false;
|
||||
};
|
||||
}
|
||||
10
lib/tests/modules/declare-coerced-value-unsound.nix
Normal file
10
lib/tests/modules/declare-coerced-value-unsound.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
options = {
|
||||
value = lib.mkOption {
|
||||
default = "12";
|
||||
type = lib.types.coercedTo lib.types.str lib.toInt lib.types.ints.s8;
|
||||
};
|
||||
};
|
||||
}
|
||||
10
lib/tests/modules/declare-coerced-value.nix
Normal file
10
lib/tests/modules/declare-coerced-value.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
options = {
|
||||
value = lib.mkOption {
|
||||
default = 42;
|
||||
type = lib.types.coercedTo lib.types.int builtins.toString lib.types.str;
|
||||
};
|
||||
};
|
||||
}
|
||||
5
lib/tests/modules/declare-either.nix
Normal file
5
lib/tests/modules/declare-either.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{ lib, ... }: {
|
||||
options.value = lib.mkOption {
|
||||
type = lib.types.either lib.types.int lib.types.str;
|
||||
};
|
||||
}
|
||||
14
lib/tests/modules/declare-enable-nested.nix
Normal file
14
lib/tests/modules/declare-enable-nested.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
options.set = {
|
||||
enable = lib.mkOption {
|
||||
default = false;
|
||||
example = true;
|
||||
type = lib.types.bool;
|
||||
description = ''
|
||||
Some descriptive text
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
14
lib/tests/modules/declare-enable.nix
Normal file
14
lib/tests/modules/declare-enable.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
options = {
|
||||
enable = lib.mkOption {
|
||||
default = false;
|
||||
example = true;
|
||||
type = lib.types.bool;
|
||||
description = ''
|
||||
Some descriptive text
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
9
lib/tests/modules/declare-int-between-value.nix
Normal file
9
lib/tests/modules/declare-int-between-value.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
options = {
|
||||
value = lib.mkOption {
|
||||
type = lib.types.ints.between (-21) 43;
|
||||
};
|
||||
};
|
||||
}
|
||||
9
lib/tests/modules/declare-int-positive-value-nested.nix
Normal file
9
lib/tests/modules/declare-int-positive-value-nested.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
options.set = {
|
||||
value = lib.mkOption {
|
||||
type = lib.types.ints.positive;
|
||||
};
|
||||
};
|
||||
}
|
||||
9
lib/tests/modules/declare-int-positive-value.nix
Normal file
9
lib/tests/modules/declare-int-positive-value.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
options = {
|
||||
value = lib.mkOption {
|
||||
type = lib.types.ints.positive;
|
||||
};
|
||||
};
|
||||
}
|
||||
9
lib/tests/modules/declare-int-unsigned-value.nix
Normal file
9
lib/tests/modules/declare-int-unsigned-value.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
options = {
|
||||
value = lib.mkOption {
|
||||
type = lib.types.ints.unsigned;
|
||||
};
|
||||
};
|
||||
}
|
||||
6
lib/tests/modules/declare-lazyAttrsOf.nix
Normal file
6
lib/tests/modules/declare-lazyAttrsOf.nix
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{ lib, ... }: {
|
||||
options.value = lib.mkOption {
|
||||
type = lib.types.lazyAttrsOf (lib.types.str // { emptyValue.value = "empty"; });
|
||||
default = {};
|
||||
};
|
||||
}
|
||||
9
lib/tests/modules/declare-oneOf.nix
Normal file
9
lib/tests/modules/declare-oneOf.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{ lib, ... }: {
|
||||
options.value = lib.mkOption {
|
||||
type = lib.types.oneOf [
|
||||
lib.types.int
|
||||
(lib.types.listOf lib.types.int)
|
||||
lib.types.str
|
||||
];
|
||||
};
|
||||
}
|
||||
12
lib/tests/modules/declare-set.nix
Normal file
12
lib/tests/modules/declare-set.nix
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
options.set = lib.mkOption {
|
||||
default = { };
|
||||
example = { a = 1; };
|
||||
type = lib.types.attrsOf lib.types.int;
|
||||
description = ''
|
||||
Some descriptive text
|
||||
'';
|
||||
};
|
||||
}
|
||||
28
lib/tests/modules/declare-submodule-via-evalModules.nix
Normal file
28
lib/tests/modules/declare-submodule-via-evalModules.nix
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{ lib, ... }: {
|
||||
options.submodule = lib.mkOption {
|
||||
inherit (lib.evalModules {
|
||||
modules = [
|
||||
{
|
||||
options.inner = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
};
|
||||
}
|
||||
];
|
||||
}) type;
|
||||
default = {};
|
||||
};
|
||||
|
||||
config.submodule = lib.mkMerge [
|
||||
({ lib, ... }: {
|
||||
options.outer = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
};
|
||||
})
|
||||
{
|
||||
inner = true;
|
||||
outer = true;
|
||||
}
|
||||
];
|
||||
}
|
||||
28
lib/tests/modules/declare-submoduleWith-modules.nix
Normal file
28
lib/tests/modules/declare-submoduleWith-modules.nix
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{ lib, ... }: {
|
||||
options.submodule = lib.mkOption {
|
||||
type = lib.types.submoduleWith {
|
||||
modules = [
|
||||
{
|
||||
options.inner = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
default = {};
|
||||
};
|
||||
|
||||
config.submodule = lib.mkMerge [
|
||||
({ lib, ... }: {
|
||||
options.outer = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
};
|
||||
})
|
||||
{
|
||||
inner = true;
|
||||
outer = true;
|
||||
}
|
||||
];
|
||||
}
|
||||
13
lib/tests/modules/declare-submoduleWith-noshorthand.nix
Normal file
13
lib/tests/modules/declare-submoduleWith-noshorthand.nix
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{ lib, ... }: let
|
||||
sub.options.config = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
};
|
||||
in {
|
||||
options.submodule = lib.mkOption {
|
||||
type = lib.types.submoduleWith {
|
||||
modules = [ sub ];
|
||||
};
|
||||
default = {};
|
||||
};
|
||||
}
|
||||
12
lib/tests/modules/declare-submoduleWith-path.nix
Normal file
12
lib/tests/modules/declare-submoduleWith-path.nix
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{ lib, ... }: {
|
||||
options.submodule = lib.mkOption {
|
||||
type = lib.types.submoduleWith {
|
||||
modules = [
|
||||
./declare-enable.nix
|
||||
];
|
||||
};
|
||||
default = {};
|
||||
};
|
||||
|
||||
config.submodule = ./define-enable.nix;
|
||||
}
|
||||
14
lib/tests/modules/declare-submoduleWith-shorthand.nix
Normal file
14
lib/tests/modules/declare-submoduleWith-shorthand.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{ lib, ... }: let
|
||||
sub.options.config = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
};
|
||||
in {
|
||||
options.submodule = lib.mkOption {
|
||||
type = lib.types.submoduleWith {
|
||||
modules = [ sub ];
|
||||
shorthandOnlyDefinesConfig = true;
|
||||
};
|
||||
default = {};
|
||||
};
|
||||
}
|
||||
17
lib/tests/modules/declare-submoduleWith-special.nix
Normal file
17
lib/tests/modules/declare-submoduleWith-special.nix
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{ lib, ... }: {
|
||||
options.submodule = lib.mkOption {
|
||||
type = lib.types.submoduleWith {
|
||||
modules = [
|
||||
({ lib, ... }: {
|
||||
options.foo = lib.mkOption {
|
||||
default = lib.foo;
|
||||
};
|
||||
})
|
||||
];
|
||||
specialArgs.lib = lib // {
|
||||
foo = "foo";
|
||||
};
|
||||
};
|
||||
default = {};
|
||||
};
|
||||
}
|
||||
9
lib/tests/modules/declare-variants.nix
Normal file
9
lib/tests/modules/declare-variants.nix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{ lib, moduleType, ... }:
|
||||
let inherit (lib) mkOption types;
|
||||
in
|
||||
{
|
||||
options.variants = mkOption {
|
||||
type = types.lazyAttrsOf moduleType;
|
||||
default = {};
|
||||
};
|
||||
}
|
||||
8
lib/tests/modules/default.nix
Normal file
8
lib/tests/modules/default.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{ lib ? import ../.., modules ? [] }:
|
||||
|
||||
{
|
||||
inherit (lib.evalModules {
|
||||
inherit modules;
|
||||
specialArgs.modulesPath = ./.;
|
||||
}) config options;
|
||||
}
|
||||
7
lib/tests/modules/define-_module-args-custom.nix
Normal file
7
lib/tests/modules/define-_module-args-custom.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
config = {
|
||||
_module.args.custom = true;
|
||||
};
|
||||
}
|
||||
3
lib/tests/modules/define-attrsOfSub-bar-enable.nix
Normal file
3
lib/tests/modules/define-attrsOfSub-bar-enable.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
attrsOfSub.bar.enable = true;
|
||||
}
|
||||
3
lib/tests/modules/define-attrsOfSub-bar.nix
Normal file
3
lib/tests/modules/define-attrsOfSub-bar.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
attrsOfSub.bar = {};
|
||||
}
|
||||
5
lib/tests/modules/define-attrsOfSub-foo-enable-force.nix
Normal file
5
lib/tests/modules/define-attrsOfSub-foo-enable-force.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
attrsOfSub.foo.enable = lib.mkForce false;
|
||||
}
|
||||
5
lib/tests/modules/define-attrsOfSub-foo-enable-if.nix
Normal file
5
lib/tests/modules/define-attrsOfSub-foo-enable-if.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{ config, lib, ... }:
|
||||
|
||||
{
|
||||
attrsOfSub.foo.enable = lib.mkIf config.enable true;
|
||||
}
|
||||
3
lib/tests/modules/define-attrsOfSub-foo-enable.nix
Normal file
3
lib/tests/modules/define-attrsOfSub-foo-enable.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
attrsOfSub.foo.enable = true;
|
||||
}
|
||||
7
lib/tests/modules/define-attrsOfSub-foo-force-enable.nix
Normal file
7
lib/tests/modules/define-attrsOfSub-foo-force-enable.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
attrsOfSub.foo = lib.mkForce {
|
||||
enable = false;
|
||||
};
|
||||
}
|
||||
7
lib/tests/modules/define-attrsOfSub-foo-if-enable.nix
Normal file
7
lib/tests/modules/define-attrsOfSub-foo-if-enable.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{ config, lib, ... }:
|
||||
|
||||
{
|
||||
attrsOfSub.foo = lib.mkIf config.enable {
|
||||
enable = true;
|
||||
};
|
||||
}
|
||||
3
lib/tests/modules/define-attrsOfSub-foo.nix
Normal file
3
lib/tests/modules/define-attrsOfSub-foo.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
attrsOfSub.foo = {};
|
||||
}
|
||||
7
lib/tests/modules/define-attrsOfSub-force-foo-enable.nix
Normal file
7
lib/tests/modules/define-attrsOfSub-force-foo-enable.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
attrsOfSub = lib.mkForce {
|
||||
foo.enable = false;
|
||||
};
|
||||
}
|
||||
7
lib/tests/modules/define-attrsOfSub-if-foo-enable.nix
Normal file
7
lib/tests/modules/define-attrsOfSub-if-foo-enable.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{ config, lib, ... }:
|
||||
|
||||
{
|
||||
attrsOfSub = lib.mkIf config.enable {
|
||||
foo.enable = true;
|
||||
};
|
||||
}
|
||||
4
lib/tests/modules/define-bare-submodule-values.nix
Normal file
4
lib/tests/modules/define-bare-submodule-values.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
bare-submodule.nested = 42;
|
||||
bare-submodule.deep = 420;
|
||||
}
|
||||
5
lib/tests/modules/define-enable-force.nix
Normal file
5
lib/tests/modules/define-enable-force.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
enable = lib.mkForce false;
|
||||
}
|
||||
7
lib/tests/modules/define-enable-with-custom-arg.nix
Normal file
7
lib/tests/modules/define-enable-with-custom-arg.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{ lib, custom, ... }:
|
||||
|
||||
{
|
||||
config = {
|
||||
enable = custom;
|
||||
};
|
||||
}
|
||||
3
lib/tests/modules/define-enable.nix
Normal file
3
lib/tests/modules/define-enable.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
enable = true;
|
||||
}
|
||||
5
lib/tests/modules/define-force-attrsOfSub-foo-enable.nix
Normal file
5
lib/tests/modules/define-force-attrsOfSub-foo-enable.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{ lib, ... }:
|
||||
|
||||
lib.mkForce {
|
||||
attrsOfSub.foo.enable = false;
|
||||
}
|
||||
5
lib/tests/modules/define-force-enable.nix
Normal file
5
lib/tests/modules/define-force-enable.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{ lib, ... }:
|
||||
|
||||
lib.mkForce {
|
||||
enable = false;
|
||||
}
|
||||
5
lib/tests/modules/define-if-attrsOfSub-foo-enable.nix
Normal file
5
lib/tests/modules/define-if-attrsOfSub-foo-enable.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{ config, lib, ... }:
|
||||
|
||||
lib.mkIf config.enable {
|
||||
attrsOfSub.foo.enable = true;
|
||||
}
|
||||
3
lib/tests/modules/define-module-check.nix
Normal file
3
lib/tests/modules/define-module-check.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
_module.check = false;
|
||||
}
|
||||
16
lib/tests/modules/define-option-dependently-nested.nix
Normal file
16
lib/tests/modules/define-option-dependently-nested.nix
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{ lib, options, ... }:
|
||||
|
||||
# Some modules may be distributed separately and need to adapt to other modules
|
||||
# that are distributed and versioned separately.
|
||||
{
|
||||
|
||||
# Always defined, but the value depends on the presence of an option.
|
||||
config.set = {
|
||||
value = if options ? set.enable then 360 else 7;
|
||||
}
|
||||
# Only define if possible.
|
||||
// lib.optionalAttrs (options ? set.enable) {
|
||||
enable = true;
|
||||
};
|
||||
|
||||
}
|
||||
16
lib/tests/modules/define-option-dependently.nix
Normal file
16
lib/tests/modules/define-option-dependently.nix
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{ lib, options, ... }:
|
||||
|
||||
# Some modules may be distributed separately and need to adapt to other modules
|
||||
# that are distributed and versioned separately.
|
||||
{
|
||||
|
||||
# Always defined, but the value depends on the presence of an option.
|
||||
config = {
|
||||
value = if options ? enable then 360 else 7;
|
||||
}
|
||||
# Only define if possible.
|
||||
// lib.optionalAttrs (options ? enable) {
|
||||
enable = true;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
{ shorthandOnlyDefinesConfig = true; }
|
||||
3
lib/tests/modules/define-submoduleWith-noshorthand.nix
Normal file
3
lib/tests/modules/define-submoduleWith-noshorthand.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
submodule.config.config = true;
|
||||
}
|
||||
3
lib/tests/modules/define-submoduleWith-shorthand.nix
Normal file
3
lib/tests/modules/define-submoduleWith-shorthand.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
submodule.config = true;
|
||||
}
|
||||
3
lib/tests/modules/define-value-int-negative.nix
Normal file
3
lib/tests/modules/define-value-int-negative.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value = -23;
|
||||
}
|
||||
3
lib/tests/modules/define-value-int-positive.nix
Normal file
3
lib/tests/modules/define-value-int-positive.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value = 42;
|
||||
}
|
||||
3
lib/tests/modules/define-value-int-zero.nix
Normal file
3
lib/tests/modules/define-value-int-zero.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value = 0;
|
||||
}
|
||||
3
lib/tests/modules/define-value-list.nix
Normal file
3
lib/tests/modules/define-value-list.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value = [];
|
||||
}
|
||||
3
lib/tests/modules/define-value-string-arbitrary.nix
Normal file
3
lib/tests/modules/define-value-string-arbitrary.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value = "foobar";
|
||||
}
|
||||
3
lib/tests/modules/define-value-string-bigint.nix
Normal file
3
lib/tests/modules/define-value-string-bigint.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value = "1000";
|
||||
}
|
||||
12
lib/tests/modules/define-value-string-properties.nix
Normal file
12
lib/tests/modules/define-value-string-properties.nix
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{ lib, ... }: {
|
||||
|
||||
imports = [{
|
||||
value = lib.mkDefault "def";
|
||||
}];
|
||||
|
||||
value = lib.mkMerge [
|
||||
(lib.mkIf false "nope")
|
||||
"yes"
|
||||
];
|
||||
|
||||
}
|
||||
3
lib/tests/modules/define-value-string.nix
Normal file
3
lib/tests/modules/define-value-string.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
value = "24";
|
||||
}
|
||||
22
lib/tests/modules/define-variant.nix
Normal file
22
lib/tests/modules/define-variant.nix
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{ config, lib, ... }:
|
||||
let inherit (lib) types mkOption attrNames;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
attrs = mkOption { type = types.attrsOf lib.types.int; };
|
||||
result = mkOption { };
|
||||
resultFoo = mkOption { };
|
||||
resultFooBar = mkOption { };
|
||||
resultFooFoo = mkOption { };
|
||||
};
|
||||
config = {
|
||||
attrs.a = 1;
|
||||
variants.foo.attrs.b = 1;
|
||||
variants.bar.attrs.y = 1;
|
||||
variants.foo.variants.bar.attrs.z = 1;
|
||||
variants.foo.variants.foo.attrs.c = 3;
|
||||
resultFoo = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.attrs);
|
||||
resultFooBar = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.variants.bar.attrs);
|
||||
resultFooFoo = lib.concatMapStringsSep " " toString (attrNames config.variants.foo.variants.foo.attrs);
|
||||
};
|
||||
}
|
||||
5
lib/tests/modules/disable-declare-enable.nix
Normal file
5
lib/tests/modules/disable-declare-enable.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
disabledModules = [ ./declare-enable.nix ];
|
||||
}
|
||||
5
lib/tests/modules/disable-define-enable.nix
Normal file
5
lib/tests/modules/disable-define-enable.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
disabledModules = [ ./define-enable.nix ];
|
||||
}
|
||||
5
lib/tests/modules/disable-enable-modules.nix
Normal file
5
lib/tests/modules/disable-enable-modules.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{ lib, ... }:
|
||||
|
||||
{
|
||||
disabledModules = [ "define-enable.nix" "declare-enable.nix" ];
|
||||
}
|
||||
5
lib/tests/modules/disable-recursive/bar.nix
Normal file
5
lib/tests/modules/disable-recursive/bar.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
imports = [
|
||||
../declare-enable.nix
|
||||
];
|
||||
}
|
||||
7
lib/tests/modules/disable-recursive/disable-bar.nix
Normal file
7
lib/tests/modules/disable-recursive/disable-bar.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
|
||||
disabledModules = [
|
||||
./bar.nix
|
||||
];
|
||||
|
||||
}
|
||||
7
lib/tests/modules/disable-recursive/disable-foo.nix
Normal file
7
lib/tests/modules/disable-recursive/disable-foo.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
|
||||
disabledModules = [
|
||||
./foo.nix
|
||||
];
|
||||
|
||||
}
|
||||
5
lib/tests/modules/disable-recursive/foo.nix
Normal file
5
lib/tests/modules/disable-recursive/foo.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
imports = [
|
||||
../declare-enable.nix
|
||||
];
|
||||
}
|
||||
8
lib/tests/modules/disable-recursive/main.nix
Normal file
8
lib/tests/modules/disable-recursive/main.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
imports = [
|
||||
./foo.nix
|
||||
./bar.nix
|
||||
];
|
||||
|
||||
enable = true;
|
||||
}
|
||||
36
lib/tests/modules/emptyValues.nix
Normal file
36
lib/tests/modules/emptyValues.nix
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) types;
|
||||
in {
|
||||
|
||||
options = {
|
||||
int = lib.mkOption {
|
||||
type = types.lazyAttrsOf types.int;
|
||||
};
|
||||
list = lib.mkOption {
|
||||
type = types.lazyAttrsOf (types.listOf types.int);
|
||||
};
|
||||
nonEmptyList = lib.mkOption {
|
||||
type = types.lazyAttrsOf (types.nonEmptyListOf types.int);
|
||||
};
|
||||
attrs = lib.mkOption {
|
||||
type = types.lazyAttrsOf (types.attrsOf types.int);
|
||||
};
|
||||
null = lib.mkOption {
|
||||
type = types.lazyAttrsOf (types.nullOr types.int);
|
||||
};
|
||||
submodule = lib.mkOption {
|
||||
type = types.lazyAttrsOf (types.submodule {});
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
int.a = lib.mkIf false null;
|
||||
list.a = lib.mkIf false null;
|
||||
nonEmptyList.a = lib.mkIf false null;
|
||||
attrs.a = lib.mkIf false null;
|
||||
null.a = lib.mkIf false null;
|
||||
submodule.a = lib.mkIf false null;
|
||||
};
|
||||
|
||||
}
|
||||
41
lib/tests/modules/extendModules-168767-imports.nix
Normal file
41
lib/tests/modules/extendModules-168767-imports.nix
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
{ lib
|
||||
, extendModules
|
||||
, ...
|
||||
}:
|
||||
with lib;
|
||||
{
|
||||
imports = [
|
||||
|
||||
{
|
||||
options.sub = mkOption {
|
||||
default = { };
|
||||
type = types.submodule (
|
||||
{ config
|
||||
, extendModules
|
||||
, ...
|
||||
}:
|
||||
{
|
||||
options.value = mkOption {
|
||||
type = types.int;
|
||||
};
|
||||
|
||||
options.specialisation = mkOption {
|
||||
default = { };
|
||||
inherit
|
||||
(extendModules {
|
||||
modules = [{
|
||||
specialisation = mkOverride 0 { };
|
||||
}];
|
||||
})
|
||||
type;
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
{ config.sub.value = 1; }
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
3
lib/tests/modules/freeform-attrsOf.nix
Normal file
3
lib/tests/modules/freeform-attrsOf.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{ lib, ... }: {
|
||||
freeformType = with lib.types; attrsOf (either str (attrsOf str));
|
||||
}
|
||||
3
lib/tests/modules/freeform-lazyAttrsOf.nix
Normal file
3
lib/tests/modules/freeform-lazyAttrsOf.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{ lib, ... }: {
|
||||
freeformType = with lib.types; lazyAttrsOf (either str (lazyAttrsOf str));
|
||||
}
|
||||
14
lib/tests/modules/freeform-nested.nix
Normal file
14
lib/tests/modules/freeform-nested.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
deathtrapArgs = lib.mapAttrs
|
||||
(k: _: throw "The module system is too strict, accessing an unused option's ${k} mkOption-attribute.")
|
||||
(lib.functionArgs lib.mkOption);
|
||||
in
|
||||
{
|
||||
options.nest.foo = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
};
|
||||
options.nest.unused = lib.mkOption deathtrapArgs;
|
||||
config.nest.bar = "bar";
|
||||
}
|
||||
8
lib/tests/modules/freeform-str-dep-unstr.nix
Normal file
8
lib/tests/modules/freeform-str-dep-unstr.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{ lib, config, ... }: {
|
||||
options.foo = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
};
|
||||
|
||||
config.foo = lib.mkIf (config ? value) config.value;
|
||||
}
|
||||
22
lib/tests/modules/freeform-submodules.nix
Normal file
22
lib/tests/modules/freeform-submodules.nix
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{ lib, options, ... }: with lib.types; {
|
||||
|
||||
options.fooDeclarations = lib.mkOption {
|
||||
default = (options.free.type.getSubOptions [])._freeformOptions.foo.declarations;
|
||||
};
|
||||
|
||||
options.free = lib.mkOption {
|
||||
type = submodule {
|
||||
config._module.freeformType = lib.mkMerge [
|
||||
(attrsOf (submodule {
|
||||
options.foo = lib.mkOption {};
|
||||
}))
|
||||
(attrsOf (submodule {
|
||||
options.bar = lib.mkOption {};
|
||||
}))
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
config.free.xxx.foo = 10;
|
||||
config.free.yyy.bar = 10;
|
||||
}
|
||||
8
lib/tests/modules/freeform-unstr-dep-str.nix
Normal file
8
lib/tests/modules/freeform-unstr-dep-str.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{ lib, config, ... }: {
|
||||
options.value = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
};
|
||||
|
||||
config.foo = lib.mkIf (config.value != null) config.value;
|
||||
}
|
||||
25
lib/tests/modules/functionTo/list-order.nix
Normal file
25
lib/tests/modules/functionTo/list-order.nix
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
{ lib, config, ... }:
|
||||
let
|
||||
inherit (lib) types;
|
||||
in {
|
||||
options = {
|
||||
fun = lib.mkOption {
|
||||
type = types.functionTo (types.listOf types.str);
|
||||
};
|
||||
|
||||
result = lib.mkOption {
|
||||
type = types.str;
|
||||
default = toString (config.fun {
|
||||
a = "a";
|
||||
b = "b";
|
||||
c = "c";
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
config.fun = lib.mkMerge [
|
||||
(input: lib.mkAfter [ input.a ])
|
||||
(input: [ input.b ])
|
||||
];
|
||||
}
|
||||
27
lib/tests/modules/functionTo/merging-attrs.nix
Normal file
27
lib/tests/modules/functionTo/merging-attrs.nix
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{ lib, config, ... }:
|
||||
let
|
||||
inherit (lib) types;
|
||||
in {
|
||||
options = {
|
||||
fun = lib.mkOption {
|
||||
type = types.functionTo (types.attrsOf types.str);
|
||||
};
|
||||
|
||||
result = lib.mkOption {
|
||||
type = types.str;
|
||||
default = toString (lib.attrValues (config.fun {
|
||||
a = "a";
|
||||
b = "b";
|
||||
c = "c";
|
||||
}));
|
||||
};
|
||||
};
|
||||
|
||||
config.fun = lib.mkMerge [
|
||||
(input: { inherit (input) a; })
|
||||
(input: { inherit (input) b; })
|
||||
(input: {
|
||||
b = lib.mkForce input.c;
|
||||
})
|
||||
];
|
||||
}
|
||||
24
lib/tests/modules/functionTo/merging-list.nix
Normal file
24
lib/tests/modules/functionTo/merging-list.nix
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{ lib, config, ... }:
|
||||
let
|
||||
inherit (lib) types;
|
||||
in {
|
||||
options = {
|
||||
fun = lib.mkOption {
|
||||
type = types.functionTo (types.listOf types.str);
|
||||
};
|
||||
|
||||
result = lib.mkOption {
|
||||
type = types.str;
|
||||
default = toString (config.fun {
|
||||
a = "a";
|
||||
b = "b";
|
||||
c = "c";
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
config.fun = lib.mkMerge [
|
||||
(input: [ input.a ])
|
||||
(input: [ input.b ])
|
||||
];
|
||||
}
|
||||
61
lib/tests/modules/functionTo/submodule-options.nix
Normal file
61
lib/tests/modules/functionTo/submodule-options.nix
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
{ lib, config, options, ... }:
|
||||
let
|
||||
inherit (lib) types;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
|
||||
# fun.<function-body>.a
|
||||
({ ... }: {
|
||||
options = {
|
||||
fun = lib.mkOption {
|
||||
type = types.functionTo (types.submodule {
|
||||
options.a = lib.mkOption { default = "a"; };
|
||||
});
|
||||
};
|
||||
};
|
||||
})
|
||||
|
||||
# fun.<function-body>.b
|
||||
({ ... }: {
|
||||
options = {
|
||||
fun = lib.mkOption {
|
||||
type = types.functionTo (types.submodule {
|
||||
options.b = lib.mkOption { default = "b"; };
|
||||
});
|
||||
};
|
||||
};
|
||||
})
|
||||
];
|
||||
|
||||
options = {
|
||||
result = lib.mkOption
|
||||
{
|
||||
type = types.str;
|
||||
default = lib.concatStringsSep " " (lib.attrValues (config.fun (throw "shouldn't use input param")));
|
||||
};
|
||||
|
||||
optionsResult = lib.mkOption
|
||||
{
|
||||
type = types.str;
|
||||
default = lib.concatStringsSep " "
|
||||
(lib.concatLists
|
||||
(lib.mapAttrsToList
|
||||
(k: v:
|
||||
if k == "_module"
|
||||
then [ ]
|
||||
else [ (lib.showOption v.loc) ]
|
||||
)
|
||||
(
|
||||
(options.fun.type.getSubOptions [ "fun" ])
|
||||
)
|
||||
)
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
config.fun = lib.mkMerge
|
||||
[
|
||||
(input: { b = "bee"; })
|
||||
];
|
||||
}
|
||||
17
lib/tests/modules/functionTo/trivial.nix
Normal file
17
lib/tests/modules/functionTo/trivial.nix
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{ lib, config, ... }:
|
||||
let
|
||||
inherit (lib) types;
|
||||
in {
|
||||
options = {
|
||||
fun = lib.mkOption {
|
||||
type = types.functionTo types.str;
|
||||
};
|
||||
|
||||
result = lib.mkOption {
|
||||
type = types.str;
|
||||
default = config.fun "input";
|
||||
};
|
||||
};
|
||||
|
||||
config.fun = input: "input is ${input}";
|
||||
}
|
||||
18
lib/tests/modules/functionTo/wrong-type.nix
Normal file
18
lib/tests/modules/functionTo/wrong-type.nix
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
{ lib, config, ... }:
|
||||
let
|
||||
inherit (lib) types;
|
||||
in {
|
||||
options = {
|
||||
fun = lib.mkOption {
|
||||
type = types.functionTo types.str;
|
||||
};
|
||||
|
||||
result = lib.mkOption {
|
||||
type = types.str;
|
||||
default = config.fun 0;
|
||||
};
|
||||
};
|
||||
|
||||
config.fun = input: input + 1;
|
||||
}
|
||||
6
lib/tests/modules/import-custom-arg.nix
Normal file
6
lib/tests/modules/import-custom-arg.nix
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{ lib, custom, ... }:
|
||||
|
||||
{
|
||||
imports = []
|
||||
++ lib.optional custom ./define-enable-force.nix;
|
||||
}
|
||||
11
lib/tests/modules/import-from-store.nix
Normal file
11
lib/tests/modules/import-from-store.nix
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{ lib, ... }:
|
||||
{
|
||||
|
||||
imports = [
|
||||
"${builtins.toFile "drv" "{}"}"
|
||||
./declare-enable.nix
|
||||
./define-enable.nix
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
28
lib/tests/modules/optionTypeFile.nix
Normal file
28
lib/tests/modules/optionTypeFile.nix
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{ config, lib, ... }: {
|
||||
|
||||
_file = "optionTypeFile.nix";
|
||||
|
||||
options.theType = lib.mkOption {
|
||||
type = lib.types.optionType;
|
||||
};
|
||||
|
||||
options.theOption = lib.mkOption {
|
||||
type = config.theType;
|
||||
default = {};
|
||||
};
|
||||
|
||||
config.theType = lib.mkMerge [
|
||||
(lib.types.submodule {
|
||||
options.nested = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
};
|
||||
})
|
||||
(lib.types.submodule {
|
||||
_file = "other.nix";
|
||||
options.nested = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
})
|
||||
];
|
||||
|
||||
}
|
||||
27
lib/tests/modules/optionTypeMerging.nix
Normal file
27
lib/tests/modules/optionTypeMerging.nix
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{ config, lib, ... }: {
|
||||
|
||||
options.theType = lib.mkOption {
|
||||
type = lib.types.optionType;
|
||||
};
|
||||
|
||||
options.theOption = lib.mkOption {
|
||||
type = config.theType;
|
||||
};
|
||||
|
||||
config.theType = lib.mkMerge [
|
||||
(lib.types.submodule {
|
||||
options.int = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 10;
|
||||
};
|
||||
})
|
||||
(lib.types.submodule {
|
||||
options.str = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
})
|
||||
];
|
||||
|
||||
config.theOption.str = "hello";
|
||||
|
||||
}
|
||||
30
lib/tests/modules/raw.nix
Normal file
30
lib/tests/modules/raw.nix
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
{ lib, ... }: {
|
||||
|
||||
options = {
|
||||
processedToplevel = lib.mkOption {
|
||||
type = lib.types.raw;
|
||||
};
|
||||
unprocessedNesting = lib.mkOption {
|
||||
type = lib.types.raw;
|
||||
};
|
||||
multiple = lib.mkOption {
|
||||
type = lib.types.raw;
|
||||
};
|
||||
priorities = lib.mkOption {
|
||||
type = lib.types.raw;
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
processedToplevel = lib.mkIf true 10;
|
||||
unprocessedNesting.foo = throw "foo";
|
||||
multiple = lib.mkMerge [
|
||||
"foo"
|
||||
"foo"
|
||||
];
|
||||
priorities = lib.mkMerge [
|
||||
"foo"
|
||||
(lib.mkForce "bar")
|
||||
];
|
||||
};
|
||||
}
|
||||
12
lib/tests/modules/types-anything/attrs-coercible.nix
Normal file
12
lib/tests/modules/types-anything/attrs-coercible.nix
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{ lib, ... }: {
|
||||
|
||||
options.value = lib.mkOption {
|
||||
type = lib.types.anything;
|
||||
};
|
||||
|
||||
config.value = {
|
||||
outPath = "foo";
|
||||
err = throw "err";
|
||||
};
|
||||
|
||||
}
|
||||
26
lib/tests/modules/types-anything/equal-atoms.nix
Normal file
26
lib/tests/modules/types-anything/equal-atoms.nix
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{ lib, ... }: {
|
||||
|
||||
options.value = lib.mkOption {
|
||||
type = lib.types.anything;
|
||||
};
|
||||
|
||||
config = lib.mkMerge [
|
||||
{
|
||||
value.int = 0;
|
||||
value.bool = false;
|
||||
value.string = "";
|
||||
value.path = /.;
|
||||
value.null = null;
|
||||
value.float = 0.1;
|
||||
}
|
||||
{
|
||||
value.int = 0;
|
||||
value.bool = false;
|
||||
value.string = "";
|
||||
value.path = /.;
|
||||
value.null = null;
|
||||
value.float = 0.1;
|
||||
}
|
||||
];
|
||||
|
||||
}
|
||||
23
lib/tests/modules/types-anything/functions.nix
Normal file
23
lib/tests/modules/types-anything/functions.nix
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{ lib, config, ... }: {
|
||||
|
||||
options.value = lib.mkOption {
|
||||
type = lib.types.anything;
|
||||
};
|
||||
|
||||
options.applied = lib.mkOption {
|
||||
default = lib.mapAttrs (name: fun: fun null) config.value;
|
||||
};
|
||||
|
||||
config = lib.mkMerge [
|
||||
{
|
||||
value.single-lambda = x: x;
|
||||
value.multiple-lambdas = x: { inherit x; };
|
||||
value.merging-lambdas = x: { inherit x; };
|
||||
}
|
||||
{
|
||||
value.multiple-lambdas = x: [ x ];
|
||||
value.merging-lambdas = y: { inherit y; };
|
||||
}
|
||||
];
|
||||
|
||||
}
|
||||
16
lib/tests/modules/types-anything/lists.nix
Normal file
16
lib/tests/modules/types-anything/lists.nix
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{ lib, ... }: {
|
||||
|
||||
options.value = lib.mkOption {
|
||||
type = lib.types.anything;
|
||||
};
|
||||
|
||||
config = lib.mkMerge [
|
||||
{
|
||||
value = [ null ];
|
||||
}
|
||||
{
|
||||
value = [ null ];
|
||||
}
|
||||
];
|
||||
|
||||
}
|
||||
44
lib/tests/modules/types-anything/mk-mods.nix
Normal file
44
lib/tests/modules/types-anything/mk-mods.nix
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
{ lib, ... }: {
|
||||
|
||||
options.value = lib.mkOption {
|
||||
type = lib.types.anything;
|
||||
};
|
||||
|
||||
config = lib.mkMerge [
|
||||
{
|
||||
value.mkiffalse = lib.mkIf false {};
|
||||
}
|
||||
{
|
||||
value.mkiftrue = lib.mkIf true {};
|
||||
}
|
||||
{
|
||||
value.mkdefault = lib.mkDefault 0;
|
||||
}
|
||||
{
|
||||
value.mkdefault = 1;
|
||||
}
|
||||
{
|
||||
value.mkmerge = lib.mkMerge [
|
||||
{}
|
||||
];
|
||||
}
|
||||
{
|
||||
value.mkbefore = lib.mkBefore true;
|
||||
}
|
||||
{
|
||||
value.nested = lib.mkMerge [
|
||||
{
|
||||
foo = lib.mkDefault 0;
|
||||
bar = lib.mkIf false 0;
|
||||
}
|
||||
(lib.mkIf true {
|
||||
foo = lib.mkIf true (lib.mkForce 1);
|
||||
bar = {
|
||||
baz = lib.mkDefault "baz";
|
||||
};
|
||||
})
|
||||
];
|
||||
}
|
||||
];
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue