mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 03:23:29 +03:00
lib.types.boolByOr: init
This type is necessary to have correct merging behavior for `allowUnfreePredicate` and `allowInsecurePredicate` Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
This commit is contained in:
parent
6cb8f045bf
commit
8d3978c149
4 changed files with 43 additions and 0 deletions
|
@ -111,6 +111,12 @@ checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*'
|
||||||
checkConfigError 'while evaluating a definition from `.*/define-enable-abort.nix' config.enable ./define-enable-abort.nix
|
checkConfigError 'while evaluating a definition from `.*/define-enable-abort.nix' config.enable ./define-enable-abort.nix
|
||||||
checkConfigError 'while evaluating the error message for definitions for .enable., which is an option that does not exist' config.enable ./define-enable-abort.nix
|
checkConfigError 'while evaluating the error message for definitions for .enable., which is an option that does not exist' config.enable ./define-enable-abort.nix
|
||||||
|
|
||||||
|
# Check boolByOr type.
|
||||||
|
checkConfigOutput '^false$' config.value.falseFalse ./boolByOr.nix
|
||||||
|
checkConfigOutput '^true$' config.value.trueFalse ./boolByOr.nix
|
||||||
|
checkConfigOutput '^true$' config.value.falseTrue ./boolByOr.nix
|
||||||
|
checkConfigOutput '^true$' config.value.trueTrue ./boolByOr.nix
|
||||||
|
|
||||||
checkConfigOutput '^1$' config.bare-submodule.nested ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.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 '^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 '^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
|
||||||
|
|
14
lib/tests/modules/boolByOr.nix
Normal file
14
lib/tests/modules/boolByOr.nix
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{ lib, ... }: {
|
||||||
|
|
||||||
|
options.value = lib.mkOption {
|
||||||
|
type = lib.types.lazyAttrsOf lib.types.boolByOr;
|
||||||
|
};
|
||||||
|
|
||||||
|
config.value = {
|
||||||
|
falseFalse = lib.mkMerge [ false false ];
|
||||||
|
trueFalse = lib.mkMerge [ true false ];
|
||||||
|
falseTrue = lib.mkMerge [ false true ];
|
||||||
|
trueTrue = lib.mkMerge [ true true ];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -275,6 +275,22 @@ rec {
|
||||||
merge = mergeEqualOption;
|
merge = mergeEqualOption;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
boolByOr = mkOptionType {
|
||||||
|
name = "boolByOr";
|
||||||
|
description = "boolean (merged using or)";
|
||||||
|
descriptionClass = "noun";
|
||||||
|
check = isBool;
|
||||||
|
merge = loc: defs:
|
||||||
|
foldl'
|
||||||
|
(result: def:
|
||||||
|
# Under the assumption that .check always runs before merge, we can assume that all defs.*.value
|
||||||
|
# have been forced, and therefore we assume we don't introduce order-dependent strictness here
|
||||||
|
result || def.value
|
||||||
|
)
|
||||||
|
false
|
||||||
|
defs;
|
||||||
|
};
|
||||||
|
|
||||||
int = mkOptionType {
|
int = mkOptionType {
|
||||||
name = "int";
|
name = "int";
|
||||||
description = "signed integer";
|
description = "signed integer";
|
||||||
|
|
|
@ -13,6 +13,13 @@ merging is handled.
|
||||||
`types.bool`
|
`types.bool`
|
||||||
|
|
||||||
: A boolean, its values can be `true` or `false`.
|
: A boolean, its values can be `true` or `false`.
|
||||||
|
All definitions must have the same value, after priorities. An error is thrown in case of a conflict.
|
||||||
|
|
||||||
|
`types.boolByOr`
|
||||||
|
|
||||||
|
: A boolean, its values can be `true` or `false`.
|
||||||
|
The result is `true` if _any_ of multiple definitions is `true`.
|
||||||
|
In other words, definitions are merged with the logical _OR_ operator.
|
||||||
|
|
||||||
`types.path`
|
`types.path`
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue