-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
141 lines (121 loc) · 4.57 KB
/
flake.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
{
inputs = {
flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/0.1.1.tar.gz";
systems.url = "github:nix-systems/default";
};
outputs = { self, flake-schemas, systems }:
let
# lib
inherit (builtins) attrNames elemAt filter foldl' head isAttrs
length mapAttrs stringLength substring zipAttrsWith;
update =
a: b: if isAttrs b then recursiveUpdate a b else b;
# nixpkgs clones
hasSuffix = suffix: content:
let
lenContent = stringLength content;
lenSuffix = stringLength suffix;
in
lenContent >= lenSuffix
&& substring (lenContent - lenSuffix) lenContent content == suffix;
recursiveUpdateUntil = pred: lhs: rhs:
let
f = attrPath:
zipAttrsWith (n: values:
let here = attrPath ++ [ n ]; in
if length values == 1
|| pred here (elemAt values 1) (head values) then
head values
else
f here values
);
in
f [ ] [ rhs lhs ];
recursiveUpdate = lhs: rhs:
recursiveUpdateUntil (path: lhs: rhs: !(isAttrs lhs && isAttrs rhs)) lhs rhs;
# main functions
support = targets: nixpkgs: applier:
let
eachSystem = system:
let
nestSystem = _: value: { ${system} = value; };
systemOutputs = applier {
inherit system;
pkgs = nixpkgs.legacyPackages.${system};
};
in
mapAttrs nestSystem systemOutputs;
in
zipAttrsWith
(_: values: foldl' update { } values)
(map eachSystem targets);
support' = targets: nixpkgs: applier: accu:
update accu (support targets nixpkgs (applier accu));
withUniversal = output:
applier: accu: accu // ({
"${output}" =
let
new = applier accu;
in
if isAttrs new then
update (accu.${output} or { }) new
else new;
});
withNestedUniversal = output: name:
applier: accu: accu // ({ "${output}" = (accu.${output} or { }) // { "${name}" = applier accu; }; });
findSystems = accu:
attrNames (accu.legacyPackages or accu.packages or accu.apps or accu.formatter or accu.devShells);
withNestedSystem = name: nixpkgs: applier: accu:
support (findSystems accu) accu nixpkgs
({ pkgs, system }@combo: {
"${name}" = update accu.${name}.${system} (applier accu combo);
});
withSchemas = withUniversal "schemas";
# system list
importedSystems = import systems;
linuxes = filter (hasSuffix "-linux") importedSystems;
darwins = filter (hasSuffix "-darwin") importedSystems;
in
withSchemas (import ./schemas.nix flake-schemas) {
# Constructors
allSystems = support importedSystems;
systems = support;
system = target: support [ target ];
allLinux = support linuxes;
allDarwin = support darwins;
# With per-system
withSystems = support';
withDarwin = support' darwins;
withLinux = support' linuxes;
withAllSystems = support' importedSystems;
withSystem = target: support' [ target ];
withAarch64Linux = support' [ "aarch64-linux" ];
withAMD64Linux = support' [ "x86_64-linux" ];
withAarch64Darwin = support' [ "aarch64-darwin" ];
withAMD64Darwin = support' [ "x86_64-darwin" ];
# With per-system products
inherit withNestedSystem;
withApps = withNestedSystem "apps";
withDevShells = withNestedSystem "devShells";
withLegacyPackages = withNestedSystem "legacyPackages";
withPackages = withNestedSystem "packages";
withFormatter = nixpkgs: applier: accu:
support (findSystems accu) accu nixpkgs
(combo: { formatter = applier combo; });
# With universals
withUniversals = applier: accu: accu // (applier accu);
inherit withUniversal;
withHomeManagerModules = withUniversal "homeManagerModules";
withNixOSModules = withUniversal "nixosModules";
withOverlays = withUniversal "overlays";
inherit withSchemas;
# With universals products
inherit withNestedUniversal;
withHomeManagerModule = withNestedUniversal "homeManagerModules";
withNixOSModule = withNestedUniversal "nixosModules";
withOverlay = withNestedUniversal "overlays";
withSchema = withNestedUniversal "schemas";
# Helpers
map = applier: accu: applier accu;
};
}