mirror of
https://github.com/CHN-beta/nixpkgs.git
synced 2026-01-12 02:40:31 +08:00
Merge remote-tracking branch 'origin/master' into staging-next
This commit is contained in:
@@ -446,6 +446,7 @@ let
|
||||
fixupOptionType
|
||||
mkIf
|
||||
mkAssert
|
||||
mkDefinition
|
||||
mkMerge
|
||||
mkOverride
|
||||
mkOptionDefault
|
||||
|
||||
@@ -1097,10 +1097,16 @@ let
|
||||
# Process mkMerge and mkIf properties.
|
||||
defs' = concatMap (
|
||||
m:
|
||||
map (value: {
|
||||
inherit (m) file;
|
||||
inherit value;
|
||||
}) (addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))
|
||||
map (
|
||||
value:
|
||||
if value._type or null == "definition" then
|
||||
value
|
||||
else
|
||||
{
|
||||
inherit (m) file;
|
||||
inherit value;
|
||||
}
|
||||
) (addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))
|
||||
) defs;
|
||||
|
||||
# Process mkOverride properties.
|
||||
@@ -1365,6 +1371,11 @@ let
|
||||
inherit contents;
|
||||
};
|
||||
|
||||
/**
|
||||
Return a definition with file location information.
|
||||
*/
|
||||
mkDefinition = args@{ file, value, ... }: args // { _type = "definition"; };
|
||||
|
||||
mkOverride = priority: content: {
|
||||
_type = "override";
|
||||
inherit priority content;
|
||||
@@ -2095,6 +2106,7 @@ private
|
||||
mkBefore
|
||||
mkChangedOptionModule
|
||||
mkDefault
|
||||
mkDefinition
|
||||
mkDerivedConfig
|
||||
mkFixStrictness
|
||||
mkForce
|
||||
|
||||
@@ -673,6 +673,14 @@ checkConfigError 'The option .conflictingPathOptionType. in .*/pathWith.nix. is
|
||||
# types.pathWith { inStore = true; absolute = false; }
|
||||
checkConfigError 'In pathWith, inStore means the path must be absolute' config.impossiblePathOptionType ./pathWith.nix
|
||||
|
||||
# mkDefinition
|
||||
# check that mkDefinition 'file' is printed in the error message
|
||||
checkConfigError 'Cannot merge definitions.*\n\s*- In .file.*\n\s*- In .other.*' config.conflict ./mkDefinition.nix
|
||||
checkConfigError 'A definition for option .viaOptionDefault. is not of type .boolean.*' config.viaOptionDefault ./mkDefinition.nix
|
||||
checkConfigOutput '^true$' config.viaConfig ./mkDefinition.nix
|
||||
checkConfigOutput '^true$' config.mkMerge ./mkDefinition.nix
|
||||
checkConfigOutput '^true$' config.mkForce ./mkDefinition.nix
|
||||
|
||||
cat <<EOF
|
||||
====== module tests ======
|
||||
$pass Pass
|
||||
|
||||
71
lib/tests/modules/mkDefinition.nix
Normal file
71
lib/tests/modules/mkDefinition.nix
Normal file
@@ -0,0 +1,71 @@
|
||||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib)
|
||||
mkOption
|
||||
mkDefinition
|
||||
mkOptionDefault
|
||||
;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
{
|
||||
_file = "file";
|
||||
options.conflict = mkOption {
|
||||
default = 1;
|
||||
};
|
||||
config.conflict = mkDefinition {
|
||||
file = "other";
|
||||
value = mkOptionDefault 42;
|
||||
};
|
||||
}
|
||||
{
|
||||
# Check that mkDefinition works within 'config'
|
||||
options.viaConfig = mkOption { };
|
||||
config.viaConfig = mkDefinition {
|
||||
file = "other";
|
||||
value = true;
|
||||
};
|
||||
}
|
||||
{
|
||||
# Check mkMerge can wrap mkDefinitions
|
||||
# Not the other way around
|
||||
options.mkMerge = mkOption {
|
||||
type = lib.types.bool;
|
||||
};
|
||||
config.mkMerge = lib.mkMerge [
|
||||
(mkDefinition {
|
||||
file = "a.nix";
|
||||
value = true;
|
||||
})
|
||||
(mkDefinition {
|
||||
file = "b.nix";
|
||||
value = true;
|
||||
})
|
||||
];
|
||||
}
|
||||
{
|
||||
# Check mkDefinition can use mkForce on the value
|
||||
# Not the other way around
|
||||
options.mkForce = mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
};
|
||||
config.mkForce = mkDefinition {
|
||||
file = "other";
|
||||
value = lib.mkForce true;
|
||||
};
|
||||
}
|
||||
{
|
||||
# Currently expects an error
|
||||
# mkDefinition doesn't work on option default
|
||||
# This is a limitation and might be resolved in the future
|
||||
options.viaOptionDefault = mkOption {
|
||||
type = lib.types.bool;
|
||||
default = mkDefinition {
|
||||
file = "other";
|
||||
value = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user