Merge master into staging-next
This commit is contained in:
@@ -87,36 +87,36 @@ checkConfigOutput "false" "$@" ./define-force-enable.nix
|
||||
checkConfigOutput "false" "$@" ./define-enable-force.nix
|
||||
|
||||
# Check mkForce with option and submodules.
|
||||
checkConfigError 'attribute .*foo.* .* not found' config.loaOfSub.foo.enable ./declare-loaOfSub-any-enable.nix
|
||||
checkConfigOutput 'false' config.loaOfSub.foo.enable ./declare-loaOfSub-any-enable.nix ./define-loaOfSub-foo.nix
|
||||
set -- config.loaOfSub.foo.enable ./declare-loaOfSub-any-enable.nix ./define-loaOfSub-foo-enable.nix
|
||||
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-loaOfSub-foo-enable.nix
|
||||
checkConfigOutput 'false' "$@" ./define-loaOfSub-force-foo-enable.nix
|
||||
checkConfigOutput 'false' "$@" ./define-loaOfSub-foo-force-enable.nix
|
||||
checkConfigOutput 'false' "$@" ./define-loaOfSub-foo-enable-force.nix
|
||||
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.loaOfSub.bar.enable ./declare-loaOfSub-any-enable.nix ./define-loaOfSub-foo.nix
|
||||
checkConfigOutput 'false' config.loaOfSub.bar.enable ./declare-loaOfSub-any-enable.nix ./define-loaOfSub-foo.nix ./define-loaOfSub-bar.nix
|
||||
set -- config.loaOfSub.bar.enable ./declare-loaOfSub-any-enable.nix ./define-loaOfSub-foo.nix ./define-loaOfSub-bar-enable.nix
|
||||
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-loaOfSub-foo-enable.nix
|
||||
checkConfigError 'attribute .*bar.* .* not found' "$@" ./define-loaOfSub-force-foo-enable.nix
|
||||
checkConfigOutput 'true' "$@" ./define-loaOfSub-foo-force-enable.nix
|
||||
checkConfigOutput 'true' "$@" ./define-loaOfSub-foo-enable-force.nix
|
||||
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.loaOfSub.foo.enable ./declare-enable.nix ./declare-loaOfSub-any-enable.nix
|
||||
set -- config.loaOfSub.foo.enable ./declare-enable.nix ./declare-loaOfSub-any-enable.nix
|
||||
checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-if-loaOfSub-foo-enable.nix
|
||||
checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-loaOfSub-if-foo-enable.nix
|
||||
checkConfigError 'attribute .*foo.* .* not found' "$@" ./define-loaOfSub-foo-if-enable.nix
|
||||
checkConfigOutput 'false' "$@" ./define-loaOfSub-foo-enable-if.nix
|
||||
checkConfigOutput 'true' "$@" ./define-enable.nix ./define-if-loaOfSub-foo-enable.nix
|
||||
checkConfigOutput 'true' "$@" ./define-enable.nix ./define-loaOfSub-if-foo-enable.nix
|
||||
checkConfigOutput 'true' "$@" ./define-enable.nix ./define-loaOfSub-foo-if-enable.nix
|
||||
checkConfigOutput 'true' "$@" ./define-enable.nix ./define-loaOfSub-foo-enable-if.nix
|
||||
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
|
||||
@@ -138,7 +138,7 @@ checkConfigError 'while evaluating the module argument .*custom.* in .*import-cu
|
||||
checkConfigError 'infinite recursion encountered' "$@"
|
||||
|
||||
# Check _module.check.
|
||||
set -- config.enable ./declare-enable.nix ./define-enable.nix ./define-loaOfSub-foo.nix
|
||||
set -- config.enable ./declare-enable.nix ./define-enable.nix ./define-attrsOfSub-foo.nix
|
||||
checkConfigError 'The option .* defined in .* does not exist.' "$@"
|
||||
checkConfigOutput "true" "$@" ./define-module-check.nix
|
||||
|
||||
@@ -152,12 +152,6 @@ checkConfigOutput "12" config.value ./declare-coerced-value-unsound.nix
|
||||
checkConfigError 'The option value .* in .* is not.*8 bit signed integer.* or string convertible to it' config.value ./declare-coerced-value-unsound.nix ./define-value-string-bigint.nix
|
||||
checkConfigError 'unrecognised JSON value' config.value ./declare-coerced-value-unsound.nix ./define-value-string-arbitrary.nix
|
||||
|
||||
# Check loaOf with long list.
|
||||
checkConfigOutput "1 2 3 4 5 6 7 8 9 10" config.result ./loaOf-with-long-list.nix
|
||||
|
||||
# Check loaOf with many merges of lists.
|
||||
checkConfigOutput "1 2 3 4 5 6 7 8 9 10" config.result ./loaOf-with-many-list-merges.nix
|
||||
|
||||
# Check mkAliasOptionModule.
|
||||
checkConfigOutput "true" config.enable ./alias-with-priority.nix
|
||||
checkConfigOutput "true" config.enableAlias ./alias-with-priority.nix
|
||||
|
||||
@@ -17,10 +17,10 @@ in
|
||||
|
||||
{
|
||||
options = {
|
||||
loaOfSub = lib.mkOption {
|
||||
attrsOfSub = lib.mkOption {
|
||||
default = {};
|
||||
example = {};
|
||||
type = lib.types.loaOf (lib.types.submodule [ submod ]);
|
||||
type = lib.types.attrsOf (lib.types.submodule [ submod ]);
|
||||
description = ''
|
||||
Some descriptive text
|
||||
'';
|
||||
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;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{ lib, ... }:
|
||||
|
||||
{
|
||||
loaOfSub.foo = lib.mkForce {
|
||||
attrsOfSub.foo = lib.mkForce {
|
||||
enable = false;
|
||||
};
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{ config, lib, ... }:
|
||||
|
||||
{
|
||||
loaOfSub.foo = lib.mkIf config.enable {
|
||||
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 = {};
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{ lib, ... }:
|
||||
|
||||
{
|
||||
loaOfSub = lib.mkForce {
|
||||
attrsOfSub = lib.mkForce {
|
||||
foo.enable = false;
|
||||
};
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{ config, lib, ... }:
|
||||
|
||||
{
|
||||
loaOfSub = lib.mkIf config.enable {
|
||||
attrsOfSub = lib.mkIf config.enable {
|
||||
foo.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;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{ lib, ... }:
|
||||
|
||||
lib.mkForce {
|
||||
loaOfSub.foo.enable = false;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{ config, lib, ... }:
|
||||
|
||||
lib.mkIf config.enable {
|
||||
loaOfSub.foo.enable = true;
|
||||
attrsOfSub.foo.enable = true;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
loaOfSub.bar.enable = true;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
loaOfSub.bar = {};
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{ lib, ... }:
|
||||
|
||||
{
|
||||
loaOfSub.foo.enable = lib.mkForce false;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
{ config, lib, ... }:
|
||||
|
||||
{
|
||||
loaOfSub.foo.enable = lib.mkIf config.enable true;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
loaOfSub.foo.enable = true;
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
loaOfSub.foo = {};
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
{ config, lib, ... }:
|
||||
|
||||
{
|
||||
options = {
|
||||
loaOfInt = lib.mkOption {
|
||||
type = lib.types.loaOf lib.types.int;
|
||||
};
|
||||
|
||||
result = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
loaOfInt = [ 1 2 3 4 5 6 7 8 9 10 ];
|
||||
|
||||
result = toString (lib.attrValues config.loaOfInt);
|
||||
};
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
{ config, lib, ... }:
|
||||
|
||||
{
|
||||
options = {
|
||||
loaOfInt = lib.mkOption {
|
||||
type = lib.types.loaOf lib.types.int;
|
||||
};
|
||||
|
||||
result = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
loaOfInt = lib.mkMerge (map lib.singleton [ 1 2 3 4 5 6 7 8 9 10 ]);
|
||||
|
||||
result = toString (lib.attrValues config.loaOfInt);
|
||||
};
|
||||
}
|
||||
@@ -242,8 +242,7 @@ rec {
|
||||
|
||||
path = mkOptionType {
|
||||
name = "path";
|
||||
# Hacky: there is no ‘isPath’ primop.
|
||||
check = x: builtins.substring 0 1 (toString x) == "/";
|
||||
check = x: isCoercibleToString x && builtins.substring 0 1 (toString x) == "/";
|
||||
merge = mergeEqualOption;
|
||||
};
|
||||
|
||||
@@ -295,26 +294,43 @@ rec {
|
||||
# List or attribute set of ...
|
||||
loaOf = elemType:
|
||||
let
|
||||
convertAllLists = defs:
|
||||
convertAllLists = loc: defs:
|
||||
let
|
||||
padWidth = stringLength (toString (length defs));
|
||||
unnamedPrefix = i: "unnamed-" + fixedWidthNumber padWidth i + ".";
|
||||
in
|
||||
imap1 (i: convertIfList (unnamedPrefix i)) defs;
|
||||
|
||||
convertIfList = unnamedPrefix: def:
|
||||
imap1 (i: convertIfList loc (unnamedPrefix i)) defs;
|
||||
convertIfList = loc: unnamedPrefix: def:
|
||||
if isList def.value then
|
||||
let
|
||||
padWidth = stringLength (toString (length def.value));
|
||||
unnamed = i: unnamedPrefix + fixedWidthNumber padWidth i;
|
||||
res =
|
||||
{ inherit (def) file;
|
||||
value = listToAttrs (
|
||||
imap1 (elemIdx: elem:
|
||||
{ name = elem.name or (unnamed elemIdx);
|
||||
value = elem;
|
||||
}) def.value);
|
||||
};
|
||||
option = concatStringsSep "." loc;
|
||||
sample = take 3 def.value;
|
||||
list = concatMapStrings (x: ''{ name = "${x.name or "unnamed"}"; ...} '') sample;
|
||||
set = concatMapStrings (x: ''${x.name or "unnamed"} = {...}; '') sample;
|
||||
msg = ''
|
||||
In file ${def.file}
|
||||
a list is being assigned to the option config.${option}.
|
||||
This will soon be an error as type loaOf is deprecated.
|
||||
See https://git.io/fj2zm for more information.
|
||||
Do
|
||||
${option} =
|
||||
{ ${set}...}
|
||||
instead of
|
||||
${option} =
|
||||
[ ${list}...]
|
||||
'';
|
||||
in
|
||||
{ inherit (def) file;
|
||||
value = listToAttrs (
|
||||
imap1 (elemIdx: elem:
|
||||
{ name = elem.name or (unnamed elemIdx);
|
||||
value = elem;
|
||||
}) def.value);
|
||||
}
|
||||
lib.warn msg res
|
||||
else
|
||||
def;
|
||||
attrOnly = attrsOf elemType;
|
||||
@@ -322,7 +338,7 @@ rec {
|
||||
name = "loaOf";
|
||||
description = "list or attribute set of ${elemType.description}s";
|
||||
check = x: isList x || isAttrs x;
|
||||
merge = loc: defs: attrOnly.merge loc (convertAllLists defs);
|
||||
merge = loc: defs: attrOnly.merge loc (convertAllLists loc defs);
|
||||
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name?>"]);
|
||||
getSubModules = elemType.getSubModules;
|
||||
substSubModules = m: loaOf (elemType.substSubModules m);
|
||||
|
||||
Reference in New Issue
Block a user