-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
266 lines (238 loc) · 6.91 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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
{
description = "Yet another NixOS flake";
inputs = {
nixpkgs-unstable.url = "github:merrkry/nixpkgs/nixos-unstable";
home-manager-unstable = {
url = "github:nix-community/home-manager/master";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-24.11";
home-manager-stable = {
url = "github:nix-community/home-manager/release-24.11";
inputs.nixpkgs.follows = "nixpkgs-stable";
};
# general purpose
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
disko = {
url = "github:nix-community/disko/latest";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
deploy-rs = {
url = "github:serokell/deploy-rs";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
# desktop-oriented, unstable branch
niri-flake = {
url = "github:sodiboo/niri-flake";
inputs.nixpkgs.follows = "nixpkgs-unstable";
inputs.nixpkgs-stable.follows = "nixpkgs-stable";
};
stylix = {
url = "github:danth/stylix/master";
inputs.nixpkgs.follows = "nixpkgs-unstable";
inputs.home-manager.follows = "home-manager-unstable";
};
nur = {
url = "github:nix-community/NUR";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
lanzaboote = {
url = "github:nix-community/lanzaboote/v0.4.2";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
xremap = {
url = "github:xremap/nix-flake";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
# server-oriented, stable branch
nixos-mailserver = {
url = "gitlab:simple-nixos-mailserver/nixos-mailserver/nixos-24.11";
inputs.nixpkgs.follows = "nixpkgs-stable";
inputs.nixpkgs-24_11.follows = "nixpkgs-stable";
};
# secrets
secrets = {
url = "github:merrkry/declaratia-secrets";
flake = false;
};
};
outputs =
{ self, ... }@inputs:
let
inherit (self) outputs;
lib = inputs.nixpkgs-unstable.lib;
systems = [
"aarch64-linux"
"x86_64-linux"
];
forAllSystems = inputs.nixpkgs-unstable.lib.genAttrs systems;
machines = {
"akahi" = {
channel = "unstable";
hostPlatform = "x86_64-linux";
stateVersion = "24.05";
};
"cryolite" = {
channel = "unstable";
hostPlatform = "x86_64-linux";
stateVersion = "24.11";
};
"hoshinouta" = {
channel = "stable";
hostPlatform = "x86_64-linux";
stateVersion = "24.05";
};
"karanohako" = {
channel = "stable";
hostPlatform = "x86_64-linux";
stateVersion = "24.05";
};
"perimadeia" = {
channel = "stable";
hostPlatform = "x86_64-linux";
stateVersion = "24.11";
};
"sapphire" = {
channel = "stable";
hostPlatform = "x86_64-linux";
stateVersion = "24.11";
remoteBuild = false;
};
};
in
{
overlays = import ./overlays { inherit inputs; };
nixosConfigurations = builtins.mapAttrs (
hostName:
{
channel,
hostPlatform,
stateVersion,
mainUser ? "merrkry",
...
}:
let
channelInput = inputs."nixpkgs-${channel}";
hmInput = inputs."home-manager-${channel}";
in
channelInput.lib.nixosSystem {
specialArgs =
let
lib = channelInput.lib.extend self.overlays.extraLibs;
# calls flake inputs directly, otherwise causes infinite recursion
inputs = self.inputs // {
nixpkgs = channelInput;
home-manager = hmInput;
};
user = mainUser;
in
{
inherit
inputs
lib
outputs
user
;
};
modules = [
./hosts/${hostName}
{
networking = { inherit hostName; };
nixpkgs = {
overlays = [
(
if channelInput == inputs.nixpkgs-unstable then
self.overlays.stablePackages
else
self.overlays.unstablePackages
)
];
inherit hostPlatform;
};
system = { inherit stateVersion; };
}
hmInput.nixosModules.home-manager
./profiles
];
}
) machines;
devShells = forAllSystems (
system:
let
pkgs = import inputs.nixpkgs-unstable { inherit system; };
in
{
default =
with pkgs;
mkShell {
nativeBuildInputs = [
deploy-rs
nixd
nixfmt-rfc-style
nix-tree
nh
nvfetcher
];
};
}
);
deploy =
# Overlay to use deploy-rs from nixpkgs for deployment
# Seems too heavy to import nixpkgs twice. Looking for a fix.
let
deployPkgs =
system:
(import inputs.nixpkgs-unstable {
inherit system;
overlays = [
inputs.deploy-rs.overlays.default
(final: prev: {
deploy-rs =
let
pkgs = import inputs.nixpkgs-unstable { inherit system; };
in
{
inherit (pkgs) deploy-rs; # use prev instead of pkgs will cause error
lib = prev.deploy-rs.lib;
};
})
];
});
in
{
sshUser = "remote-deployer";
nodes = builtins.mapAttrs (
hostName:
{
hostPlatform,
remoteBuild ? true,
...
}:
{
hostname = hostName;
profiles.system = {
user = "root";
path = (deployPkgs hostPlatform).deploy-rs.lib.activate.nixos self.nixosConfigurations.${hostName};
};
inherit remoteBuild;
}
) machines;
};
checks = builtins.mapAttrs (
system: deployLib: deployLib.deployChecks self.deploy
) inputs.deploy-rs.lib;
build = lib.pipe machines [
(lib.mapAttrsToList (
hostName: properties: {
${properties.hostPlatform}.${hostName} =
self.nixosConfigurations.${hostName}.config.system.build.toplevel;
}
))
(lib.foldAttrs (lib.recursiveUpdate) { })
];
};
}