-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
301 lines (282 loc) · 9.42 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
# this flake has gotten rather unwieldy and I need to refactor it severely
# a couple of improvements I need to make are:
# - refactor modules to not depend on pkgs
# - refactor configurations to be platform independent
# - refactor to allow the same host to be built for different targets, e.g. hyperion on a vm
# - allow the flake itself to be more command-based, e.g. "build a vm image of hyperion"
{
description = "My Nix system configurations.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
deploy-rs.url = "github:serokell/deploy-rs";
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-darwin = {
url = "github:LnL7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
emacs-overlay = {
url = "github:nix-community/emacs-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
# agenix is super busted. doesn't work for network deployments, and doesn't
# work when trying to set a secret credential in /etc/fstab. Look into using
# ragenix
agenix = {
url = "github:ryantm/agenix";
inputs.nixpkgs.follows = "nixpkgs";
};
hyprland = {
url = "github:hyprwm/Hyprland";
inputs.nixpkgs.follows = "nixpkgs";
};
wezterm = {
url = "github:wez/wezterm?dir=nix";
inputs.nixpkgs.follows = "nixpkgs";
};
disko = {
url = "github:nix-community/disko/latest";
inputs.nixpkgs.follows = "nixpkgs";
};
swww.url = "github:LGFae/swww";
# TODO consider using stylix
# currently, a wallpaper is required with stylix. this is problematic
# because I do not need to set a wallpaper in my config
base16.url = "github:SenchoPens/base16.nix";
tt-schemes = {
url = "github:tinted-theming/schemes";
flake = false;
};
murex.url = "github:rfaulhaber/murex";
nix-doom-emacs-unstraightened = {
url = "github:marienz/nix-doom-emacs-unstraightened";
inputs.nixpkgs.follows = "";
};
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs = inputs @ {
self,
nixpkgs,
home-manager,
deploy-rs,
nixos-hardware,
nixos-generators,
nix-darwin,
emacs-overlay,
flake-parts,
...
}: let
inherit (lib.my) mapModules mkPkgs;
pkgs = mkPkgs nixpkgs [];
# TODO import lib functions that don't depend on pkgs
lib = nixpkgs.lib.extend (self: super: {
my = import ./nix/lib {
inherit inputs pkgs;
lib = self;
};
});
in
{
templates = {
rust = {
path = ./nix/templates/rust;
description = "Rust project template";
};
emacs-lisp = {
path = ./nix/templates/emacs-lisp;
description = "Emacs Lisp template";
};
};
# TODO utilize top-level nixosModules
overlays = mapModules ./nix/overlays import;
# these are the actual system configurations
# any particular system can be build with nixos-rebuild of course, but also:
# nix build .#nixosConfigurations.<hostname>.config.system.build.toplevel
# TODO refactor as packages, configurations can be built as packages
# like so: packages.<platform>.nixosConfigurations.<hostname>.config.system.build.toplevel
nixosConfigurations = let
mkHost = lib.my.mkNixOSHost;
in {
hyperion = mkHost ./nix/hosts/hyperion/configuration.nix {
system = "x86_64-linux";
};
atlas = mkHost ./nix/hosts/atlas/configuration.nix {
system = "x86_64-linux";
};
helios = mkHost ./nix/hosts/helios/configuration.nix {
system = "x86_64-linux";
};
pallas = mkHost ./nix/hosts/pallas/configuration.nix {
system = "aarch64-linux";
};
nike = mkHost ./nix/hosts/nike/configuration.nix {
system = "aarch64-linux";
};
nexus = mkHost ./nix/hosts/nexus/configuration.nix {
system = "x86_64-linux";
};
};
#// lib.my.mkNixOSK8sNodes 4 ./nix/hosts/nexus/configuration.nix { system = "x86_64-linux"; masterAddress = "10.0.0.1"; };
# TODO add darwin configurations
# TODO write a mapHosts function, like here: https://github.com/hlissner/dotfiles/blob/master/lib/nixos.nix
# nixosConfigurations = mapHosts ./nix/hosts { };
deploy = {
sshUser = "ryan";
autoRollback = true;
magicRollback = true;
nodes = {
# run with: nix run '.#deploy-rs' '.#atlas'
atlas = {
hostname = "atlas";
profiles.system = {
user = "root";
path =
deploy-rs.lib.x86_64-linux.activate.nixos
self.nixosConfigurations.atlas;
};
};
pallas = {
hostname = "pallas";
profiles.system = {
user = "root";
fastConnection = true;
path =
deploy-rs.lib.aarch64-linux.activate.nixos
self.nixosConfigurations.pallas;
};
};
nike = {
hostname = "nike";
profiles.system = {
user = "root";
fastConnection = true;
activationTimeout = 600;
path =
deploy-rs.lib.aarch64-linux.activate.nixos
self.nixosConfigurations.nike;
};
};
};
};
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
}
# x86_64-linux-specific packages
# TODO custom packages should be added to pkgs, made available globally
# right now, my custom aarch64 installer can only be built on x86_64 linux
// {
packages.x86_64-linux = let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
};
in {
roc-rk3328-cc-bootloader = import ./nix/pkgs/roc-rk3328-cc-bootloader {
inherit pkgs;
lib = pkgs.lib;
};
# run with:
# nix build .#arm-roc-installer
arm-roc-installer = nixos-generators.nixosGenerate {
system = "aarch64-linux";
modules = [
./nix/installers/aarch64-linux/configuration.nix
];
specialArgs = {
inherit inputs;
};
customFormats.aarch64-linux-roc = import ./nix/formats/aarch64/linux/renegade-roc/configuration.nix {
inherit pkgs;
bootloader = self.packages.x86_64-linux.roc-rk3328-cc-bootloader;
};
format = "aarch64-linux-roc";
};
# supports raspberry pi up to version 4
arm-installer-generic = nixos-generators.nixosGenerate {
system = "aarch64-linux";
modules = [
./nix/installers/aarch64-linux/configuration.nix
];
specialArgs = {
inherit inputs;
};
format = "sd-aarch64-installer";
};
# arm-installer-rpi5 = nixos-generators.nixosGenerate {
# system = "aarch64-linux";
# modules = [
# ./nix/installers/aarch64-linux/configuration.nix
# ];
# specialArgs = {
# inherit inputs;
# };
# customFormats.aarch64-linux-rpi5 = import ./nix/formats/aarch64/linux/raspberry-pi/5/configuration.nix {
# inherit pkgs inputs;
# };
# format = "aarch64-linux-rpi5";
# };
x86_64-installer-generic = nixos-generators.nixosGenerate {
system = "x86_64-linux";
modules = [
./nix/installers/x86_64-linux/configuration.nix
];
specialArgs = {
inherit inputs;
};
format = "install-iso";
};
};
}
// (let
supportedSystems = ["x86_64-linux" "aarch64-darwin"];
forSystems = systems: f:
nixpkgs.lib.genAttrs systems
(system:
f system (import nixpkgs {
inherit system;
config.allowUnfree = true;
}));
forAllSystems = forSystems supportedSystems;
in {
formatter = forAllSystems (system: pkgs: pkgs.alejandra);
apps = forAllSystems (system: pkgs: {
# I re-export deploy-rs due to an issue with running `nix flake github:serokell/deploy-rs ...`
# per a conversation I had here: https://github.com/serokell/deploy-rs/issues/155
deploy-rs = deploy-rs.defaultApp."${system}";
generate = nixos-generators.apps.${system}.default;
});
devShells = forAllSystems (system: pkgs: {
deploy-rs = pkgs.mkShell {
buildInputs = [deploy-rs.defaultPackage."${system}"];
};
luaDev = pkgs.mkShell {
buildInputs = with pkgs; [
lua-language-server
luajitPackages.fennel
luajitPackages.luasocket
stylua
fnlfmt
];
};
cluster = pkgs.mkShell {
buildInputs = with pkgs; [
ansible
terraform
vagrant
];
};
generate = pkgs.mkShell {
buildInputs = [
nixos-generators.packages.${system}.default
];
};
default = self.devShells.${system}.generate;
});
});
}