1/*
2 Library of low-level helper functions for nix expressions.
3
4 Please implement (mostly) exhaustive unit tests
5 for new functions in `./tests.nix`.
6*/
7let
8
9 # A copy of `lib.makeExtensible'` in order to document `extend`.
10 # It has been leading to some trouble, so we have to document it specially.
11 makeExtensible' =
12 rattrs:
13 let
14 self = rattrs self // {
15 /**
16 Patch the Nixpkgs library
17
18 A function that applies patches onto the nixpkgs library.
19 Usage is discouraged for most scenarios.
20
21 :::{.note}
22 The name `extends` is a bit misleading, as it doesn't actually extend the library, but rather patches it.
23 It is merely a consequence of being implemented by `makeExtensible`.
24 :::
25
26 # Inputs
27
28 - An "extension function" `f` that returns attributes that will be updated in the returned Nixpkgs library.
29
30 # Output
31
32 A patched Nixpkgs library.
33
34 :::{.warning}
35 This functionality is intended as an escape hatch for when the provided version of the Nixpkgs library has a flaw.
36
37 If you were to use it to add new functionality, you will run into compatibility and interoperability issues.
38 :::
39 */
40 extend = f: lib.makeExtensible (lib.extends f rattrs);
41 };
42 in
43 self;
44
45 lib = makeExtensible' (
46 self:
47 let
48 callLibs = file: import file { lib = self; };
49 in
50 {
51
52 # often used, or depending on very little
53 trivial = callLibs ./trivial.nix;
54 fixedPoints = callLibs ./fixed-points.nix;
55
56 # datatypes
57 attrsets = callLibs ./attrsets.nix;
58 lists = callLibs ./lists.nix;
59 strings = callLibs ./strings.nix;
60 stringsWithDeps = callLibs ./strings-with-deps.nix;
61
62 # packaging
63 customisation = callLibs ./customisation.nix;
64 derivations = callLibs ./derivations.nix;
65 maintainers = import ../maintainers/maintainer-list.nix;
66 teams = callLibs ../maintainers/team-list.nix;
67 meta = callLibs ./meta.nix;
68 versions = callLibs ./versions.nix;
69
70 # module system
71 modules = callLibs ./modules.nix;
72 options = callLibs ./options.nix;
73 types = callLibs ./types.nix;
74
75 # constants
76 licenses = callLibs ./licenses.nix;
77 sourceTypes = callLibs ./source-types.nix;
78 systems = callLibs ./systems;
79
80 # serialization
81 cli = callLibs ./cli.nix;
82 gvariant = callLibs ./gvariant.nix;
83 generators = callLibs ./generators.nix;
84
85 # misc
86 asserts = callLibs ./asserts.nix;
87 debug = callLibs ./debug.nix;
88 misc = callLibs ./deprecated/misc.nix;
89
90 # domain-specific
91 fetchers = callLibs ./fetchers.nix;
92
93 # Eval-time filesystem handling
94 path = callLibs ./path;
95 filesystem = callLibs ./filesystem.nix;
96 fileset = callLibs ./fileset;
97 sources = callLibs ./sources.nix;
98
99 # back-compat aliases
100 platforms = self.systems.doubles;
101
102 # linux kernel configuration
103 kernel = callLibs ./kernel.nix;
104
105 # network
106 network = callLibs ./network;
107
108 # TODO: For consistency, all builtins should also be available from a sub-library;
109 # these are the only ones that are currently not
110 inherit (builtins)
111 addErrorContext
112 isPath
113 trace
114 typeOf
115 unsafeGetAttrPos
116 ;
117 inherit (self.trivial)
118 id
119 const
120 pipe
121 concat
122 or
123 and
124 xor
125 bitAnd
126 bitOr
127 bitXor
128 bitNot
129 boolToString
130 mergeAttrs
131 flip
132 defaultTo
133 mapNullable
134 inNixShell
135 isFloat
136 min
137 max
138 importJSON
139 importTOML
140 warn
141 warnIf
142 warnIfNot
143 throwIf
144 throwIfNot
145 checkListOfEnum
146 info
147 showWarnings
148 nixpkgsVersion
149 version
150 isInOldestRelease
151 oldestSupportedReleaseIsAtLeast
152 mod
153 compare
154 splitByAndCompare
155 seq
156 deepSeq
157 lessThan
158 add
159 sub
160 functionArgs
161 setFunctionArgs
162 isFunction
163 toFunction
164 mirrorFunctionArgs
165 fromHexString
166 toHexString
167 toBaseDigits
168 inPureEvalMode
169 isBool
170 isInt
171 pathExists
172 genericClosure
173 readFile
174 ;
175 inherit (self.fixedPoints)
176 fix
177 fix'
178 converge
179 extends
180 composeExtensions
181 composeManyExtensions
182 makeExtensible
183 makeExtensibleWithCustomName
184 toExtension
185 ;
186 inherit (self.attrsets)
187 attrByPath
188 hasAttrByPath
189 setAttrByPath
190 getAttrFromPath
191 attrVals
192 attrNames
193 attrValues
194 getAttrs
195 catAttrs
196 filterAttrs
197 filterAttrsRecursive
198 foldlAttrs
199 foldAttrs
200 collect
201 nameValuePair
202 mapAttrs
203 mapAttrs'
204 mapAttrsToList
205 attrsToList
206 concatMapAttrs
207 mapAttrsRecursive
208 mapAttrsRecursiveCond
209 genAttrs
210 isDerivation
211 toDerivation
212 optionalAttrs
213 zipAttrsWithNames
214 zipAttrsWith
215 zipAttrs
216 recursiveUpdateUntil
217 recursiveUpdate
218 matchAttrs
219 mergeAttrsList
220 overrideExisting
221 showAttrPath
222 getOutput
223 getFirstOutput
224 getBin
225 getLib
226 getStatic
227 getDev
228 getInclude
229 getMan
230 chooseDevOutputs
231 zipWithNames
232 zip
233 recurseIntoAttrs
234 dontRecurseIntoAttrs
235 cartesianProduct
236 cartesianProductOfSets
237 mapCartesianProduct
238 updateManyAttrsByPath
239 listToAttrs
240 hasAttr
241 getAttr
242 isAttrs
243 intersectAttrs
244 removeAttrs
245 ;
246 inherit (self.lists)
247 singleton
248 forEach
249 map
250 foldr
251 fold
252 foldl
253 foldl'
254 imap0
255 imap1
256 filter
257 ifilter0
258 concatMap
259 flatten
260 remove
261 findSingle
262 findFirst
263 any
264 all
265 count
266 optional
267 optionals
268 toList
269 range
270 replicate
271 partition
272 zipListsWith
273 zipLists
274 reverseList
275 listDfs
276 toposort
277 sort
278 sortOn
279 naturalSort
280 compareLists
281 take
282 takeEnd
283 drop
284 dropEnd
285 sublist
286 last
287 init
288 crossLists
289 unique
290 allUnique
291 intersectLists
292 subtractLists
293 mutuallyExclusive
294 groupBy
295 groupBy'
296 concatLists
297 genList
298 length
299 head
300 tail
301 elem
302 elemAt
303 isList
304 ;
305 inherit (self.strings)
306 concatStrings
307 concatMapStrings
308 concatImapStrings
309 stringLength
310 substring
311 isString
312 replaceStrings
313 intersperse
314 concatStringsSep
315 concatMapStringsSep
316 concatMapAttrsStringSep
317 concatImapStringsSep
318 concatLines
319 makeSearchPath
320 makeSearchPathOutput
321 makeLibraryPath
322 makeIncludePath
323 makeBinPath
324 optionalString
325 hasInfix
326 hasPrefix
327 hasSuffix
328 stringToCharacters
329 stringAsChars
330 escape
331 escapeShellArg
332 escapeShellArgs
333 isStorePath
334 isStringLike
335 isValidPosixName
336 toShellVar
337 toShellVars
338 trim
339 trimWith
340 escapeRegex
341 escapeURL
342 escapeXML
343 replaceChars
344 lowerChars
345 upperChars
346 toLower
347 toUpper
348 toSentenceCase
349 addContextFrom
350 splitString
351 splitStringBy
352 removePrefix
353 removeSuffix
354 versionOlder
355 versionAtLeast
356 getName
357 getVersion
358 match
359 split
360 cmakeOptionType
361 cmakeBool
362 cmakeFeature
363 mesonOption
364 mesonBool
365 mesonEnable
366 nameFromURL
367 enableFeature
368 enableFeatureAs
369 withFeature
370 withFeatureAs
371 fixedWidthString
372 fixedWidthNumber
373 toInt
374 toIntBase10
375 readPathsFromFile
376 fileContents
377 ;
378 inherit (self.stringsWithDeps)
379 textClosureList
380 textClosureMap
381 noDepEntry
382 fullDepEntry
383 packEntry
384 stringAfter
385 ;
386 inherit (self.customisation)
387 overrideDerivation
388 makeOverridable
389 callPackageWith
390 callPackagesWith
391 extendDerivation
392 hydraJob
393 makeScope
394 makeScopeWithSplicing
395 makeScopeWithSplicing'
396 extendMkDerivation
397 ;
398 inherit (self.derivations) lazyDerivation optionalDrvAttr warnOnInstantiate;
399 inherit (self.generators) mkLuaInline;
400 inherit (self.meta)
401 addMetaAttrs
402 dontDistribute
403 setName
404 updateName
405 appendToName
406 mapDerivationAttrset
407 setPrio
408 lowPrio
409 lowPrioSet
410 hiPrio
411 hiPrioSet
412 licensesSpdx
413 getLicenseFromSpdxId
414 getLicenseFromSpdxIdOr
415 getExe
416 getExe'
417 ;
418 inherit (self.filesystem)
419 pathType
420 pathIsDirectory
421 pathIsRegularFile
422 packagesFromDirectoryRecursive
423 ;
424 inherit (self.sources)
425 cleanSourceFilter
426 cleanSource
427 sourceByRegex
428 sourceFilesBySuffices
429 commitIdFromGitRepo
430 cleanSourceWith
431 pathHasContext
432 canCleanSource
433 pathIsGitRepo
434 ;
435 inherit (self.modules)
436 evalModules
437 setDefaultModuleLocation
438 unifyModuleSyntax
439 applyModuleArgsIfFunction
440 mergeModules
441 mergeModules'
442 mergeOptionDecls
443 mergeDefinitions
444 pushDownProperties
445 dischargeProperties
446 filterOverrides
447 sortProperties
448 fixupOptionType
449 mkIf
450 mkAssert
451 mkDefinition
452 mkMerge
453 mkOverride
454 mkOptionDefault
455 mkDefault
456 mkImageMediaOverride
457 mkForce
458 mkVMOverride
459 mkFixStrictness
460 mkOrder
461 mkBefore
462 mkAfter
463 mkAliasDefinitions
464 mkAliasAndWrapDefinitions
465 fixMergeModules
466 mkRemovedOptionModule
467 mkRenamedOptionModule
468 mkRenamedOptionModuleWith
469 mkMergedOptionModule
470 mkChangedOptionModule
471 mkAliasOptionModule
472 mkDerivedConfig
473 doRename
474 mkAliasOptionModuleMD
475 ;
476 evalOptionValue = lib.warn "External use of `lib.evalOptionValue` is deprecated. If your use case isn't covered by non-deprecated functions, we'd like to know more and perhaps support your use case well, instead of providing access to these low level functions. In this case please open an issue in https://github.com/nixos/nixpkgs/issues/." self.modules.evalOptionValue;
477 inherit (self.options)
478 isOption
479 mkEnableOption
480 mkSinkUndeclaredOptions
481 mergeDefaultOption
482 mergeOneOption
483 mergeEqualOption
484 mergeUniqueOption
485 getValues
486 getFiles
487 optionAttrSetToDocList
488 optionAttrSetToDocList'
489 scrubOptionValue
490 literalExpression
491 literalExample
492 showOption
493 showOptionWithDefLocs
494 showFiles
495 unknownModule
496 mkOption
497 mkPackageOption
498 mkPackageOptionMD
499 literalMD
500 ;
501 inherit (self.types)
502 isType
503 setType
504 defaultTypeMerge
505 defaultFunctor
506 isOptionType
507 mkOptionType
508 ;
509 inherit (self.asserts)
510 assertMsg
511 assertOneOf
512 ;
513 inherit (self.debug)
514 traceIf
515 traceVal
516 traceValFn
517 traceSeq
518 traceSeqN
519 traceValSeq
520 traceValSeqFn
521 traceValSeqN
522 traceValSeqNFn
523 traceFnSeqN
524 runTests
525 testAllTrue
526 ;
527 inherit (self.misc)
528 maybeEnv
529 defaultMergeArg
530 defaultMerge
531 foldArgs
532 maybeAttrNullable
533 maybeAttr
534 ifEnable
535 checkFlag
536 getValue
537 checkReqs
538 uniqList
539 uniqListExt
540 condConcat
541 lazyGenericClosure
542 innerModifySumArgs
543 modifySumArgs
544 innerClosePropagation
545 closePropagation
546 mapAttrsFlatten
547 nvs
548 setAttr
549 setAttrMerge
550 mergeAttrsWithFunc
551 mergeAttrsConcatenateValues
552 mergeAttrsNoOverride
553 mergeAttrByFunc
554 mergeAttrsByFuncDefaults
555 mergeAttrsByFuncDefaultsClean
556 mergeAttrBy
557 fakeHash
558 fakeSha256
559 fakeSha512
560 nixType
561 imap
562 ;
563 inherit (self.versions)
564 splitVersion
565 ;
566 }
567 );
568in
569lib