1/* Some functions for manipulating meta attributes, as well as the
2 name attribute. */
3
4let lib = import ./default.nix;
5in
6
7rec {
8
9
10 /* Add to or override the meta attributes of the given
11 derivation.
12
13 Example:
14 addMetaAttrs {description = "Bla blah";} somePkg
15 */
16 addMetaAttrs = newAttrs: drv:
17 drv // { meta = (drv.meta or {}) // newAttrs; };
18
19
20 /* Change the symbolic name of a package for presentation purposes
21 (i.e., so that nix-env users can tell them apart).
22 */
23 setName = name: drv: drv // {inherit name;};
24
25
26 /* Like `setName', but takes the previous name as an argument.
27
28 Example:
29 updateName (oldName: oldName + "-experimental") somePkg
30 */
31 updateName = updater: drv: drv // {name = updater (drv.name);};
32
33
34 /* Append a suffix to the name of a package (before the version
35 part). */
36 appendToName = suffix: updateName (name:
37 let x = builtins.parseDrvName name; in "${x.name}-${suffix}-${x.version}");
38
39
40 /* Apply a function to each derivation and only to derivations in an attrset
41 */
42 mapDerivationAttrset = f: set: lib.mapAttrs (name: pkg: if lib.isDerivation pkg then (f pkg) else pkg) set;
43
44
45 /* Decrease the nix-env priority of the package, i.e., other
46 versions/variants of the package will be preferred.
47 */
48 lowPrio = drv: addMetaAttrs { priority = "10"; } drv;
49
50
51 /* Apply lowPrio to an attrset with derivations
52 */
53 lowPrioSet = set: mapDerivationAttrset lowPrio set;
54
55
56 /* Increase the nix-env priority of the package, i.e., this
57 version/variant of the package will be preferred.
58 */
59 hiPrio = drv: addMetaAttrs { priority = "-10"; } drv;
60
61
62 /* Apply hiPrio to an attrset with derivations
63 */
64 hiPrioSet = set: mapDerivationAttrset hiPrio set;
65
66}