1
- { deploy-rs
1
+ { darwin
2
+ , deploy-rs
2
3
, home-manager
3
4
, flake-utils-plus
4
5
, nixpkgs
34
35
# NixOS specific modules.
35
36
, extraNixosModules ? [ ]
36
37
38
+ # nix-darwin specific modules.
39
+ , extraNixDarwinModules ? [ ]
40
+
37
41
# The global extra arguments are included in both NixOS and home-manager.
38
42
, globalSpecialArgs ? { }
39
43
43
47
# NixOS specific extra arguments.
44
48
, nixosSpecialArgs ? { }
45
49
50
+ # nix-darwin specific extra arguments.
51
+ , nixDarwinSpecialArgs ? { }
52
+
46
53
# Shared overlays between channels, gets applied to all `channels.<name>.input`
47
54
, sharedOverlays ? [ ]
48
55
@@ -95,43 +102,125 @@ let
95
102
"extraGlobalModules"
96
103
"extraHomeManagerModules"
97
104
"extraNixosModules"
105
+ "extraNixDarwinModules"
98
106
"globalSpecialArgs"
99
107
"hmSpecialArgs"
100
108
"nixosSpecialArgs"
109
+ "nixDarwinSpecialArgs"
101
110
"outputsBuilder"
102
111
"sharedOverlays"
103
112
] ;
104
113
105
114
# generate each host by injecting special arguments and the given host
106
115
# without certain soxin-only attributes.
107
116
hosts' =
108
- mapAttrs
109
- ( hostname : host : ( recursiveUpdate
110
- {
111
- specialArgs = {
112
- inherit soxin soxincfg home-manager ;
113
-
114
- # the mode allows us to tell at what level we are within the modules.
115
- mode = "NixOS" ;
116
- }
117
- # include the global special arguments.
118
- // globalSpecialArgs
119
- # include the NixOS special arguments.
120
- // nixosSpecialArgs ;
121
- }
122
-
123
- # pass along the hosts minus the deploy key that's specific to soxin.
124
- ( removeAttrs host [ "deploy" ] )
125
- ) )
126
- hosts ;
117
+ let
118
+ darwinHosts =
119
+ let
120
+ darwinOnlyHosts = filterAttrs ( n : host : host . mode == "nix-darwin" ) hosts ;
121
+
122
+ # Build host with darwinSystem.
123
+ builder = args : darwin . lib . darwinSystem args ;
124
+
125
+ # Setup the output
126
+ output = "darwinConfigurations" ;
127
+ in
128
+ mapAttrs
129
+ ( _ : host :
130
+ # setup the default attributes, users can override it by passing them through their host definition.
131
+ { inherit builder output ; }
132
+ //
133
+ ( recursiveUpdate
134
+ # pass along the hosts minus few keys that are implementation detail to soxin.
135
+ ( removeAttrs host [ "deploy" "mode" "modules" ] )
136
+
137
+ {
138
+ modules = [ ]
139
+ # include modules for the host
140
+ ++ ( host . modules or [ ] )
141
+ # include the NixOS modules
142
+ ++ extraNixDarwinModules
143
+ # include home-manager modules
144
+ ++ ( singleton home-manager . darwinModules . home-manager )
145
+ ;
146
+ specialArgs =
147
+ {
148
+ inherit
149
+ home-manager
150
+ soxin
151
+ soxincfg
152
+ ;
153
+
154
+ inherit ( host )
155
+ mode
156
+ ;
157
+ }
158
+ # include the specialArgs that were passed in.
159
+ // ( host . specialArgs or { } )
160
+ # include the global special arguments.
161
+ // globalSpecialArgs
162
+ # include the NixDarwin special arguments.
163
+ // nixDarwinSpecialArgs
164
+ ;
165
+ }
166
+ ) )
167
+ darwinOnlyHosts ;
168
+
169
+ nixosHosts =
170
+ let
171
+ nixosOnlyHosts = filterAttrs ( n : host : host . mode == "NixOS" ) hosts ;
172
+ in
173
+ mapAttrs
174
+ ( _ : host : ( recursiveUpdate
175
+ # pass along the hosts minus few keys that are implementation detail to soxin.
176
+ ( removeAttrs host [ "deploy" "mode" ] )
177
+
178
+ {
179
+ modules = [ ]
180
+ # include modules for the host
181
+ ++ ( host . modules or [ ] )
182
+ # include the NixOS modules
183
+ ++ extraNixosModules
184
+ # include sops
185
+ ++ ( optionals withSops ( singleton sops-nix . nixosModules . sops ) )
186
+ # include home-manager modules
187
+ ++ ( singleton home-manager . nixosModules . home-manager )
188
+ ;
189
+
190
+ specialArgs =
191
+ {
192
+ inherit
193
+ home-manager
194
+ soxin
195
+ soxincfg
196
+ ;
197
+
198
+ inherit ( host )
199
+ mode
200
+ ;
201
+ }
202
+ # include the specialArgs that were passed in.
203
+ // ( host . specialArgs or { } )
204
+ # include the global special arguments.
205
+ // globalSpecialArgs
206
+ # include the NixOS special arguments.
207
+ // nixosSpecialArgs
208
+ ;
209
+ }
210
+ ) )
211
+ nixosOnlyHosts ;
212
+
213
+ # TODO: add support for home-manager modes
214
+ in
215
+ darwinHosts // nixosHosts ;
127
216
128
217
# Generate the deployment nodes.
129
218
deploy . nodes =
130
219
let
131
220
# filter out hosts without a deploy attribute.
132
221
deploy-hosts = filterAttrs ( n : v : ( v . deploy or { } ) != { } ) hosts ;
133
222
in
134
- mapAttrs ( hostname : host : host . deploy ) deploy-hosts ;
223
+ mapAttrs ( _ : host : host . deploy ) deploy-hosts ;
135
224
136
225
soxinSystemFlake = {
137
226
# inherit the required fields as-is
@@ -236,22 +325,17 @@ let
236
325
modules =
237
326
# include the modules that are passed in
238
327
( hostDefaults . modules or [ ] )
239
- # include sops
240
- ++ ( optionals withSops ( singleton sops-nix . nixosModules . sops ) )
241
328
# include the global modules
242
329
++ extraGlobalModules
243
- # include the NixOS modules
244
- ++ extraNixosModules
245
330
# include Soxin modules
246
331
++ ( singleton soxin . nixosModule )
247
- # include home-manager modules
248
- ++ ( singleton home-manager . nixosModules . home-manager )
249
332
# configure fup to expose NIX_PATH and Nix registry from inputs.
250
333
++ ( singleton { nix = { inherit generateNixPathFromInputs generateRegistryFromInputs linkInputs ; } ; } )
251
334
# configure home-manager
252
335
++ ( singleton {
253
- # tell home-manager to use the global (as in NixOS system-level) pkgs and
254
- # install all user packages through the users.users.<name>.packages.
336
+ # tell home-manager to use the global (as in NixOS/Nix-Darwin
337
+ # system-level) pkgs and install all user packages through the
338
+ # users.users.<name>.packages.
255
339
home-manager . useGlobalPkgs = true ;
256
340
home-manager . useUserPackages = true ;
257
341
@@ -264,15 +348,17 @@ let
264
348
# include the global special arguments.
265
349
// globalSpecialArgs
266
350
# include the home-manager special arguments.
267
- // hmSpecialArgs ;
351
+ // hmSpecialArgs
352
+ ;
268
353
269
354
home-manager . sharedModules =
270
355
# include the global modules
271
356
extraGlobalModules
272
357
# include the home-manager modules
273
358
++ extraHomeManagerModules
274
359
# include Soxin module
275
- ++ ( singleton soxin . nixosModule ) ;
360
+ ++ ( singleton soxin . nixosModule )
361
+ ;
276
362
} ) ;
277
363
} ;
278
364
}
@@ -292,7 +378,7 @@ flake-utils-plus.lib.mkFlake (recursiveUpdate soxinSystemFlake otherArguments)
292
378
# TODO: Let flake-utils-plus.lib.mkFlake handle the home-managers by using the host's builder function
293
379
// {
294
380
homeConfigurations = ( mapAttrs
295
- ( hostname : host : soxin . lib . homeManagerConfiguration ( host // {
381
+ ( _ : host : soxin . lib . homeManagerConfiguration ( host // {
296
382
inherit inputs ;
297
383
hmModules =
298
384
# include the global modules
0 commit comments