git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #101139 from roberth/lib-use-static-scope-checking

lib: Use Nix's static scope checking, fix error message, optimize

commit7102388834f1cd81c4d4bc48f41f0d4b8fa8933a authorRobert Hensing <roberth@users.noreply.github.com> dateMon 26 Oct 2020, 06:59 (6 years ago) parentdfaa313a4019a4
9 files changed+265−86
lib/debug.nix+24−8 lib/default.nix+20−20 lib/lists.nix+1−1 lib/modules.nix+49−8 lib/options.nix+35−6 lib/sources.nix+28−12 lib/strings-with-deps.nix+9−4 lib/strings.nix+43−21 lib/types.nix+56−6
lib/debug.nix+24−8
@@ -14,9 +14,25 @@
1414*/
1515{ lib }:
1616let
17− inherit (builtins) trace isAttrs isList isInt
18− head substring attrNames;
19− inherit (lib) id elem isFunction;
17+ inherit (lib)
18+ isInt
19+ attrNames
20+ isList
21+ isAttrs
22+ substring
23+ addErrorContext
24+ attrValues
25+ concatLists
26+ concatStringsSep
27+ const
28+ elem
29+ generators
30+ head
31+ id
32+ isDerivation
33+ isFunction
34+ mapAttrs
35+ trace;
2036in
2137
2238rec {
@@ -94,7 +110,7 @@ rec {
94110 trace: { a = { b = {…}; }; }
95111 => null
96112 */
97− traceSeqN = depth: x: y: with lib;
113+ traceSeqN = depth: x: y:
98114 let snip = v: if isList v then noQuotes "[…]" v
99115 else if isAttrs v then noQuotes "{…}" v
100116 else v;
@@ -149,7 +165,7 @@ rec {
149165 */
150166 runTests =
151167 # Tests to run
152− tests: lib.concatLists (lib.attrValues (lib.mapAttrs (name: test:
168+ tests: concatLists (attrValues (mapAttrs (name: test:
153169 let testsToRun = if tests ? tests then tests.tests else [];
154170 in if (substring 0 4 name == "test" || elem name testsToRun)
155171 && ((testsToRun == []) || elem name tests.tests)
@@ -176,9 +192,9 @@ rec {
176192 + "and will be removed in the next release. "
177193 + "Please use more specific concatenation "
178194 + "for your uses (`lib.concat(Map)StringsSep`)." )
179− (lib.concatStringsSep "; " (map (x: "${x}=") (attrNames a)));
195+ (concatStringsSep "; " (map (x: "${x}=") (attrNames a)));
180196
181− showVal = with lib;
197+ showVal =
182198 trace ( "Warning: `showVal` is deprecated "
183199 + "and will be removed in the next release, "
184200 + "please use `traceSeqN`" )
@@ -226,7 +242,7 @@ rec {
226242 trace ( "Warning: `addErrorContextToAttrs` is deprecated "
227243 + "and will be removed in the next release. "
228244 + "Please use `builtins.addErrorContext` directly." )
229− (lib.mapAttrs (a: v: lib.addErrorContext "while evaluating ${a}" v) attrs);
245+ (mapAttrs (a: v: addErrorContext "while evaluating ${a}" v) attrs);
230246
231247 # example: (traceCallXml "myfun" id 3) will output something like
232248 # calling myfun arg 1: 3 result: 3
lib/default.nix+20−20
@@ -9,7 +9,7 @@ let
99
1010 lib = makeExtensible (self: let
1111 callLibs = file: import file { lib = self; };
12− in with self; {
12+ in {
1313
1414 # often used, or depending on very little
1515 trivial = callLibs ./trivial.nix;
@@ -54,7 +54,7 @@ let
5454 filesystem = callLibs ./filesystem.nix;
5555
5656 # back-compat aliases
57− platforms = systems.doubles;
57+ platforms = self.systems.doubles;
5858
5959 # linux kernel configuration
6060 kernel = callLibs ./kernel.nix;
@@ -63,14 +63,14 @@ let
6363 deepSeq elem elemAt filter genericClosure genList getAttr
6464 hasAttr head isAttrs isBool isInt isList isString length
6565 lessThan listToAttrs pathExists readFile replaceStrings seq
66− stringLength sub substring tail;
67− inherit (trivial) id const pipe concat or and bitAnd bitOr bitXor
68− bitNot boolToString mergeAttrs flip mapNullable inNixShell min max
66+ stringLength sub substring tail trace;
67+ inherit (self.trivial) id const pipe concat or and bitAnd bitOr bitXor
68+ bitNot boolToString mergeAttrs flip mapNullable inNixShell isFloat min max
6969 importJSON importTOML warn info showWarnings nixpkgsVersion version mod compare
7070 splitByAndCompare functionArgs setFunctionArgs isFunction toHexString toBaseDigits;
71− inherit (fixedPoints) fix fix' converge extends composeExtensions
71+ inherit (self.fixedPoints) fix fix' converge extends composeExtensions
7272 makeExtensible makeExtensibleWithCustomName;
73− inherit (attrsets) attrByPath hasAttrByPath setAttrByPath
73+ inherit (self.attrsets) attrByPath hasAttrByPath setAttrByPath
7474 getAttrFromPath attrVals attrValues getAttrs catAttrs filterAttrs
7575 filterAttrsRecursive foldAttrs collect nameValuePair mapAttrs
7676 mapAttrs' mapAttrsToList mapAttrsRecursive mapAttrsRecursiveCond
@@ -79,13 +79,13 @@ let
7979 recursiveUpdate matchAttrs overrideExisting getOutput getBin
8080 getLib getDev getMan chooseDevOutputs zipWithNames zip
8181 recurseIntoAttrs dontRecurseIntoAttrs;
82− inherit (lists) singleton forEach foldr fold foldl foldl' imap0 imap1
82+ inherit (self.lists) singleton forEach foldr fold foldl foldl' imap0 imap1
8383 concatMap flatten remove findSingle findFirst any all count
8484 optional optionals toList range partition zipListsWith zipLists
8585 reverseList listDfs toposort sort naturalSort compareLists take
8686 drop sublist last init crossLists unique intersectLists
8787 subtractLists mutuallyExclusive groupBy groupBy';
88− inherit (strings) concatStrings concatMapStrings concatImapStrings
88+ inherit (self.strings) concatStrings concatMapStrings concatImapStrings
8989 intersperse concatStringsSep concatMapStringsSep
9090 concatImapStringsSep makeSearchPath makeSearchPathOutput
9191 makeLibraryPath makeBinPath optionalString
@@ -97,19 +97,19 @@ let
9797 nameFromURL enableFeature enableFeatureAs withFeature
9898 withFeatureAs fixedWidthString fixedWidthNumber isStorePath
9999 toInt readPathsFromFile fileContents;
100− inherit (stringsWithDeps) textClosureList textClosureMap
100+ inherit (self.stringsWithDeps) textClosureList textClosureMap
101101 noDepEntry fullDepEntry packEntry stringAfter;
102− inherit (customisation) overrideDerivation makeOverridable
102+ inherit (self.customisation) overrideDerivation makeOverridable
103103 callPackageWith callPackagesWith extendDerivation hydraJob
104104 makeScope;
105− inherit (meta) addMetaAttrs dontDistribute setName updateName
105+ inherit (self.meta) addMetaAttrs dontDistribute setName updateName
106106 appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio
107107 hiPrioSet;
108− inherit (sources) pathType pathIsDirectory cleanSourceFilter
108+ inherit (self.sources) pathType pathIsDirectory cleanSourceFilter
109109 cleanSource sourceByRegex sourceFilesBySuffices
110110 commitIdFromGitRepo cleanSourceWith pathHasContext
111111 canCleanSource pathIsRegularFile pathIsGitRepo;
112− inherit (modules) evalModules unifyModuleSyntax
112+ inherit (self.modules) evalModules unifyModuleSyntax
113113 applyIfFunction mergeModules
114114 mergeModules' mergeOptionDecls evalOptionValue mergeDefinitions
115115 pushDownProperties dischargeProperties filterOverrides
@@ -119,21 +119,21 @@ let
119119 mkAliasAndWrapDefinitions fixMergeModules mkRemovedOptionModule
120120 mkRenamedOptionModule mkMergedOptionModule mkChangedOptionModule
121121 mkAliasOptionModule doRename;
122− inherit (options) isOption mkEnableOption mkSinkUndeclaredOptions
122+ inherit (self.options) isOption mkEnableOption mkSinkUndeclaredOptions
123123 mergeDefaultOption mergeOneOption mergeEqualOption getValues
124124 getFiles optionAttrSetToDocList optionAttrSetToDocList'
125125 scrubOptionValue literalExample showOption showFiles
126126 unknownModule mkOption;
127− inherit (types) isType setType defaultTypeMerge defaultFunctor
127+ inherit (self.types) isType setType defaultTypeMerge defaultFunctor
128128 isOptionType mkOptionType;
129− inherit (asserts)
129+ inherit (self.asserts)
130130 assertMsg assertOneOf;
131− inherit (debug) addErrorContextToAttrs traceIf traceVal traceValFn
131+ inherit (self.debug) addErrorContextToAttrs traceIf traceVal traceValFn
132132 traceXMLVal traceXMLValMarked traceSeq traceSeqN traceValSeq
133133 traceValSeqFn traceValSeqN traceValSeqNFn traceShowVal
134134 traceShowValMarked showVal traceCall traceCall2 traceCall3
135135 traceValIfNot runTests testAllTrue traceCallXml attrNamesToStr;
136− inherit (misc) maybeEnv defaultMergeArg defaultMerge foldArgs
136+ inherit (self.misc) maybeEnv defaultMergeArg defaultMerge foldArgs
137137 maybeAttrNullable maybeAttr ifEnable checkFlag getValue
138138 checkReqs uniqList uniqListExt condConcat lazyGenericClosure
139139 innerModifySumArgs modifySumArgs innerClosePropagation
@@ -143,7 +143,7 @@ let
143143 mergeAttrsByFuncDefaultsClean mergeAttrBy
144144 fakeHash fakeSha256 fakeSha512
145145 nixType imap;
146− inherit (versions)
146+ inherit (self.versions)
147147 splitVersion;
148148 });
149149in lib
lib/lists.nix+1−1
@@ -1,9 +1,9 @@
11# General list operations.
22
33{ lib }:
4−with lib.trivial;
54let
65 inherit (lib.strings) toInt;
6+ inherit (lib.trivial) compare min;
77in
88rec {
99
lib/modules.nix+49−8
@@ -1,12 +1,53 @@
11{ lib }:
22
3−with lib.lists;
4−with lib.strings;
5−with lib.trivial;
6−with lib.attrsets;
7−with lib.options;
8−with lib.debug;
9−with lib.types;
3+let
4+ inherit (lib)
5+ all
6+ any
7+ attrByPath
8+ attrNames
9+ catAttrs
10+ concatLists
11+ concatMap
12+ count
13+ elem
14+ filter
15+ findFirst
16+ flip
17+ foldl
18+ foldl'
19+ getAttrFromPath
20+ head
21+ id
22+ imap1
23+ isAttrs
24+ isBool
25+ isFunction
26+ isString
27+ length
28+ mapAttrs
29+ mapAttrsToList
30+ mapAttrsRecursiveCond
31+ min
32+ optional
33+ optionalAttrs
34+ optionalString
35+ recursiveUpdate
36+ reverseList sort
37+ setAttrByPath
38+ toList
39+ types
40+ warn
41+ ;
42+ inherit (lib.options)
43+ isOption
44+ mkOption
45+ showDefs
46+ showFiles
47+ showOption
48+ unknownModule
49+ ;
50+in
1051
1152rec {
1253
@@ -616,7 +657,7 @@ rec {
616657 fixupOptionType = loc: opt:
617658 let
618659 options = opt.options or
619− (throw "Option `${showOption loc'}' has type optionSet but has no option attribute, in ${showFiles opt.declarations}.");
660+ (throw "Option `${showOption loc}' has type optionSet but has no option attribute, in ${showFiles opt.declarations}.");
620661 f = tp:
621662 let optionSetIn = type: (tp.name == type) && (tp.functor.wrapped.name == "optionSet");
622663 in
lib/options.nix+35−6
@@ -1,11 +1,40 @@
11# Nixpkgs/NixOS option handling.
22{ lib }:
33
4−with lib.trivial;
5−with lib.lists;
6−with lib.attrsets;
7−with lib.strings;
8−
4+let
5+ inherit (lib)
6+ all
7+ collect
8+ concatLists
9+ concatMap
10+ elemAt
11+ filter
12+ foldl'
13+ head
14+ isAttrs
15+ isBool
16+ isDerivation
17+ isFunction
18+ isInt
19+ isList
20+ isString
21+ length
22+ mapAttrs
23+ optional
24+ optionals
25+ take
26+ ;
27+ inherit (lib.attrsets)
28+ optionalAttrs
29+ ;
30+ inherit (lib.strings)
31+ concatMapStrings
32+ concatStringsSep
33+ ;
34+ inherit (lib.types)
35+ mkOptionType
36+ ;
37+in
938rec {
1039
1140 /* Returns true when the given argument is an option
@@ -110,7 +139,7 @@ rec {
110139 # Return early if we only have one element
111140 # This also makes it work for functions, because the foldl' below would try
112141 # to compare the first element with itself, which is false for functions
113− else if length defs == 1 then (elemAt defs 0).value
142+ else if length defs == 1 then (head defs).value
114143 else (foldl' (first: def:
115144 if def.value != first.value then
116145 throw "The option `${showOption loc}' has conflicting definition values:${showDefs [ first def ]}"
lib/sources.nix+28−12
@@ -1,16 +1,33 @@
11# Functions for copying sources to the Nix store.
22{ lib }:
33
4+let
5+ inherit (builtins)
6+ hasContext
7+ match
8+ readDir
9+ storeDir
10+ tryEval
11+ ;
12+ inherit (lib)
13+ filter
14+ getAttr
15+ isString
16+ pathExists
17+ readFile
18+ split
19+ ;
20+in
421rec {
522
623 # Returns the type of a path: regular (for file), symlink, or directory
7− pathType = p: with builtins; getAttr (baseNameOf p) (readDir (dirOf p));
24+ pathType = p: getAttr (baseNameOf p) (readDir (dirOf p));
825
926 # Returns true if the path exists and is a directory, false otherwise
10− pathIsDirectory = p: if builtins.pathExists p then (pathType p) == "directory" else false;
27+ pathIsDirectory = p: if pathExists p then (pathType p) == "directory" else false;
1128
1229 # Returns true if the path exists and is a regular file, false otherwise
13− pathIsRegularFile = p: if builtins.pathExists p then (pathType p) == "regular" else false;
30+ pathIsRegularFile = p: if pathExists p then (pathType p) == "regular" else false;
1431
1532 # Bring in a path as a source, filtering out all Subversion and CVS
1633 # directories, as well as backup files (*~).
@@ -19,8 +36,8 @@ rec {
1936 (baseName == ".git" || type == "directory" && (baseName == ".svn" || baseName == "CVS" || baseName == ".hg")) ||
2037 # Filter out editor backup / swap files.
2138 lib.hasSuffix "~" baseName ||
22− builtins.match "^\\.sw[a-z]$" baseName != null ||
23− builtins.match "^\\..*\\.sw[a-z]$" baseName != null ||
39+ match "^\\.sw[a-z]$" baseName != null ||
40+ match "^\\..*\\.sw[a-z]$" baseName != null ||
2441
2542 # Filter out generates files.
2643 lib.hasSuffix ".o" baseName ||
@@ -89,7 +106,7 @@ rec {
89106 in lib.cleanSourceWith {
90107 filter = (path: type:
91108 let relPath = lib.removePrefix (toString origSrc + "/") (toString path);
92− in lib.any (re: builtins.match re relPath != null) regexes);
109+ in lib.any (re: match re relPath != null) regexes);
93110 inherit src;
94111 };
95112
@@ -102,13 +119,12 @@ rec {
102119 in type == "directory" || lib.any (ext: lib.hasSuffix ext base) exts;
103120 in cleanSourceWith { inherit filter; src = path; };
104121
105− pathIsGitRepo = path: (builtins.tryEval (commitIdFromGitRepo path)).success;
122+ pathIsGitRepo = path: (tryEval (commitIdFromGitRepo path)).success;
106123
107124 # Get the commit id of a git repo
108125 # Example: commitIdFromGitRepo <nixpkgs/.git>
109126 commitIdFromGitRepo =
110127 let readCommitFromFile = file: path:
111− with builtins;
112128 let fileName = toString path + "/" + file;
113129 packedRefsName = toString path + "/packed-refs";
114130 absolutePath = base: path:
@@ -145,11 +161,11 @@ rec {
145161 # packed-refs file, so we have to grep through it:
146162 then
147163 let fileContent = readFile packedRefsName;
148− matchRef = builtins.match "([a-z0-9]+) ${file}";
149− isRef = s: builtins.isString s && (matchRef s) != null;
164+ matchRef = match "([a-z0-9]+) ${file}";
165+ isRef = s: isString s && (matchRef s) != null;
150166 # there is a bug in libstdc++ leading to stackoverflow for long strings:
151167 # https://github.com/NixOS/nix/issues/2147#issuecomment-659868795
152− refs = builtins.filter isRef (builtins.split "\n" fileContent);
168+ refs = filter isRef (split "\n" fileContent);
153169 in if refs == []
154170 then throw ("Could not find " + file + " in " + packedRefsName)
155171 else lib.head (matchRef (lib.head refs))
@@ -157,7 +173,7 @@ rec {
157173 else throw ("Not a .git directory: " + path);
158174 in readCommitFromFile "HEAD";
159175
160− pathHasContext = builtins.hasContext or (lib.hasPrefix builtins.storeDir);
176+ pathHasContext = builtins.hasContext or (lib.hasPrefix storeDir);
161177
162178 canCleanSource = src: src ? _isLibCleanSourceWith || !(pathHasContext (toString src));
163179}
lib/strings-with-deps.nix+9−4
@@ -41,10 +41,15 @@ Usage:
4141 [1] maybe this behaviour should be removed to keep things simple (?)
4242*/
4343
44−with lib.lists;
45−with lib.attrsets;
46−with lib.strings;
47−
44+let
45+ inherit (lib)
46+ concatStringsSep
47+ head
48+ isAttrs
49+ listToAttrs
50+ tail
51+ ;
52+in
4853rec {
4954
5055 /* !!! The interface of this function is kind of messed up, since
lib/strings.nix+43−21
@@ -8,7 +8,29 @@ in
88
99rec {
1010
11− inherit (builtins) stringLength substring head tail isString replaceStrings;
11+ inherit (builtins)
12+ compareVersions
13+ elem
14+ elemAt
15+ filter
16+ fromJSON
17+ head
18+ isInt
19+ isList
20+ isString
21+ match
22+ parseDrvName
23+ readFile
24+ replaceStrings
25+ split
26+ storeDir
27+ stringLength
28+ substring
29+ tail
30+ toJSON
31+ typeOf
32+ unsafeDiscardStringContext
33+ ;
1234
1335 /* Concatenate a list of strings.
1436
@@ -120,7 +142,7 @@ rec {
120142 subDir:
121143 # List of base paths
122144 paths:
123− concatStringsSep ":" (map (path: path + "/" + subDir) (builtins.filter (x: x != null) paths));
145+ concatStringsSep ":" (map (path: path + "/" + subDir) (filter (x: x != null) paths));
124146
125147 /* Construct a Unix-style search path by appending the given
126148 `subDir` to the specified `output` of each of the packages. If no
@@ -313,7 +335,7 @@ rec {
313335 escapeNixString "hello\${}\n"
314336 => "\"hello\\\${}\\n\""
315337 */
316− escapeNixString = s: escape ["$"] (builtins.toJSON s);
338+ escapeNixString = s: escape ["$"] (toJSON s);
317339
318340 /* Turn a string into an exact regular expression
319341
@@ -337,7 +359,7 @@ rec {
337359 */
338360 escapeNixIdentifier = s:
339361 # Regex from https://github.com/NixOS/nix/blob/d048577909e383439c2549e849c5c2f2016c997e/src/libexpr/lexer.l#L91
340− if builtins.match "[a-zA-Z_][a-zA-Z0-9_'-]*" s != null
362+ if match "[a-zA-Z_][a-zA-Z0-9_'-]*" s != null
341363 then s else escapeNixString s;
342364
343365 # Obsolete - use replaceStrings instead.
@@ -466,7 +488,7 @@ rec {
466488 versionOlder "1.1" "1.1"
467489 => false
468490 */
469− versionOlder = v1: v2: builtins.compareVersions v2 v1 == 1;
491+ versionOlder = v1: v2: compareVersions v2 v1 == 1;
470492
471493 /* Return true if string v1 denotes a version equal to or newer than v2.
472494
@@ -492,7 +514,7 @@ rec {
492514 */
493515 getName = x:
494516 let
495− parse = drv: (builtins.parseDrvName drv).name;
517+ parse = drv: (parseDrvName drv).name;
496518 in if isString x
497519 then parse x
498520 else x.pname or (parse x.name);
@@ -509,7 +531,7 @@ rec {
509531 */
510532 getVersion = x:
511533 let
512− parse = drv: (builtins.parseDrvName drv).version;
534+ parse = drv: (parseDrvName drv).version;
513535 in if isString x
514536 then parse x
515537 else x.version or (parse x.name);
@@ -527,7 +549,7 @@ rec {
527549 let
528550 components = splitString "/" url;
529551 filename = lib.last components;
530− name = builtins.head (splitString sep filename);
552+ name = head (splitString sep filename);
531553 in assert name != filename; name;
532554
533555 /* Create an --{enable,disable}-<feat> string that can be passed to
@@ -617,14 +639,14 @@ rec {
617639 */
618640 floatToString = float: let
619641 result = toString float;
620− precise = float == builtins.fromJSON result;
642+ precise = float == fromJSON result;
621643 in if precise then result
622644 else lib.warn "Imprecise conversion from float to string ${result}" result;
623645
624646 /* Check whether a value can be coerced to a string */
625647 isCoercibleToString = x:
626− builtins.elem (builtins.typeOf x) [ "path" "string" "null" "int" "float" "bool" ] ||
627− (builtins.isList x && lib.all isCoercibleToString x) ||
648+ elem (typeOf x) [ "path" "string" "null" "int" "float" "bool" ] ||
649+ (isList x && lib.all isCoercibleToString x) ||
628650 x ? outPath ||
629651 x ? __toString;
630652
@@ -643,8 +665,8 @@ rec {
643665 isStorePath = x:
644666 if isCoercibleToString x then
645667 let str = toString x; in
646− builtins.substring 0 1 str == "/"
647− && dirOf str == builtins.storeDir
668+ substring 0 1 str == "/"
669+ && dirOf str == storeDir
648670 else
649671 false;
650672
@@ -662,8 +684,8 @@ rec {
662684 */
663685 # Obviously, it is a bit hacky to use fromJSON this way.
664686 toInt = str:
665− let may_be_int = builtins.fromJSON str; in
666− if builtins.isInt may_be_int
687+ let may_be_int = fromJSON str; in
688+ if isInt may_be_int
667689 then may_be_int
668690 else throw "Could not convert ${str} to int.";
669691
@@ -685,10 +707,10 @@ rec {
685707 readPathsFromFile = lib.warn "lib.readPathsFromFile is deprecated, use a list instead"
686708 (rootPath: file:
687709 let
688− lines = lib.splitString "\n" (builtins.readFile file);
710+ lines = lib.splitString "\n" (readFile file);
689711 removeComments = lib.filter (line: line != "" && !(lib.hasPrefix "#" line));
690712 relativePaths = removeComments lines;
691− absolutePaths = builtins.map (path: rootPath + "/${path}") relativePaths;
713+ absolutePaths = map (path: rootPath + "/${path}") relativePaths;
692714 in
693715 absolutePaths);
694716
@@ -702,7 +724,7 @@ rec {
702724 fileContents ./version
703725 => "1.0"
704726 */
705− fileContents = file: removeSuffix "\n" (builtins.readFile file);
727+ fileContents = file: removeSuffix "\n" (readFile file);
706728
707729
708730 /* Creates a valid derivation name from a potentially invalid one.
@@ -720,13 +742,13 @@ rec {
720742 sanitizeDerivationName = string: lib.pipe string [
721743 # Get rid of string context. This is safe under the assumption that the
722744 # resulting string is only used as a derivation name
723− builtins.unsafeDiscardStringContext
745+ unsafeDiscardStringContext
724746 # Strip all leading "."
725− (x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0)
747+ (x: elemAt (match "\\.*(.*)" x) 0)
726748 # Split out all invalid characters
727749 # https://github.com/NixOS/nix/blob/2.3.2/src/libstore/store-api.cc#L85-L112
728750 # https://github.com/NixOS/nix/blob/2242be83c61788b9c0736a92bb0b5c7bbfc40803/nix-rust/src/store/path.rs#L100-L125
729− (builtins.split "[^[:alnum:]+._?=-]+")
751+ (split "[^[:alnum:]+._?=-]+")
730752 # Replace invalid character ranges with a "-"
731753 (concatMapStrings (s: if lib.isList s then "-" else s))
732754 # Limit to 211 characters (minus 4 chars for ".drv")
lib/types.nix+56−6
@@ -1,12 +1,62 @@
11# Definitions related to run-time type checking. Used in particular
22# to type-check NixOS configurations.
33{ lib }:
4−with lib.lists;
5−with lib.attrsets;
6−with lib.options;
7−with lib.trivial;
8−with lib.strings;
4+
95let
6+ inherit (lib)
7+ elem
8+ flip
9+ functionArgs
10+ isAttrs
11+ isBool
12+ isDerivation
13+ isFloat
14+ isFunction
15+ isInt
16+ isList
17+ isString
18+ isStorePath
19+ setFunctionArgs
20+ toDerivation
21+ toList
22+ ;
23+ inherit (lib.lists)
24+ all
25+ concatLists
26+ count
27+ elemAt
28+ filter
29+ foldl'
30+ head
31+ imap1
32+ last
33+ length
34+ tail
35+ unique
36+ ;
37+ inherit (lib.attrsets)
38+ attrNames
39+ filterAttrs
40+ hasAttr
41+ mapAttrs
42+ optionalAttrs
43+ zipAttrsWith
44+ ;
45+ inherit (lib.options)
46+ getFiles
47+ getValues
48+ mergeDefaultOption
49+ mergeEqualOption
50+ mergeOneOption
51+ showFiles
52+ showOption
53+ ;
54+ inherit (lib.strings)
55+ concatMapStringsSep
56+ concatStringsSep
57+ escapeNixString
58+ isCoercibleToString
59+ ;
1060
1161 inherit (lib.modules) mergeDefinitions;
1262 outer_types =
@@ -270,7 +320,7 @@ rec {
270320 name = "attrs";
271321 description = "attribute set";
272322 check = isAttrs;
273− merge = loc: foldl' (res: def: mergeAttrs res def.value) {};
323+ merge = loc: foldl' (res: def: res // def.value) {};
274324 emptyValue = { value = {}; };
275325 };
276326