-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathflake.nix
More file actions
342 lines (318 loc) · 11.4 KB
/
flake.nix
File metadata and controls
342 lines (318 loc) · 11.4 KB
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
{
description = "nix system configurations";
nixConfig = {
extra-substituters = [
# "https://cache.kclj.io/kclejeune"
"https://kclejeune.cachix.org"
"https://install.determinate.systems"
];
extra-trusted-public-keys = [
# "kclejeune:u0sa4anVXC4bKlzEsijdSlLyWVaEkApu6KWyDbbJMkk="
"kclejeune.cachix.org-1:fOCrECygdFZKbMxHClhiTS6oowOkJ/I/dh9q9b1I4ko="
"cache.flakehub.com-3:hJuILl5sVK4iKm86JzgdXW12Y2Hwd5G07qKtHTOcDCM="
];
};
inputs = {
determinate.url = "https://flakehub.com/f/DeterminateSystems/determinate/3";
stable.url = "github:nixos/nixpkgs/nixos-25.11";
unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nixos-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
nixos-hardware.url = "github:nixos/nixos-hardware";
nixpkgs.follows = "unstable";
# NOTE: Don't override ANY inputs for attic - it requires specific versions
# with compatible C++ bindings. nixpkgs-unstable has nix 2.31+ which has
# breaking API changes (nix::openStore, nix::settings removed).
attic.url = "github:kclejeune/attic?ref=kcl/worker-impl";
nh.url = "github:nix-community/nh";
nh.inputs.nixpkgs.follows = "unstable";
flake-compat.url = "github:nix-community/flake-compat";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
git-hooks.url = "github:cachix/git-hooks.nix";
git-hooks.inputs.nixpkgs.follows = "nixpkgs";
git-hooks.inputs.flake-compat.follows = "flake-compat";
nixGL.url = "github:nix-community/nixGL";
nixGL.inputs.nixpkgs.follows = "nixpkgs";
darwin.url = "github:lnl7/nix-darwin";
darwin.inputs.nixpkgs.follows = "nixpkgs";
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
nix-index-database.url = "github:Mic92/nix-index-database";
nix-index-database.inputs.nixpkgs.follows = "nixpkgs";
sops-nix.url = "github:Mic92/sops-nix";
sops-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
self,
darwin,
home-manager,
determinate,
flake-parts,
...
}@inputs:
let
inherit (inputs.nixpkgs) lib;
defaultSystems = lib.intersectLists (lib.platforms.linux ++ lib.platforms.darwin) (
lib.platforms.x86_64 ++ lib.platforms.aarch64
);
darwinSystems = lib.intersectLists defaultSystems lib.platforms.darwin;
homePrefix = system: if (lib.elem system darwinSystems) then "/Users" else "/home";
# generate a base darwin configuration with the
# specified hostname, overlays, and any extraModules applied
mkDarwinConfig =
{
system ? "aarch64-darwin",
nixpkgs ? inputs.nixpkgs,
baseModules ? [
determinate.darwinModules.default
home-manager.darwinModules.home-manager
./modules/darwin
],
extraModules ? [ ],
}:
darwin.lib.darwinSystem {
inherit system;
modules = baseModules ++ extraModules;
specialArgs = { inherit self inputs nixpkgs; };
};
# generate a base nixos configuration with the
# specified overlays, hardware modules, and any extraModules applied
mkNixosConfig =
{
system ? "x86_64-linux",
nixpkgs ? inputs.nixos-unstable,
hardwareModules,
baseModules ? [
determinate.nixosModules.default
home-manager.nixosModules.home-manager
./modules/nixos
],
extraModules ? [ ],
}:
nixpkgs.lib.nixosSystem {
inherit system;
modules = baseModules ++ hardwareModules ++ extraModules;
specialArgs = { inherit self inputs nixpkgs; };
};
# generate a home-manager configuration usable on any unix system
# with overlays and any extraModules applied
mkHomeConfig =
{
username,
system ? "x86_64-linux",
nixpkgs ? inputs.nixpkgs,
baseModules ? [
./modules/home-manager
(
{ pkgs, ... }:
{
nix.package = pkgs.nix;
home = {
inherit username;
homeDirectory = "${homePrefix system}/${username}";
};
}
)
],
extraModules ? [ ],
}:
inputs.home-manager.lib.homeManagerConfiguration {
pkgs = import nixpkgs {
inherit system;
config = import ./modules/config.nix;
overlays = [ self.overlays.default ];
};
extraSpecialArgs = { inherit self inputs nixpkgs; };
modules = baseModules ++ extraModules;
};
in
flake-parts.lib.mkFlake { inherit inputs; } (
{
config,
withSystem,
moduleWithSystem,
...
}:
{
debug = true;
imports = [
inputs.home-manager.flakeModules.home-manager
inputs.treefmt-nix.flakeModule
inputs.flake-parts.flakeModules.easyOverlay
inputs.git-hooks.flakeModule
];
systems = lib.intersectLists (lib.platforms.linux ++ lib.platforms.darwin) (
lib.platforms.x86_64 ++ lib.platforms.aarch64
);
flake = {
darwinConfigurations =
# generate darwin configs for each supported platform
lib.mergeAttrsList (
# arch-independent configs that can operate on both x86_64-darwin and aarch64-darwin
(lib.map (system: {
"kclejeune@${system}" = mkDarwinConfig {
inherit system;
extraModules = [
./profiles/personal
./modules/darwin/apps.nix
];
};
"klejeune@${system}" = mkDarwinConfig {
inherit system;
extraModules = [
./profiles/work
];
};
}) darwinSystems)
# and "custom" ones that aren't universal
++ [ ]
);
nixosConfigurations =
# generate nixos configs, if these are ever applicable
lib.mergeAttrsList [
{
"kclejeune@x86_64-linux" = mkNixosConfig {
system = "x86_64-linux";
hardwareModules = [
./modules/hardware/phil.nix
inputs.nixos-hardware.nixosModules.lenovo-thinkpad-t460s
];
extraModules = [
./modules/nixos/desktop.nix
./profiles/personal
];
};
gateway = mkNixosConfig {
system = "x86_64-linux";
hardwareModules = [
./modules/nixos/hetzner.nix
];
extraModules = [
inputs.sops-nix.nixosModules.sops
./modules/nixos/gateway.nix
./profiles/personal
];
};
}
];
homeConfigurations =
# generate home-manager configs for each supported platform
lib.mergeAttrsList (
(lib.map (system: {
"kclejeune@${system}" = mkHomeConfig {
inherit system;
username = "kclejeune";
extraModules = [ ./profiles/personal/home-manager ];
};
"klejeune@${system}" = mkHomeConfig {
inherit system;
username = "klejeune";
extraModules = [
./profiles/work/home-manager
];
};
}) defaultSystems)
# and "custom" ones that aren't universal
++ [ ]
);
};
perSystem =
{
config,
pkgs,
system,
lib,
...
}:
let
filterSystem = attrs: lib.filterAttrs (name: drv: drv.pkgs.system == system) attrs;
in
{
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
self.overlays.default
];
};
overlayAttrs = {
inherit (inputs.attic.packages.${system}) attic attic-client attic-server;
cb = pkgs.callPackage ./pkgs/cb/package.nix { };
fnox = pkgs.callPackage ./pkgs/fnox/package.nix { };
weave = pkgs.callPackage ./pkgs/weave/package.nix { };
stable = inputs.stable.legacyPackages.${system};
determinate-nixd = inputs.determinate.packages.${system}.default;
nix = inputs.determinate.inputs.nix.packages.${system}.default;
nh = inputs.nh.packages.${system}.default;
};
checks = lib.mergeAttrsList [
# home-manager checks; add _home suffix to original config to avoid nixos coflict
(lib.mapAttrs' (name: cfg: (lib.nameValuePair "${name}_home" cfg.activationPackage)) (
filterSystem self.homeConfigurations
))
# nixOS + nix-darwin checks
(lib.mapAttrs (_: cfg: cfg.config.system.build.toplevel) (
filterSystem (self.darwinConfigurations // self.nixosConfigurations)
))
];
legacyPackages = pkgs;
treefmt = {
programs = {
deadnix = {
enable = true;
no-lambda-arg = true;
no-lambda-pattern-names = true;
};
nixfmt.enable = true;
oxfmt.enable = true;
ruff-check.enable = true;
ruff-format.enable = true;
shellcheck.enable = true;
shfmt.enable = true;
stylua.enable = true;
};
settings.excludes = [
".envrc"
".env"
".vscode/*.json"
"**/Spoons/**/*.json"
"**/zed/**/*.json"
];
settings.on-unmatched = "info";
settings.formatter.ruff-check.options = [
# sort imports
"--extend-select"
"I"
];
};
pre-commit = {
settings.package = pkgs.prek;
settings.hooks.treefmt = {
enable = true;
pass_filenames = false;
settings.no-cache = false;
};
};
devShells = {
default = pkgs.mkShell {
packages =
(builtins.attrValues {
inherit (pkgs)
bashInteractive
fd
ripgrep
uv
nh
;
})
++ config.pre-commit.settings.enabledPackages
++ (lib.attrValues config.treefmt.build.programs)
++ (lib.mapAttrsToList (name: value: value) config.packages);
shellHook = config.pre-commit.installationScript;
};
};
};
}
);
}