-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathdefault.nix
204 lines (187 loc) · 6.06 KB
/
default.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
{
core-inputs,
user-inputs,
snowfall-lib,
snowfall-config,
}: let
inherit (core-inputs.nixpkgs.lib) assertMsg foldl filterAttrs const;
in rec {
flake = rec {
## Remove the `self` attribute from an attribute set.
## Example Usage:
## ```nix
## without-self { self = {}; x = true; }
## ```
## Result:
## ```nix
## { x = true; }
## ```
#@ Attrs -> Attrs
without-self = flake-inputs: builtins.removeAttrs flake-inputs ["self"];
## Remove the `src` attribute from an attribute set.
## Example Usage:
## ```nix
## without-src { src = ./.; x = true; }
## ```
## Result:
## ```nix
## { x = true; }
## ```
#@ Attrs -> Attrs
without-src = flake-inputs: builtins.removeAttrs flake-inputs ["src"];
## Remove the `src` and `self` attributes from an attribute set.
## Example Usage:
## ```nix
## without-snowfall-inputs { self = {}; src = ./.; x = true; }
## ```
## Result:
## ```nix
## { x = true; }
## ```
#@ Attrs -> Attrs
without-snowfall-inputs = snowfall-lib.fp.compose without-self without-src;
## Remove Snowfall-specific attributes so the rest can be safely passed to flake-utils-plus.
## Example Usage:
## ```nix
## without-snowfall-options { src = ./.; x = true; }
## ```
## Result:
## ```nix
## { x = true; }
## ```
#@ Attrs -> Attrs
without-snowfall-options = flake-options:
builtins.removeAttrs
flake-options
[
"systems"
"modules"
"overlays"
"packages"
"outputs-builder"
"outputsBuilder"
"packagesPrefix"
"hosts"
"homes"
"channels-config"
"templates"
"checks"
"alias"
"snowfall"
];
## Transform an attribute set of inputs into an attribute set where the values are the inputs' `lib` attribute. Entries without a `lib` attribute are removed.
## Example Usage:
## ```nix
## get-lib { x = nixpkgs; y = {}; }
## ```
## Result:
## ```nix
## { x = nixpkgs.lib; }
## ```
#@ Attrs -> Attrs
get-libs = attrs: let
# @PERF(jakehamilton): Replace filter+map with a fold.
attrs-with-libs =
filterAttrs
(name: value: builtins.isAttrs (value.lib or null))
attrs;
libs =
builtins.mapAttrs (name: input: input.lib) attrs-with-libs;
in
libs;
};
mkFlake = full-flake-options: let
namespace = snowfall-config.namespace or "internal";
custom-flake-options = flake.without-snowfall-options full-flake-options;
alias = full-flake-options.alias or {};
homes = snowfall-lib.home.create-homes (full-flake-options.homes or {});
systems = snowfall-lib.system.create-systems {
systems = full-flake-options.systems or {};
homes = full-flake-options.homes or {};
};
hosts = snowfall-lib.attrs.merge-shallow [(full-flake-options.systems.hosts or {}) systems homes];
templates = snowfall-lib.template.create-templates {
overrides = full-flake-options.templates or {};
alias = alias.templates or {};
};
nixos-modules = snowfall-lib.module.create-modules {
src = snowfall-lib.fs.get-snowfall-file "modules/nixos";
overrides = full-flake-options.modules.nixos or {};
alias = alias.modules.nixos or {};
};
darwin-modules = snowfall-lib.module.create-modules {
src = snowfall-lib.fs.get-snowfall-file "modules/darwin";
overrides = full-flake-options.modules.darwin or {};
alias = alias.modules.darwin or {};
};
home-modules = snowfall-lib.module.create-modules {
src = snowfall-lib.fs.get-snowfall-file "modules/home";
overrides = full-flake-options.modules.home or {};
alias = alias.modules.home or {};
};
overlays = snowfall-lib.overlay.create-overlays {
inherit namespace;
extra-overlays = full-flake-options.extra-exported-overlays or {};
};
outputs-builder = channels: let
user-outputs-builder =
full-flake-options.outputs-builder
or full-flake-options.outputsBuilder
or (const {});
user-outputs = user-outputs-builder channels;
packages = snowfall-lib.package.create-packages {
inherit channels namespace;
overrides = (full-flake-options.packages or {}) // (user-outputs.packages or {});
alias = alias.packages or {};
};
shells = snowfall-lib.shell.create-shells {
inherit channels;
overrides = (full-flake-options.shells or {}) // (user-outputs.devShells or {});
alias = alias.shells or {};
};
checks = snowfall-lib.check.create-checks {
inherit channels;
overrides = (full-flake-options.checks or {}) // (user-outputs.checks or {});
alias = alias.checks or {};
};
formatter = snowfall-lib.formatter.create-formatter {
inherit channels;
};
outputs = {
inherit packages checks formatter;
devShells = shells;
};
in
snowfall-lib.attrs.merge-deep [user-outputs outputs];
flake-options =
custom-flake-options
// {
inherit hosts templates;
inherit (user-inputs) self;
lib = snowfall-lib.internal.user-lib;
inputs = snowfall-lib.flake.without-src user-inputs;
nixosModules = nixos-modules;
darwinModules = darwin-modules;
homeModules = home-modules;
channelsConfig = full-flake-options.channels-config or {};
channels.nixpkgs.overlaysBuilder = snowfall-lib.overlay.create-overlays-builder {
inherit namespace;
extra-overlays = full-flake-options.overlays or [];
};
outputsBuilder = outputs-builder;
snowfall = {
config = snowfall-config;
raw-config = full-flake-options.snowfall or {};
user-lib = snowfall-lib.internal.user-lib;
};
};
flake-utils-plus-outputs =
core-inputs.flake-utils-plus.lib.mkFlake flake-options;
flake-outputs =
flake-utils-plus-outputs
// {
inherit overlays;
};
in
flake-outputs;
}