1 /* Some functions for manipulating meta attributes, as well as the
9 /* Add to or override the meta attributes of the given
13 addMetaAttrs {description = "Bla blah";} somePkg
15 addMetaAttrs = newAttrs: drv:
16 drv // { meta = (drv.meta or {}) // newAttrs; };
19 /* Disable Hydra builds of given derivation.
21 dontDistribute = drv: addMetaAttrs { hydraPlatforms = []; } drv;
24 /* Change the symbolic name of a package for presentation purposes
25 (i.e., so that nix-env users can tell them apart).
27 setName = name: drv: drv // {inherit name;};
30 /* Like `setName', but takes the previous name as an argument.
33 updateName (oldName: oldName + "-experimental") somePkg
35 updateName = updater: drv: drv // {name = updater (drv.name);};
38 /* Append a suffix to the name of a package (before the version
40 appendToName = suffix: updateName (name:
41 let x = builtins.parseDrvName name; in "${x.name}-${suffix}-${x.version}");
44 /* Apply a function to each derivation and only to derivations in an attrset.
46 mapDerivationAttrset = f: set: lib.mapAttrs (name: pkg: if lib.isDerivation pkg then (f pkg) else pkg) set;
48 /* Set the nix-env priority of the package.
50 setPrio = priority: addMetaAttrs { inherit priority; };
52 /* Decrease the nix-env priority of the package, i.e., other
53 versions/variants of the package will be preferred.
57 /* Apply lowPrio to an attrset with derivations
59 lowPrioSet = set: mapDerivationAttrset lowPrio set;
62 /* Increase the nix-env priority of the package, i.e., this
63 version/variant of the package will be preferred.
65 hiPrio = setPrio (-10);
67 /* Apply hiPrio to an attrset with derivations
69 hiPrioSet = set: mapDerivationAttrset hiPrio set;
72 /* Check to see if a platform is matched by the given `meta.platforms`
75 A `meta.platform` pattern is either
77 1. (legacy) a system string.
79 2. (modern) a pattern for the platform `parsed` field.
81 We can inject these into a patten for the whole of a structured platform,
84 platformMatch = platform: elem: let
86 if builtins.isString elem
87 then { system = elem; }
88 else { parsed = elem; };
89 in lib.matchAttrs pattern platform;
91 /* Check if a package is available on a given platform.
93 A package is available on a platform if both
95 1. One of `meta.platforms` pattern matches the given platform.
97 2. None of `meta.badPlatforms` pattern matches the given platform.
99 availableOn = platform: pkg:
100 lib.any (platformMatch platform) pkg.meta.platforms &&
101 lib.all (elem: !platformMatch platform elem) (pkg.meta.badPlatforms or []);