at 22.05-pre 2.9 kB view raw
1/* Some functions for manipulating meta attributes, as well as the 2 name attribute. */ 3 4{ lib }: 5 6rec { 7 8 9 /* Add to or override the meta attributes of the given 10 derivation. 11 12 Example: 13 addMetaAttrs {description = "Bla blah";} somePkg 14 */ 15 addMetaAttrs = newAttrs: drv: 16 drv // { meta = (drv.meta or {}) // newAttrs; }; 17 18 19 /* Disable Hydra builds of given derivation. 20 */ 21 dontDistribute = drv: addMetaAttrs { hydraPlatforms = []; } drv; 22 23 24 /* Change the symbolic name of a package for presentation purposes 25 (i.e., so that nix-env users can tell them apart). 26 */ 27 setName = name: drv: drv // {inherit name;}; 28 29 30 /* Like `setName', but takes the previous name as an argument. 31 32 Example: 33 updateName (oldName: oldName + "-experimental") somePkg 34 */ 35 updateName = updater: drv: drv // {name = updater (drv.name);}; 36 37 38 /* Append a suffix to the name of a package (before the version 39 part). */ 40 appendToName = suffix: updateName (name: 41 let x = builtins.parseDrvName name; in "${x.name}-${suffix}-${x.version}"); 42 43 44 /* Apply a function to each derivation and only to derivations in an attrset. 45 */ 46 mapDerivationAttrset = f: set: lib.mapAttrs (name: pkg: if lib.isDerivation pkg then (f pkg) else pkg) set; 47 48 /* Set the nix-env priority of the package. 49 */ 50 setPrio = priority: addMetaAttrs { inherit priority; }; 51 52 /* Decrease the nix-env priority of the package, i.e., other 53 versions/variants of the package will be preferred. 54 */ 55 lowPrio = setPrio 10; 56 57 /* Apply lowPrio to an attrset with derivations 58 */ 59 lowPrioSet = set: mapDerivationAttrset lowPrio set; 60 61 62 /* Increase the nix-env priority of the package, i.e., this 63 version/variant of the package will be preferred. 64 */ 65 hiPrio = setPrio (-10); 66 67 /* Apply hiPrio to an attrset with derivations 68 */ 69 hiPrioSet = set: mapDerivationAttrset hiPrio set; 70 71 72 /* Check to see if a platform is matched by the given `meta.platforms` 73 element. 74 75 A `meta.platform` pattern is either 76 77 1. (legacy) a system string. 78 79 2. (modern) a pattern for the platform `parsed` field. 80 81 We can inject these into a patten for the whole of a structured platform, 82 and then match that. 83 */ 84 platformMatch = platform: elem: let 85 pattern = 86 if builtins.isString elem 87 then { system = elem; } 88 else { parsed = elem; }; 89 in lib.matchAttrs pattern platform; 90 91 /* Check if a package is available on a given platform. 92 93 A package is available on a platform if both 94 95 1. One of `meta.platforms` pattern matches the given platform. 96 97 2. None of `meta.badPlatforms` pattern matches the given platform. 98 */ 99 availableOn = platform: pkg: 100 lib.any (platformMatch platform) pkg.meta.platforms && 101 lib.all (elem: !platformMatch platform elem) (pkg.meta.badPlatforms or []); 102}