nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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/computed-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 boolToYesNo
131 mergeAttrs
132 flip
133 defaultTo
134 mapNullable
135 inNixShell
136 isFloat
137 min
138 max
139 importJSON
140 importTOML
141 warn
142 warnIf
143 warnIfNot
144 throwIf
145 throwIfNot
146 checkListOfEnum
147 info
148 showWarnings
149 nixpkgsVersion
150 version
151 isInOldestRelease
152 oldestSupportedReleaseIsAtLeast
153 mod
154 compare
155 splitByAndCompare
156 seq
157 deepSeq
158 lessThan
159 add
160 sub
161 functionArgs
162 setFunctionArgs
163 isFunction
164 toFunction
165 mirrorFunctionArgs
166 fromHexString
167 toHexString
168 toBaseDigits
169 inPureEvalMode
170 isBool
171 isInt
172 pathExists
173 genericClosure
174 readFile
175 ;
176 inherit (self.fixedPoints)
177 fix
178 fix'
179 converge
180 extends
181 composeExtensions
182 composeManyExtensions
183 makeExtensible
184 makeExtensibleWithCustomName
185 toExtension
186 ;
187 inherit (self.attrsets)
188 attrByPath
189 hasAttrByPath
190 setAttrByPath
191 getAttrFromPath
192 attrVals
193 attrNames
194 attrValues
195 getAttrs
196 catAttrs
197 filterAttrs
198 filterAttrsRecursive
199 foldlAttrs
200 foldAttrs
201 collect
202 nameValuePair
203 mapAttrs
204 mapAttrs'
205 mapAttrsToList
206 attrsToList
207 concatMapAttrs
208 mapAttrsRecursive
209 mapAttrsRecursiveCond
210 mapAttrsToListRecursive
211 mapAttrsToListRecursiveCond
212 genAttrs
213 genAttrs'
214 isDerivation
215 toDerivation
216 optionalAttrs
217 zipAttrsWithNames
218 zipAttrsWith
219 zipAttrs
220 recursiveUpdateUntil
221 recursiveUpdate
222 matchAttrs
223 mergeAttrsList
224 overrideExisting
225 showAttrPath
226 getOutput
227 getFirstOutput
228 getBin
229 getLib
230 getStatic
231 getDev
232 getInclude
233 getMan
234 chooseDevOutputs
235 recurseIntoAttrs
236 dontRecurseIntoAttrs
237 cartesianProduct
238 mapCartesianProduct
239 updateManyAttrsByPath
240 listToAttrs
241 hasAttr
242 getAttr
243 isAttrs
244 intersectAttrs
245 removeAttrs
246 ;
247 inherit (self.lists)
248 singleton
249 forEach
250 map
251 foldr
252 fold
253 foldl
254 foldl'
255 imap0
256 imap1
257 filter
258 ifilter0
259 concatMap
260 flatten
261 remove
262 findSingle
263 findFirst
264 any
265 all
266 count
267 optional
268 optionals
269 toList
270 range
271 replicate
272 partition
273 zipListsWith
274 zipLists
275 reverseList
276 listDfs
277 toposort
278 sort
279 sortOn
280 naturalSort
281 compareLists
282 take
283 takeEnd
284 drop
285 dropEnd
286 sublist
287 last
288 init
289 crossLists
290 unique
291 uniqueStrings
292 allUnique
293 intersectLists
294 subtractLists
295 mutuallyExclusive
296 groupBy
297 groupBy'
298 concatLists
299 genList
300 length
301 head
302 tail
303 elem
304 elemAt
305 isList
306 concatAttrValues
307 ;
308 inherit (self.strings)
309 concatStrings
310 concatMapStrings
311 concatImapStrings
312 stringLength
313 substring
314 isString
315 replaceString
316 replaceStrings
317 intersperse
318 concatStringsSep
319 concatMapStringsSep
320 concatMapAttrsStringSep
321 concatImapStringsSep
322 concatLines
323 makeSearchPath
324 makeSearchPathOutput
325 makeLibraryPath
326 makeIncludePath
327 makeBinPath
328 optionalString
329 hasInfix
330 hasPrefix
331 hasSuffix
332 join
333 stringToCharacters
334 stringAsChars
335 escape
336 escapeShellArg
337 escapeShellArgs
338 isStorePath
339 isStringLike
340 isValidPosixName
341 toShellVar
342 toShellVars
343 trim
344 trimWith
345 escapeRegex
346 escapeURL
347 escapeXML
348 lowerChars
349 upperChars
350 toLower
351 toUpper
352 toCamelCase
353 toSentenceCase
354 addContextFrom
355 splitString
356 splitStringBy
357 removePrefix
358 removeSuffix
359 versionOlder
360 versionAtLeast
361 getName
362 getVersion
363 match
364 split
365 cmakeOptionType
366 cmakeBool
367 cmakeFeature
368 mesonOption
369 mesonBool
370 mesonEnable
371 nameFromURL
372 enableFeature
373 enableFeatureAs
374 withFeature
375 withFeatureAs
376 fixedWidthString
377 fixedWidthNumber
378 toInt
379 toIntBase10
380 fileContents
381 ;
382 inherit (self.stringsWithDeps)
383 textClosureList
384 textClosureMap
385 noDepEntry
386 fullDepEntry
387 packEntry
388 stringAfter
389 ;
390 inherit (self.customisation)
391 overrideDerivation
392 makeOverridable
393 callPackageWith
394 callPackagesWith
395 extendDerivation
396 hydraJob
397 makeScope
398 makeScopeWithSplicing
399 makeScopeWithSplicing'
400 extendMkDerivation
401 renameCrossIndexFrom
402 renameCrossIndexTo
403 mapCrossIndex
404 ;
405 inherit (self.derivations) lazyDerivation optionalDrvAttr warnOnInstantiate;
406 inherit (self.generators) mkLuaInline;
407 inherit (self.meta)
408 addMetaAttrs
409 dontDistribute
410 setName
411 updateName
412 appendToName
413 mapDerivationAttrset
414 setPrio
415 lowPrio
416 lowPrioSet
417 hiPrio
418 hiPrioSet
419 licensesSpdx
420 getLicenseFromSpdxId
421 getLicenseFromSpdxIdOr
422 getExe
423 getExe'
424 ;
425 inherit (self.filesystem)
426 pathType
427 pathIsDirectory
428 pathIsRegularFile
429 packagesFromDirectoryRecursive
430 ;
431 inherit (self.sources)
432 cleanSourceFilter
433 cleanSource
434 sourceByRegex
435 sourceFilesBySuffices
436 commitIdFromGitRepo
437 cleanSourceWith
438 pathHasContext
439 canCleanSource
440 pathIsGitRepo
441 revOrTag
442 repoRevToName
443 ;
444 inherit (self.modules)
445 evalModules
446 setDefaultModuleLocation
447 unifyModuleSyntax
448 applyModuleArgsIfFunction
449 mergeModules
450 mergeModules'
451 mergeOptionDecls
452 mergeDefinitions
453 pushDownProperties
454 dischargeProperties
455 filterOverrides
456 sortProperties
457 fixupOptionType
458 mkIf
459 mkAssert
460 mkDefinition
461 mkMerge
462 mkOverride
463 mkOptionDefault
464 mkDefault
465 mkImageMediaOverride
466 mkForce
467 mkVMOverride
468 mkFixStrictness
469 mkOrder
470 mkBefore
471 mkAfter
472 mkAliasDefinitions
473 mkAliasAndWrapDefinitions
474 fixMergeModules
475 mkRemovedOptionModule
476 mkRenamedOptionModule
477 mkRenamedOptionModuleWith
478 mkMergedOptionModule
479 mkChangedOptionModule
480 mkAliasOptionModule
481 mkDerivedConfig
482 doRename
483 mkAliasOptionModuleMD
484 ;
485 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;
486 inherit (self.options)
487 isOption
488 mkEnableOption
489 mkSinkUndeclaredOptions
490 mergeDefaultOption
491 mergeOneOption
492 mergeEqualOption
493 mergeUniqueOption
494 getValues
495 getFiles
496 optionAttrSetToDocList
497 optionAttrSetToDocList'
498 scrubOptionValue
499 literalExpression
500 showOption
501 showOptionWithDefLocs
502 showFiles
503 unknownModule
504 mkOption
505 mkPackageOption
506 literalMD
507 ;
508 inherit (self.types)
509 isType
510 setType
511 defaultTypeMerge
512 defaultFunctor
513 isOptionType
514 mkOptionType
515 ;
516 inherit (self.asserts)
517 assertMsg
518 assertOneOf
519 ;
520 inherit (self.debug)
521 traceIf
522 traceVal
523 traceValFn
524 traceSeq
525 traceSeqN
526 traceValSeq
527 traceValSeqFn
528 traceValSeqN
529 traceValSeqNFn
530 traceFnSeqN
531 runTests
532 testAllTrue
533 ;
534 inherit (self.misc)
535 maybeEnv
536 defaultMergeArg
537 defaultMerge
538 foldArgs
539 maybeAttrNullable
540 maybeAttr
541 ifEnable
542 checkFlag
543 getValue
544 checkReqs
545 uniqList
546 uniqListExt
547 condConcat
548 lazyGenericClosure
549 innerModifySumArgs
550 modifySumArgs
551 innerClosePropagation
552 closePropagation
553 nvs
554 setAttr
555 setAttrMerge
556 mergeAttrsWithFunc
557 mergeAttrsConcatenateValues
558 mergeAttrsNoOverride
559 mergeAttrByFunc
560 mergeAttrsByFuncDefaults
561 mergeAttrsByFuncDefaultsClean
562 mergeAttrBy
563 fakeHash
564 fakeSha256
565 fakeSha512
566 nixType
567 imap
568 ;
569 inherit (self.versions)
570 splitVersion
571 ;
572 inherit (self.network.ipv6)
573 mkEUI64Suffix
574 ;
575 }
576 );
577in
578lib