mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-28 14:22:50 +03:00
Merge pull request #144022 from hercules-ci/lib-modules-optimize-unmatchedDefns
lib/modules: Short-circuit unmatchedDefns when configs is empty
This commit is contained in:
commit
ae0b7d6db0
@ -13,8 +13,6 @@ let
|
|||||||
elem
|
elem
|
||||||
filter
|
filter
|
||||||
findFirst
|
findFirst
|
||||||
flip
|
|
||||||
foldl
|
|
||||||
foldl'
|
foldl'
|
||||||
getAttrFromPath
|
getAttrFromPath
|
||||||
head
|
head
|
||||||
@ -474,7 +472,7 @@ rec {
|
|||||||
[{ inherit (module) file; inherit value; }]
|
[{ inherit (module) file; inherit value; }]
|
||||||
) configs;
|
) configs;
|
||||||
|
|
||||||
resultsByName = flip mapAttrs declsByName (name: decls:
|
resultsByName = mapAttrs (name: decls:
|
||||||
# We're descending into attribute ‘name’.
|
# We're descending into attribute ‘name’.
|
||||||
let
|
let
|
||||||
loc = prefix ++ [name];
|
loc = prefix ++ [name];
|
||||||
@ -495,7 +493,7 @@ rec {
|
|||||||
in
|
in
|
||||||
throw "The option `${showOption loc}' in `${firstOption._file}' is a prefix of options in `${firstNonOption._file}'."
|
throw "The option `${showOption loc}' in `${firstOption._file}' is a prefix of options in `${firstNonOption._file}'."
|
||||||
else
|
else
|
||||||
mergeModules' loc decls defns);
|
mergeModules' loc decls defns) declsByName;
|
||||||
|
|
||||||
matchedOptions = mapAttrs (n: v: v.matchedOptions) resultsByName;
|
matchedOptions = mapAttrs (n: v: v.matchedOptions) resultsByName;
|
||||||
|
|
||||||
@ -509,12 +507,19 @@ rec {
|
|||||||
inherit matchedOptions;
|
inherit matchedOptions;
|
||||||
|
|
||||||
# Transforms unmatchedDefnsByName into a list of definitions
|
# Transforms unmatchedDefnsByName into a list of definitions
|
||||||
unmatchedDefns = concatLists (mapAttrsToList (name: defs:
|
unmatchedDefns =
|
||||||
map (def: def // {
|
if configs == []
|
||||||
# Set this so we know when the definition first left unmatched territory
|
then
|
||||||
prefix = [name] ++ (def.prefix or []);
|
# When no config values exist, there can be no unmatched config, so
|
||||||
}) defs
|
# we short circuit and avoid evaluating more _options_ than necessary.
|
||||||
) unmatchedDefnsByName);
|
[]
|
||||||
|
else
|
||||||
|
concatLists (mapAttrsToList (name: defs:
|
||||||
|
map (def: def // {
|
||||||
|
# Set this so we know when the definition first left unmatched territory
|
||||||
|
prefix = [name] ++ (def.prefix or []);
|
||||||
|
}) defs
|
||||||
|
) unmatchedDefnsByName);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Merge multiple option declarations into a single declaration. In
|
/* Merge multiple option declarations into a single declaration. In
|
||||||
@ -928,7 +933,7 @@ rec {
|
|||||||
mkMergedOptionModule = from: to: mergeFn:
|
mkMergedOptionModule = from: to: mergeFn:
|
||||||
{ config, options, ... }:
|
{ config, options, ... }:
|
||||||
{
|
{
|
||||||
options = foldl recursiveUpdate {} (map (path: setAttrByPath path (mkOption {
|
options = foldl' recursiveUpdate {} (map (path: setAttrByPath path (mkOption {
|
||||||
visible = false;
|
visible = false;
|
||||||
# To use the value in mergeFn without triggering errors
|
# To use the value in mergeFn without triggering errors
|
||||||
default = "_mkMergedOptionModule";
|
default = "_mkMergedOptionModule";
|
||||||
@ -1032,7 +1037,7 @@ rec {
|
|||||||
|
|
||||||
/* Use this function to import a JSON file as NixOS configuration.
|
/* Use this function to import a JSON file as NixOS configuration.
|
||||||
|
|
||||||
importJSON -> path -> attrs
|
modules.importJSON :: path -> attrs
|
||||||
*/
|
*/
|
||||||
importJSON = file: {
|
importJSON = file: {
|
||||||
_file = file;
|
_file = file;
|
||||||
@ -1041,7 +1046,7 @@ rec {
|
|||||||
|
|
||||||
/* Use this function to import a TOML file as NixOS configuration.
|
/* Use this function to import a TOML file as NixOS configuration.
|
||||||
|
|
||||||
importTOML -> path -> attrs
|
modules.importTOML :: path -> attrs
|
||||||
*/
|
*/
|
||||||
importTOML = file: {
|
importTOML = file: {
|
||||||
_file = file;
|
_file = file;
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
{ lib, ... }: {
|
{ 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 {
|
options.value = lib.mkOption {
|
||||||
type = lib.types.attrsOf lib.types.str;
|
type = lib.types.attrsOf lib.types.str;
|
||||||
default = {};
|
default = {};
|
||||||
};
|
};
|
||||||
|
options.testing-laziness-so-don't-read-me = lib.mkOption deathtrapArgs;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
{ lib, ... }: {
|
{ 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 {
|
options.nest.foo = lib.mkOption {
|
||||||
type = lib.types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
};
|
};
|
||||||
|
options.nest.unused = lib.mkOption deathtrapArgs;
|
||||||
config.nest.bar = "bar";
|
config.nest.bar = "bar";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user