Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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 replaceString 313 replaceStrings 314 intersperse 315 concatStringsSep 316 concatMapStringsSep 317 concatMapAttrsStringSep 318 concatImapStringsSep 319 concatLines 320 makeSearchPath 321 makeSearchPathOutput 322 makeLibraryPath 323 makeIncludePath 324 makeBinPath 325 optionalString 326 hasInfix 327 hasPrefix 328 hasSuffix 329 stringToCharacters 330 stringAsChars 331 escape 332 escapeShellArg 333 escapeShellArgs 334 isStorePath 335 isStringLike 336 isValidPosixName 337 toShellVar 338 toShellVars 339 trim 340 trimWith 341 escapeRegex 342 escapeURL 343 escapeXML 344 replaceChars 345 lowerChars 346 upperChars 347 toLower 348 toUpper 349 toCamelCase 350 toSentenceCase 351 addContextFrom 352 splitString 353 splitStringBy 354 removePrefix 355 removeSuffix 356 versionOlder 357 versionAtLeast 358 getName 359 getVersion 360 match 361 split 362 cmakeOptionType 363 cmakeBool 364 cmakeFeature 365 mesonOption 366 mesonBool 367 mesonEnable 368 nameFromURL 369 enableFeature 370 enableFeatureAs 371 withFeature 372 withFeatureAs 373 fixedWidthString 374 fixedWidthNumber 375 toInt 376 toIntBase10 377 readPathsFromFile 378 fileContents 379 ; 380 inherit (self.stringsWithDeps) 381 textClosureList 382 textClosureMap 383 noDepEntry 384 fullDepEntry 385 packEntry 386 stringAfter 387 ; 388 inherit (self.customisation) 389 overrideDerivation 390 makeOverridable 391 callPackageWith 392 callPackagesWith 393 extendDerivation 394 hydraJob 395 makeScope 396 makeScopeWithSplicing 397 makeScopeWithSplicing' 398 extendMkDerivation 399 ; 400 inherit (self.derivations) lazyDerivation optionalDrvAttr warnOnInstantiate; 401 inherit (self.generators) mkLuaInline; 402 inherit (self.meta) 403 addMetaAttrs 404 dontDistribute 405 setName 406 updateName 407 appendToName 408 mapDerivationAttrset 409 setPrio 410 lowPrio 411 lowPrioSet 412 hiPrio 413 hiPrioSet 414 licensesSpdx 415 getLicenseFromSpdxId 416 getLicenseFromSpdxIdOr 417 getExe 418 getExe' 419 ; 420 inherit (self.filesystem) 421 pathType 422 pathIsDirectory 423 pathIsRegularFile 424 packagesFromDirectoryRecursive 425 ; 426 inherit (self.sources) 427 cleanSourceFilter 428 cleanSource 429 sourceByRegex 430 sourceFilesBySuffices 431 commitIdFromGitRepo 432 cleanSourceWith 433 pathHasContext 434 canCleanSource 435 pathIsGitRepo 436 revOrTag 437 repoRevToName 438 ; 439 inherit (self.modules) 440 evalModules 441 setDefaultModuleLocation 442 unifyModuleSyntax 443 applyModuleArgsIfFunction 444 mergeModules 445 mergeModules' 446 mergeOptionDecls 447 mergeDefinitions 448 pushDownProperties 449 dischargeProperties 450 filterOverrides 451 sortProperties 452 fixupOptionType 453 mkIf 454 mkAssert 455 mkDefinition 456 mkMerge 457 mkOverride 458 mkOptionDefault 459 mkDefault 460 mkImageMediaOverride 461 mkForce 462 mkVMOverride 463 mkFixStrictness 464 mkOrder 465 mkBefore 466 mkAfter 467 mkAliasDefinitions 468 mkAliasAndWrapDefinitions 469 fixMergeModules 470 mkRemovedOptionModule 471 mkRenamedOptionModule 472 mkRenamedOptionModuleWith 473 mkMergedOptionModule 474 mkChangedOptionModule 475 mkAliasOptionModule 476 mkDerivedConfig 477 doRename 478 mkAliasOptionModuleMD 479 ; 480 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; 481 inherit (self.options) 482 isOption 483 mkEnableOption 484 mkSinkUndeclaredOptions 485 mergeDefaultOption 486 mergeOneOption 487 mergeEqualOption 488 mergeUniqueOption 489 getValues 490 getFiles 491 optionAttrSetToDocList 492 optionAttrSetToDocList' 493 scrubOptionValue 494 literalExpression 495 literalExample 496 showOption 497 showOptionWithDefLocs 498 showFiles 499 unknownModule 500 mkOption 501 mkPackageOption 502 mkPackageOptionMD 503 literalMD 504 ; 505 inherit (self.types) 506 isType 507 setType 508 defaultTypeMerge 509 defaultFunctor 510 isOptionType 511 mkOptionType 512 ; 513 inherit (self.asserts) 514 assertMsg 515 assertOneOf 516 ; 517 inherit (self.debug) 518 traceIf 519 traceVal 520 traceValFn 521 traceSeq 522 traceSeqN 523 traceValSeq 524 traceValSeqFn 525 traceValSeqN 526 traceValSeqNFn 527 traceFnSeqN 528 runTests 529 testAllTrue 530 ; 531 inherit (self.misc) 532 maybeEnv 533 defaultMergeArg 534 defaultMerge 535 foldArgs 536 maybeAttrNullable 537 maybeAttr 538 ifEnable 539 checkFlag 540 getValue 541 checkReqs 542 uniqList 543 uniqListExt 544 condConcat 545 lazyGenericClosure 546 innerModifySumArgs 547 modifySumArgs 548 innerClosePropagation 549 closePropagation 550 mapAttrsFlatten 551 nvs 552 setAttr 553 setAttrMerge 554 mergeAttrsWithFunc 555 mergeAttrsConcatenateValues 556 mergeAttrsNoOverride 557 mergeAttrByFunc 558 mergeAttrsByFuncDefaults 559 mergeAttrsByFuncDefaultsClean 560 mergeAttrBy 561 fakeHash 562 fakeSha256 563 fakeSha512 564 nixType 565 imap 566 ; 567 inherit (self.versions) 568 splitVersion 569 ; 570 } 571 ); 572in 573lib