-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
274 lines (262 loc) · 9.98 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
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable-small";
nixos-hardware.url = "github:NixOS/nixos-hardware/";
home-manager = {
url = "github:nix-community/home-manager";
# packages installed via home-manager use my nixpkgs
inputs.nixpkgs.follows = "nixpkgs";
};
nix-darwin = {
url = "github:LnL7/nix-darwin";
# packages installed via nix-darwin use my nixpkgs
inputs.nixpkgs.follows = "nixpkgs";
};
pre-commit-hooks.url = "github:cachix/git-hooks.nix";
nur.url = "github:nix-community/NUR";
flake-utils.url = "github:numtide/flake-utils";
sops-nix.url = "github:Mic92/sops-nix";
nix-netboot-serve.url = "github:DeterminateSystems/nix-netboot-serve";
deploy-rs.url = "github:serokell/deploy-rs";
# https://hydra.nixos.org/job/nixos/trunk-combined/nixos.sd_image.aarch64-linux
nixpkgs-raspberrypi.url = "github:nixos/nixpkgs/4d7c2644dbac9cf8282c0afe68fca8f0f3e7b2db";
plasma-manager = {
url = "github:pjones/plasma-manager";
inputs = {
nixpkgs.follows = "nixpkgs";
home-manager.follows = "home-manager";
};
};
};
outputs = { self, ... }@inputs:
let
# import all the overlays that extend packages via nix or home-manager.
overlays = [
inputs.nur.overlays.default
(import ./nix/pkgs)
# TODO: this was hacked, need to find a better way
#(import ./nix/pkgs/nvim-treesitter-sexp) # TODO: fix nvim-treesitter-sexp
];
# I am sure this is ugly to experienced nix users, and might break in all
# kinds of unexpected ways. This was my first actual function written in
# nix, and I never really figured out the repl, this is what I ended up
# with.
#
# This function takes a path, and returns a list of every file under it.
#
# TODO:
# - filter by .nix
# - handles readDir's `symlink` and `unknown` types
# - is there a better way than (path + ("/" + path))?
# - can this be moved into a library and sourced over inline?
getModules = path:
let
lib = inputs.nixpkgs.lib;
getNixFilesRec = path:
let
contents = builtins.readDir path;
files = builtins.attrNames (lib.filterAttrs (_: v: v == "regular") contents);
dirs = builtins.attrNames (lib.filterAttrs (_: v: v == "directory") contents);
nixFiles = lib.filter (p: lib.hasSuffix ".nix" p) files;
in
# return the path of all files found in this directory
(map (p: path + ("/" + p)) nixFiles)
++
# pass each directory into this function again
(lib.concatMap (d: getNixFilesRec (path + ("/" + d))) dirs);
in
getNixFilesRec path;
hmModules = getModules ./nix/modules/hm_modules;
nixModules = getModules ./nix/modules/nix_modules;
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forAllSystems = inputs.nixpkgs.lib.genAttrs supportedSystems;
in
{
checks = forAllSystems
(system: {
pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run
{
src = ./.;
hooks = {
black.enable = true;
nixpkgs-fmt.enable = true;
prettier = {
enable = true;
excludes = [ "flake.lock" ];
};
shellcheck.enable = true;
stylua.enable = true;
pkg_version = {
enable = false;
name = "pkg-version-bump";
entry = "bin/pre-commit-update-version";
files = "^nix/pkgs/.*?/default\.nix$";
language = "script";
pass_filenames = true;
};
};
}
//
# this functions outputs two checks defined in `deploy-rs`'s flake,
# `deploy-schema` and `deploy-activate`.
#
# https://github.com/serokell/deploy-rs/blob/aa07eb05537d4cd025e2310397a6adcedfe72c76/flake.nix#L128
builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) inputs.deploy-rs.lib;
});
devShells = forAllSystems (system: {
default = inputs.nixpkgs.legacyPackages.${system}.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
buildInputs = self.checks.${system}.pre-commit-check.enabledPackages;
};
});
nixosConfigurations = {
dino = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = nixModules ++ [
inputs.nixos-hardware.nixosModules.framework-12th-gen-intel
./nix/hosts/dino/configuration.nix
./nix/hosts/dino/hardware-configuration.nix
# todo: refactor these into something else
./nix/hosts/_includes/common.nix
./nix/hosts/_includes/docker.nix
./nix/hosts/_includes/kvm.nix
./nix/hosts/_includes/laptop.nix
inputs.sops-nix.nixosModules.sops
inputs.home-manager.nixosModules.home-manager
{
systemFoundry = {
deployment_target.enable = true;
users.kyle.enable = true;
desktop.kde.enable = true;
};
# TODO: overwriting for testing pourposes
services = {
power-profiles-daemon.enable = false; # am using tlp
mullvad-vpn.enable = true;
};
nixpkgs.overlays = overlays;
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
sharedModules = hmModules ++ [
# TODO: make this module available to all machines
inputs.plasma-manager.homeManagerModules.plasma-manager
];
users.kyle = {
imports = [ ./nix/profiles/full.nix ];
hmFoundry = {
desktop = {
browsers.qutebrowser.enable = true;
media.latex.enable = true;
term.wezterm.enable = true;
wm.kde.enable = true;
};
dev = {
hashicorp.enable = inputs.nixpkgs.lib.mkForce true;
};
};
};
};
}
];
};
tiger = inputs.nixpkgs.lib.nixosSystem
{
system = "x86_64-linux";
modules = nixModules ++ [
./nix/hosts/tiger/configuration.nix
inputs.sops-nix.nixosModules.sops
inputs.nix-netboot-serve.nixosModules.nix-netboot-serve
inputs.home-manager.nixosModules.home-manager
{
systemFoundry =
{
deployment_target.enable = true;
users.kyle.enable = true;
};
nixpkgs.overlays = overlays;
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
sharedModules = hmModules ++ [
# TODO: make this module available to all machines
inputs.plasma-manager.homeManagerModules.plasma-manager
];
users.kyle = import ./nix/profiles/ssh.nix;
};
}
];
};
iso = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./nix/iso.nix
"${inputs.nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix"
#inputs.sops-nix.nixosModules.sops
#{
# nixpkgs.overlays = overlays;
#}
];
};
sd_card = inputs.nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
"${inputs.nixpkgs-raspberrypi}/nixos/modules/installer/sd-card/sd-image-aarch64-new-kernel-installer.nix"
{
nixpkgs.config.allowUnsupportedSystem = true;
system.stateVersion = "23.05";
}
./nix/hosts/bootstrap.nix
];
};
pi1 = inputs.nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = nixModules ++ [
inputs.nixos-hardware.nixosModules."raspberry-pi-4"
./nix/hosts/pi1/configuration.nix
inputs.sops-nix.nixosModules.sops
inputs.home-manager.nixosModules.home-manager
{
systemFoundry = {
deployment_target.enable = true;
users.kyle.enable = true;
};
nixpkgs.overlays = overlays;
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
sharedModules = hmModules ++ [
# TODO: make this module available to all machines
# TODO: should this be available on machines we only ssh into?
inputs.plasma-manager.homeManagerModules.plasma-manager
];
users.kyle = import ./nix/profiles/ssh.nix;
};
}
];
};
};
# deploy-rs
deploy = {
fastConnection = true;
nodes = {
dino = {
hostname = "dino";
profiles.system = {
sshUser = "svc.deploy";
user = "root";
path = inputs.deploy-rs.lib.x86_64-linux.activate.nixos self.nixosConfigurations.dino;
};
};
tiger = {
hostname = "tiger";
profiles.system = {
sshUser = "svc.deploy";
user = "root";
path = inputs.deploy-rs.lib.x86_64-linux.activate.nixos self.nixosConfigurations.tiger;
};
};
};
};
};
}