-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
392 lines (377 loc) · 12.4 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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
{
description = "Development Machine's flake";
inputs = {
nixpkgs.url = "nixpkgs/nixos-24.05";
# For Darwin until https://github.com/NixOS/nixpkgs/pull/298070 fixed
nixpkgs2311.url = "nixpkgs/nixos-23.11";
# Unstable for select packages
nixpkgs-unstable.url = "nixpkgs/nixos-unstable";
# Home manager for dotfiles
home-manager = {
url = "github:nix-community/home-manager/release-24.05";
inputs.nixpkgs.follows = "nixpkgs";
};
# Wrapper manager for wrapping applications (careful updating)
wrapper-manager = {
url = "github:viperML/wrapper-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
# Darwin for macbook, follow 2311 till fixed
darwin = {
url = "github:lnl7/nix-darwin/master";
inputs.nixpkgs.follows = "nixpkgs2311";
};
home-manager2311 = {
url = "github:nix-community/home-manager/release-23.11";
inputs.nixpkgs.follows = "nixpkgs2311";
};
};
outputs =
{
self,
nixpkgs,
home-manager,
home-manager2311,
...
}@inputs:
let
# https://ayats.org/blog/no-flake-utils/
# Why you don't need flake-utils.
# https://xeiaso.net/blog/nix-flakes-1-2022-02-21/
supportedSystems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = forAllSystems (
system:
import nixpkgs {
inherit system;
config.allowUnfree = true;
overlays = [ my-custom-overlay ];
}
);
nixpkgsFor2311 = forAllSystems (
system:
import inputs.nixpkgs2311 {
inherit system;
config.allowUnfree = true;
overlays = [ my-custom-overlay ];
}
);
# Add unstable packages as an overlay so that they are available in the
# configs as `pkgs.unstable.<package-name>`
my-custom-overlay = final: prev: {
unstable = import inputs.nixpkgs-unstable {
system = "${prev.system}";
config.allowUnfree = true;
};
};
# Function for making python shells. That way I can switch between
# different versions of python as required. It can also be used between
# different subflakes.
pythonShell =
{
myPkgs,
pythonVersion,
additionalPkgs ? [ ],
}:
myPkgs.mkShell {
shellHook =
with myPkgs;
let
pythonldlibpath = lib.makeLibraryPath ([
stdenv.cc.cc
xmlsec
libxml2
zlib
rdkafka
]);
in
# Export the LD_LIBRARY_PATH so that pip can resolve shared libs when installing
''
export LD_LIBRARY_PATH="${pythonldlibpath}"
'';
nativeBuildInputs =
with myPkgs;
let
devpython = pythonVersion.withPackages (
packages: with packages; [
virtualenv
pip
setuptools
wheel
]
);
in
[
devpython
pkg-config
libtool
rdkafka
]
++ additionalPkgs;
};
in
{
# Lib is not part of the flake standard, it's a custom entry I add so that
# I can reuse functions in other flakes.
lib = {
inherit forAllSystems nixpkgsFor pythonShell;
};
# Default is used by CI for linting. All my linting stuff is already baked
# into my neovim package so I reuse the packages from there.
devShells = forAllSystems (
system:
let
pkgs = nixpkgsFor.${system};
nvimPackages = import ./src/nvim/packages.nix pkgs;
in
{
default = pkgs.mkShell { buildInputs = nvimPackages; };
python39 = pythonShell {
myPkgs = pkgs;
pythonVersion = pkgs.python39;
};
python310 = pythonShell {
myPkgs = pkgs;
pythonVersion = pkgs.python310;
};
python311 = pythonShell {
myPkgs = pkgs;
pythonVersion = pkgs.python311;
};
python312 = pythonShell {
myPkgs = pkgs;
# Stable has a bug with babel 2.12.1 and needs updating to 2.13.1
pythonVersion = pkgs.unstable.python312;
};
}
);
# Create packages out of my wrapped applications. Mostly for fun.
packages = forAllSystems (
system:
let
pkgs = nixpkgsFor.${system};
in
{
mytmux = inputs.wrapper-manager.lib.build {
inherit pkgs;
modules = [ ./src/tmux ];
};
myneovim = pkgs.callPackage ./src/nvim/myneovim.nix { inherit pkgs; };
}
);
# Expose my wrapped applications. This lets you do stuff like:
# nix run git+https://github.com/thornycrackers/nix-config#myneovim
# nix run git+https://github.com/thornycrackers/nix-config#mytmux
#
# If you want to test the setups out
apps = forAllSystems (system: {
mytmux = {
type = "app";
program = "${self.packages.${system}.mytmux}/bin/tmux";
};
myneovim = {
type = "app";
program = "${self.packages.${system}.myneovim}/bin/nvim";
};
});
# Configuration for development machine
nixosConfigurations.boston = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
# This makes my custom overlay available for others to use.
(
{ config, pkgs, ... }:
{
nixpkgs.overlays = [ my-custom-overlay ];
}
)
# Configuration for the system
./hosts/boston/configuration.nix
# Home manager stuff, user name needs sync with configuration.nix
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.thorny = import ./hosts/shared/home-linux.nix;
home-manager.extraSpecialArgs = {
inherit inputs;
username = "thorny";
homedirectory = "/home/thorny";
};
}
];
};
# Configuration for development machine
nixosConfigurations.snow =
let
system = "x86_64-linux";
flakePkgs = self.packages."${system}";
in
nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = {
inherit flakePkgs;
};
modules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
# This makes my custom overlay available for others to use.
(
{ config, pkgs, ... }:
{
nixpkgs.overlays = [ my-custom-overlay ];
}
)
# Configuration for the system
./hosts/snow/configuration.nix
# Home manager stuff, user name needs sync with configuration.nix
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.thorny = import ./hosts/shared/home-linux-desktop.nix;
home-manager.extraSpecialArgs = {
inherit inputs;
username = "thorny";
homedirectory = "/home/thorny";
};
}
];
};
# Configuration for development machine
nixosConfigurations.enigma =
let
system = "aarch64-linux";
flakePkgs = self.packages."${system}";
in
nixpkgs.lib.nixosSystem {
inherit system;
specialArgs = {
inherit flakePkgs;
};
modules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
# This makes my custom overlay available for others to use.
(
{ config, pkgs, ... }:
{
nixpkgs.overlays = [ my-custom-overlay ];
}
)
# Configuration for the system
./hosts/enigma/configuration.nix
# Home manager stuff, user name needs sync with configuration.nix
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.thorny = import ./hosts/shared/home-linux.nix;
home-manager.extraSpecialArgs = {
inherit inputs;
username = "thorny";
homedirectory = "/home/thorny";
};
}
];
};
# Configuration for temp aarch64vm
nixosConfigurations.aarch64vm = nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
# This makes my custom overlay available for others to use.
(
{ config, pkgs, ... }:
{
nixpkgs.overlays = [ my-custom-overlay ];
}
)
# Configuration for the system
# This file doesn't exist in the repository. The script that
# provisions the VM generates the base config with `nixos-generate-config`
./hosts/aarch64vm/configuration.nix
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.root = import ./hosts/shared/home-linux.nix;
home-manager.extraSpecialArgs = {
inherit inputs;
username = "root";
homedirectory = "/root";
};
}
];
};
# Darwin config for macbook
darwinConfigurations."Codys-MacBook-Pro" =
let
system = "x86_64-darwin";
flakePkgs = self.packages."${system}";
in
inputs.darwin.lib.darwinSystem {
inherit system;
specialArgs = with inputs; {
inherit wrapper-manager flakePkgs;
};
pkgs = nixpkgsFor2311.${system};
modules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
# This makes my custom overlay available for others to use.
(
{ config, pkgs, ... }:
{
nixpkgs.overlays = [ my-custom-overlay ];
}
)
./hosts/macbook/darwin-configuration.nix
home-manager.darwinModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.codyhiar = import ./hosts/shared/home-macbooks.nix;
home-manager.extraSpecialArgs = {
inherit inputs;
};
}
];
};
# Darwin config for macbookwork
darwinConfigurations."Codys-MacBook-Pro-Work" =
let
system = "aarch64-darwin";
flakePkgs = self.packages."${system}";
in
inputs.darwin.lib.darwinSystem {
inherit system;
specialArgs = with inputs; {
inherit wrapper-manager flakePkgs;
};
modules = [
# Overlays-module makes "pkgs.unstable" available in configuration.nix
# This makes my custom overlay available for others to use.
(
{ config, pkgs, ... }:
{
nixpkgs.overlays = [ my-custom-overlay ];
}
)
./hosts/macbookwork/darwin-configuration.nix
home-manager2311.darwinModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.codyhiar = import ./hosts/shared/home-macbooks.nix;
home-manager.extraSpecialArgs = {
inherit inputs;
};
}
];
};
};
}