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