-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
280 lines (264 loc) Β· 10.3 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
{
description = "Garuda Linux infrastructure flake βοΈ";
nixConfig.extra-substituters = [ "https://garuda-linux.cachix.org" ];
nixConfig.extra-trusted-public-keys = [ "garuda-linux.cachix.org-1:tWw7YBE6qZae0L6BbyNrHo8G8L4sHu5QoDp0OXv70bg=" ];
inputs = {
# Devshell to set up a development environment
devshell.url = "github:numtide/devshell";
devshell.inputs.nixpkgs.follows = "nixpkgs";
# Used by multiple flakes, have them use the same version
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
# Flake parts for easy flake management
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
# Home-manager for dotfile management
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
# The single source of truth
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-24.05";
# Our mailserver
nixos-mailserver.url = "gitlab:simple-nixos-mailserver/nixos-mailserver/master";
nixos-mailserver.inputs.flake-compat.follows = "flake-compat";
nixos-mailserver.inputs.nixpkgs.follows = "nixpkgs";
nixos-mailserver.inputs.nixpkgs-24_05.follows = "nixpkgs-stable";
# Pre-commit hooks via nix-shell or nix develop
pre-commit-hooks.url = "github:cachix/git-hooks.nix";
pre-commit-hooks.inputs.flake-compat.follows = "flake-compat";
pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
pre-commit-hooks.inputs.nixpkgs-stable.follows = "nixpkgs-stable";
# SSH keys of maintainers
keys_nico.url = "https://github.com/dr460nf1r3.keys";
keys_nico.flake = false;
keys_tne.url = "https://github.com/justtne.keys";
keys_tne.flake = false;
keys_frank.url = "https://github.com/fgd-garuda.keys";
keys_frank.flake = false;
keys_technetium1.url = "https://github.com/technetium1.keys";
keys_technetium1.flake = false;
keys_alexjp.url = "https://github.com/alexjp.keys";
keys_alexjp.flake = false;
keys_xiota.url = "https://github.com/xiota.keys";
keys_xiota.flake = false;
keys_pedrohlc.url = "https://github.com/pedrohlc.keys";
keys_pedrohlc.flake = false;
# Sources for custom applications and files
src-chaotic-toolbox.url = "github:chaotic-aur/toolbox";
src-chaotic-toolbox.flake = false;
# TODO: https://github.com/NixOS/nix/pull/9163
src-chaotic-portable-builder = {
type = "gitlab";
owner = "garuda-linux";
repo = "tools%2Fchaotic-portable-builder";
flake = false;
};
src-repoctl.url = "github:cassava/repoctl";
src-repoctl.flake = false;
# TODO: https://github.com/NixOS/nix/pull/9163
src-buildiso = {
type = "gitlab";
owner = "garuda-linux";
repo = "tools%2Fbuildiso-docker";
flake = false;
};
src-chaotic-mirror.url = "github:chaotic-aur/docker-mirror";
src-chaotic-mirror.flake = false;
# TODO: https://github.com/NixOS/nix/pull/9163
src-garuda-website = {
type = "gitlab";
owner = "garuda-linux";
repo = "website%2Fgaruda";
flake = false;
};
src-cloudflare-ipv4 = {
url = "https://www.cloudflare.com/ips-v4";
flake = false;
};
src-cloudflare-authenticated_origin_pull_ca = {
url = "https://developers.cloudflare.com/ssl/static/authenticated_origin_pull_ca.pem";
flake = false;
};
};
outputs =
{ flake-parts
, nixpkgs
, pre-commit-hooks
, self
, ...
} @ inputs:
let
perSystem =
{ pkgs
, system
, ...
}: {
apps.default = self.outputs.devShells.${system}.default.flakeApp;
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
hooks = {
actionlint.enable = true;
ansible-lint.enable = true;
check-json.enable = true;
commitizen.enable = true;
deadnix.enable = true;
detect-private-keys.enable = true;
flake-checker.enable = true;
nil.enable = true;
nixpkgs-fmt.enable = true;
prettier.enable = true;
statix.enable = true;
yamllint.enable = true;
};
src = ./.;
};
};
devShells =
let
buildiso = ''
if ! command -v docker &>/dev/null; then
echo "This command requires docker to be installed. Please install Docker and try again."
exit 1
fi
if ! docker images | grep buildiso &>/dev/null; then
docker build ${inputs.src-buildiso} -t buildiso
fi
docker run --rm -it --privileged --name buildiso \
-v "./buildiso/buildiso:/var/cache/garuda-tools/garuda-chroots/buildiso" \
-v "./buildiso/cron:/var/spool/anacron" \
-v "./buildiso/pkg:/var/cache/pacman/pkg/" \
-v "./buildiso/iso:/var/cache/garuda-tools/garuda-builds/iso/" \
-v "./buildiso/logs:/var/cache/garuda-tools/garuda-logs/" \
buildiso /bin/bash
'';
immortalis = "builds.garudalinux.org";
ipv6-generator = builtins.readFile ./scripts/ipv6-generator.sh;
makeDevshell = import "${inputs.devshell}/modules" pkgs;
mkShell = config:
(makeDevshell {
configuration = {
inherit config;
imports = [ ];
};
}).shell;
in
rec {
default = infra-nix-shell;
infra-nix-shell = mkShell {
devshell = {
name = "infra-nix";
startup = {
preCommitHooks.text = self.checks.${system}.pre-commit-check.shellHook;
dr460nixedEnv.text = ''
export LC_ALL="C.UTF-8"
export NIX_PATH=nixpkgs=${nixpkgs}
'';
};
};
commands = [
{ package = "ansible"; }
{ package = "rsync"; }
{ package = "commitizen"; }
{ package = "manix"; }
{ package = "mdbook"; }
{ package = "mdbook-admonish"; }
{ package = "mdbook-emojicodes"; }
{ package = "nodePackages.prettier"; }
{ package = "nixos-install-tools"; }
{ package = "pre-commit"; }
{
name = "apply";
help = "Applies the infra-nix configuration pushed to the servers";
command = ''
ansible-playbook playbooks/apply.yml
'';
}
{
name = "clean";
help = "Runs the garbage collection on the servers";
command = ''
ansible-playbook playbooks/garbage_collect.yml
'';
}
{
name = "deploy";
help = "Deploys the local NixOS configuration to the servers";
command = ''
ansible-playbook playbooks/garuda.yml
'';
}
{
name = "update";
help = "Performs a full system update on the servers bumping flake lock";
command = ''
ansible-playbook playbooks/system_update.yml
'';
}
{
name = "restart";
help = "Restarts all physical servers";
command = ''
ansible-playbook playbooks/reboot.yml
'';
}
{
name = "update-forum";
help = "Updates the Discourse container of our forum";
category = "infra-nix";
command = ''
# We are assuming the NixOS user is named the same as the one using it
ssh -p224 ${immortalis} "cd /var/discourse; sudo ./launcher rebuild app"
'';
}
{
name = "buildiso-remote";
help = "Spawns a buildiso shell on the iso-runner builder";
category = "infra-nix";
command = ''
# We are assuming the NixOS user is named the same as the one using it
ssh -p227 -t ${immortalis} "buildiso"
'';
}
{
name = "buildiso-local";
help = "Spawns a local buildiso shell to build to ./buildiso (needs Docker)";
category = "infra-nix";
command = buildiso;
}
{
name = "ipv6-generator";
help = "Generates random IPv6 addresses in our /64 subnet to help rorating them";
category = "infra-nix";
command = ipv6-generator;
}
];
motd = ''
{202}π¨ Welcome to Garuda's infra-nix shell{reset} βοΈ
$(type -p menu &>/dev/null && menu)
'';
};
};
formatter = pkgs.nixpkgs-fmt;
packages = {
docs =
pkgs.runCommand "infra-docs"
{ nativeBuildInputs = with pkgs; [ bash mdbook ]; }
''
bash -c "errors=$(mdbook build -d $out ${./.}/docs |& grep ERROR)
if [ \"$errors\" ]; then
exit 1
fi"
'';
};
};
in
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
./nixos/flake-module.nix
inputs.devshell.flakeModule
inputs.pre-commit-hooks.flakeModule
];
systems = [ "x86_64-linux" "aarch64-linux" ];
inherit perSystem;
};
}