-
Notifications
You must be signed in to change notification settings - Fork 43
/
flake.nix
340 lines (314 loc) · 9.5 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
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
{
description = "nix system configurations";
nixConfig = {
substituters = [
"https://cache.nixos.org"
"https://kclejeune.cachix.org"
];
trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"kclejeune.cachix.org-1:fOCrECygdFZKbMxHClhiTS6oowOkJ/I/dh9q9b1I4ko="
];
};
inputs = {
# package repos
stable.url = "github:nixos/nixpkgs/nixos-24.05";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nixos-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
devenv = {
url = "github:cachix/devenv/v1.0.7";
inputs.nixpkgs.follows = "nixpkgs";
};
# system management
nixos-hardware.url = "github:nixos/nixos-hardware";
darwin = {
url = "github:lnl7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-index-database = {
url = "github:Mic92/nix-index-database";
inputs.nixpkgs.follows = "nixpkgs";
};
# shell stuff
flake-utils.url = "github:numtide/flake-utils";
treefmt-nix.url = "github:numtide/treefmt-nix";
};
outputs = {
self,
darwin,
devenv,
flake-utils,
home-manager,
...
} @ inputs: let
inherit (flake-utils.lib) eachSystemMap;
isDarwin = system: (builtins.elem system inputs.nixpkgs.lib.platforms.darwin);
homePrefix = system:
if isDarwin system
then "/Users"
else "/home";
defaultSystems = [
# "aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
"x86_64-linux"
];
# generate a base darwin configuration with the
# specified hostname, overlays, and any extraModules applied
mkDarwinConfig = {
system ? "aarch64-darwin",
nixpkgs ? inputs.nixpkgs,
baseModules ? [
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 ? [
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
{
home = {
inherit username;
homeDirectory = "${homePrefix system}/${username}";
sessionVariables = {
NIX_PATH = "nixpkgs=${nixpkgs}";
};
};
}
],
extraModules ? [],
}:
inputs.home-manager.lib.homeManagerConfiguration rec {
pkgs = import nixpkgs {
inherit system;
overlays = builtins.attrValues self.overlays;
};
extraSpecialArgs = {inherit self inputs nixpkgs;};
modules = baseModules ++ extraModules;
};
mkChecks = {
arch,
os,
username ? "kclejeune",
}: {
"${arch}-${os}" = {
"${username}_${os}" =
(
if os == "darwin"
then self.darwinConfigurations
else self.nixosConfigurations
)
."${username}@${arch}-${os}"
.config
.system
.build
.toplevel;
"${username}_home" =
self.homeConfigurations."${username}@${arch}-${os}".activationPackage;
devShell = self.devShells."${arch}-${os}".default;
};
};
in {
checks =
{}
// (mkChecks {
arch = "aarch64";
os = "darwin";
})
// (mkChecks {
arch = "x86_64";
os = "darwin";
})
// (mkChecks {
arch = "aarch64";
os = "linux";
})
// (mkChecks {
arch = "x86_64";
os = "linux";
});
darwinConfigurations = {
"kclejeune@aarch64-darwin" = mkDarwinConfig {
system = "aarch64-darwin";
extraModules = [./profiles/personal.nix ./modules/darwin/apps.nix];
};
"kclejeune@x86_64-darwin" = mkDarwinConfig {
system = "x86_64-darwin";
extraModules = [./profiles/personal.nix ./modules/darwin/apps.nix];
};
"lejeukc1@aarch64-darwin" = mkDarwinConfig {
system = "aarch64-darwin";
extraModules = [./profiles/work.nix];
};
"lejeukc1@x86_64-darwin" = mkDarwinConfig {
system = "aarch64-darwin";
extraModules = [./profiles/work.nix];
};
};
nixosConfigurations = {
"kclejeune@x86_64-linux" = mkNixosConfig {
system = "x86_64-linux";
hardwareModules = [
./modules/hardware/phil.nix
inputs.nixos-hardware.nixosModules.lenovo-thinkpad-t460s
];
extraModules = [./profiles/personal.nix];
};
# "kclejeune@aarch64-linux" = mkNixosConfig {
# system = "aarch64-linux";
# hardwareModules = [./modules/hardware/phil.nix];
# extraModules = [./profiles/personal.nix];
# };
};
homeConfigurations = {
"kclejeune@x86_64-linux" = mkHomeConfig {
username = "kclejeune";
system = "x86_64-linux";
extraModules = [./profiles/home-manager/personal.nix];
};
# "kclejeune@aarch64-linux" = mkHomeConfig {
# username = "kclejeune";
# system = "aarch64-linux";
# extraModules = [./profiles/home-manager/personal.nix];
# };
"kclejeune@x86_64-darwin" = mkHomeConfig {
username = "kclejeune";
system = "x86_64-darwin";
extraModules = [./profiles/home-manager/personal.nix];
};
"kclejeune@aarch64-darwin" = mkHomeConfig {
username = "kclejeune";
system = "aarch64-darwin";
extraModules = [./profiles/home-manager/personal.nix];
};
"lejeukc1@x86_64-linux" = mkHomeConfig {
username = "lejeukc1";
system = "x86_64-linux";
extraModules = [./profiles/home-manager/work.nix];
};
};
devShells = eachSystemMap defaultSystems (system: let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = builtins.attrValues self.overlays;
};
in {
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
(import ./devenv.nix)
];
};
});
packages = eachSystemMap defaultSystems (system: let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = builtins.attrValues self.overlays;
};
in rec {
pyEnv =
pkgs.python3.withPackages
(ps: with ps; [black typer colorama shellingham]);
sysdo = pkgs.writeScriptBin "sysdo" ''
#! ${pyEnv}/bin/python3
${builtins.readFile ./bin/do.py}
'';
cb = pkgs.writeShellScriptBin "cb" ''
#! ${pkgs.lib.getExe pkgs.bash}
# universal clipboard, [email protected]
shopt -s expand_aliases
# ------------------------------------------------------------------------------
# os utils
case "$OSTYPE$(uname)" in
[lL]inux*) TUX_OS=1 ;;
[dD]arwin*) MAC_OS=1 ;;
[cC]ygwin) WIN_OS=1 ;;
*) echo "unknown os=\"$OSTYPE$(uname)\"" >&2 ;;
esac
is_tux() { [ ''${TUX_OS-0} -ne 0 ]; }
is_mac() { [ ''${MAC_OS-0} -ne 0 ]; }
is_win() { [ ''${WIN_OS-0} -ne 0 ]; }
# ------------------------------------------------------------------------------
# copy and paste
if is_mac; then
alias cbcopy=pbcopy
alias cbpaste=pbpaste
elif is_win; then
alias cbcopy=putclip
alias cbpaste=getclip
else
alias cbcopy='${pkgs.xclip} -sel c'
alias cbpaste='${pkgs.xclip} -sel c -o'
fi
# ------------------------------------------------------------------------------
cb() {
if [ ! -t 0 ] && [ $# -eq 0 ]; then
# no stdin and no call for --help, blow away the current clipboard and copy
cbcopy
else
cbpaste ''${@:+"$@"}
fi
}
# ------------------------------------------------------------------------------
if ! return 2>/dev/null; then
cb ''${@:+"$@"}
fi
'';
});
apps = eachSystemMap defaultSystems (system: rec {
sysdo = {
type = "app";
program = "${self.packages.${system}.sysdo}/bin/sysdo";
};
cb = {
type = "app";
program = "${self.packages.${system}.cb}/bin/cb";
};
default = sysdo;
});
overlays = {
channels = final: prev: {
# expose other channels via overlays
stable = import inputs.stable {system = prev.system;};
};
extraPackages = final: prev: {
sysdo = self.packages.${prev.system}.sysdo;
pyEnv = self.packages.${prev.system}.pyEnv;
cb = self.packages.${prev.system}.cb;
devenv = self.packages.${prev.system}.devenv;
};
};
};
}