-
Notifications
You must be signed in to change notification settings - Fork 54
/
exportPackages.nix
91 lines (73 loc) · 2.96 KB
/
exportPackages.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
{ flake-utils-plus }:
let
exportPackagesBuilder = overlays:
let
# overlays: self.overlays
exportPackages = channels:
/**
Synopsis: exportPackagesBuilder _channels_
channels: builder `channels` argument
Returns valid packges that have been defined within an overlay so they
can be shared via _self.packages_ with the world. This is especially useful
over sharing one's art via _self.overlays_ in case you have a binary cache
running from which third parties could benefit.
Steps:
1. merge all channels into one nixpkgs attribute set
2. collect all overlays' packages' keys into one flat list
3. pick out each package from the nixpkgs set into one packages set
$. flatten package set and filter out disallowed packages - by flake check requirements
example input and output:
```
overlays = {
"unstable/firefox" = prev: final: {
firefox = prev.override { privacySupport = true; };
};
}
self.packages = {
firefox = *firefox derivation with privacySupport*;
}
```
**/
let
inherit (flake-utils-plus.lib) flattenTree filterPackages;
inherit (builtins) foldl' attrNames mapAttrs listToAttrs
attrValues concatStringSep concatMap any head;
nameValuePair = name: value: { inherit name value; };
flattenedPackages =
# merge all channels into one package set
foldl' (a: b: a // b) { } (attrValues channels);
# flatten all overlays' packages' keys into a single list
flattenedOverlaysNames =
let
allOverlays = attrValues overlays;
overlayNamesList = overlay:
attrNames (overlay null null);
in
concatMap overlayNamesList allOverlays;
# create list of single-attribute sets that contain each package
exportPackagesList = map
(name:
let
item = flattenedPackages.${name};
exportItem = { ${name} = item; };
in
if item ? type && item.type == "derivation" then
# if its a package export it
exportItem
else if item ? __dontExport && !item.__dontExport then
# if its a package sub-system, __dontExport has to be set to false to export
exportItem
else
{ }
)
flattenedOverlaysNames;
# fold list into one attribute set
exportPackages = foldl' (lhs: rhs: lhs // rhs) { } exportPackagesList;
inherit ((head (attrValues channels))) system;
in
# flatten nested sets with "/" delimiter then drop disallowed packages
filterPackages system (flattenTree exportPackages);
in
exportPackages;
in
exportPackagesBuilder