This repository was archived by the owner on Nov 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdefault.nix
More file actions
292 lines (279 loc) · 8.76 KB
/
Copy pathdefault.nix
File metadata and controls
292 lines (279 loc) · 8.76 KB
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
{
config,
inputs,
pkgs,
namespace,
...
}:
let
# Do not change this value! This tracks when NixOS was installed on your system.
stateVersion = "24.11";
hostName = "Hevana";
# Where to store service files
services-root = "/storage/services";
# Credentials for interacting with the Porkbun API
porkbunCredentials = {
"PORKBUN_API_KEY_FILE" = "${pkgs.writeText "porkbun-api-key" ''
${config.${namespace}.secrets.networking.porkbun.api.apiKey}
''}";
"PORKBUN_SECRET_API_KEY_FILE" = "${pkgs.writeText "porkbun-secret-api-key" ''
${config.${namespace}.secrets.networking.porkbun.api.secretKey}
''}";
};
# Block list for Nginx
nginxBlocklist = {
locations."/robots.txt" = {
alias = "${inputs.ai-blocklist}/robots.txt";
};
extraConfig = ''
if ($http_user_agent ~* "(${builtins.readFile "${inputs.ai-blocklist}/robots.txt"})") {
return 444;
}
'';
};
in
{
imports = [ ./hardware-configuration.nix ];
system.stateVersion = stateVersion;
networking.hostName = hostName;
services = {
# Enable internal-only Nginx status page
nginx.statusPage = true;
# Monitor RAID drives using SMART
smartd.devices = [
{ device = "/dev/sda"; }
{ device = "/dev/sdb"; }
{ device = "/dev/sdc"; }
{ device = "/dev/sdd"; }
];
};
# Build Nix packages for other hosts.
# Runs every Saturday morning at 4 AM
systemd.services."build-hosts" = {
serviceConfig = {
Type = "oneshot";
User = "aires";
};
path = config.${namespace}.corePackages;
script = ''
/run/current-system/sw/bin/nixos-operations-script --operation build --hostname Khanda --flake ${
config.${namespace}.secrets.nixConfigFolder
}
'';
};
systemd.timers."build-hosts" = {
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "Sat, 04:00";
Persistent = true;
Unit = "build-hosts.service";
};
};
# Configure the system.
${namespace} = {
# Enable Secure Boot support.
bootloader = {
enable = true;
secureboot.enable = true;
tpm2.enable = true;
};
# Enable GPU support.
gpu.amd.enable = true;
# Enable support for primary RAID array
raid = {
enable = true;
mailAddr = config.${namespace}.secrets.users.aires.email;
storage = {
enable = true;
keyFile = config.${namespace}.secrets.devices.storage.keyFile.path;
};
};
services = {
acme = {
enable = true;
defaultEmail = config.${namespace}.secrets.users.aires.email;
certs = {
"${config.${namespace}.secrets.networking.domains.primary}" = {
dnsProvider = "porkbun";
domain = "*.${config.${namespace}.secrets.networking.domains.primary}";
webroot = null; # Required in order to prevent a failed assertion
credentialFiles = porkbunCredentials;
};
"${config.${namespace}.secrets.networking.domains.blog}" = {
dnsProvider = "porkbun";
webroot = null; # Required in order to prevent a failed assertion
credentialFiles = porkbunCredentials;
};
};
};
apcupsd = {
enable = true;
configText = builtins.readFile ./etc/apcupsd.conf;
};
archiveteam-warrior = {
enable = true;
useVPN = true;
port = 8001;
};
autoUpgrade = {
enable = true;
pushUpdates = true; # Update automatically and push updates back up to Forgejo
onCalendar = "06:00";
configDir = config.${namespace}.secrets.nixConfigFolder;
user = config.users.users.aires.name;
};
binary-cache = {
enable = true;
secretKeyFile = "${services-root}/nixos-binary-cache/certs/cache-priv-key.pem";
url = config.${namespace}.secrets.services.binary-cache.url;
auth = {
user = config.${namespace}.secrets.services.binary-cache.auth.username;
password = config.${namespace}.secrets.services.binary-cache.auth.password;
};
};
duplicacy-web = {
enable = true;
home = "/storage/backups/settings/Haven";
homeBackupDir = "/home/aires/duplicacy-settings-backup-Hevana";
};
forgejo = {
enable = true;
home = "${services-root}/forgejo";
url = config.${namespace}.secrets.services.forgejo.url;
};
jellyfin = {
enable = true;
home = "${services-root}/jellyfin";
url = config.${namespace}.secrets.services.jellyfin.url;
};
languagetool = {
enable = true;
url = config.${namespace}.secrets.services.languagetool.url;
port = 8100;
auth = {
user = config.${namespace}.secrets.services.languagetool.auth.user;
password = config.${namespace}.secrets.services.languagetool.auth.password;
};
ngrams.enable = true;
};
msmtp = {
enable = true;
accounts.default = {
host = config.${namespace}.secrets.services.msmtp.host;
user = config.${namespace}.secrets.services.msmtp.user;
password = config.${namespace}.secrets.services.msmtp.password;
auth = true;
tls = true;
tls_starttls = true;
port = 587;
from = "${config.networking.hostName}@${config.${namespace}.secrets.networking.domains.primary}";
};
aliases = {
text = ''
default: ${config.${namespace}.secrets.users.aires.email}
'';
mode = "0644";
};
};
nginx = {
enable = true;
virtualHosts = {
"${config.${namespace}.secrets.networking.domains.primary}" = {
default = true;
enableACME = true; # Enable Let's Encrypt
locations."/" = {
# Catchall vhost, will redirect users to Forgejo
return = "301 https://${config.${namespace}.secrets.services.forgejo.url}";
};
} // nginxBlocklist;
# Personal blog website
"${config.${namespace}.secrets.networking.domains.blog}" = {
useACMEHost = config.${namespace}.secrets.networking.domains.blog;
forceSSL = true;
root = "${services-root}/nginx/sites/${config.${namespace}.secrets.networking.domains.blog}";
} // nginxBlocklist;
# Work lab VM
"${config.${namespace}.secrets.hosts.gremlin-lab.URI}" = {
useACMEHost = config.${namespace}.secrets.networking.domains.primary;
forceSSL = true;
locations."/" = {
proxyPass = "http://${config.${namespace}.secrets.hosts.gremlin-lab.IP}";
proxyWebsockets = true;
extraConfig = "proxy_ssl_server_name on;";
};
};
};
};
observability = {
enable = true;
url = config.${namespace}.secrets.services.observability.url;
grafana = {
home = "${services-root}/observability/grafana";
smtp = with config.${namespace}.secrets.services.msmtp; {
enabled = true;
host = "${host}:465";
user = user;
password = password;
startTLS_policy = "MandatoryStartTLS";
from_name = "Grafana";
from_address = "admin@${config.${namespace}.secrets.networking.domains.primary}";
};
};
};
open-webui = {
enable = true;
url = config.${namespace}.secrets.services.open-webui.url;
ollama.enable = true;
};
qbittorrent = {
enable = true;
home = "${services-root}/qbittorrent";
url = config.${namespace}.secrets.services.qbittorrent.url;
port = 8090;
};
ssh = {
enable = true;
ports = [ config.${namespace}.secrets.hosts.hevana.ssh.port ];
};
syncthing = {
enable = true;
home = "${services-root}/syncthing/aires";
user = "aires";
web = {
enable = true;
public = true;
};
};
tor = {
enable = true;
snowflake-proxy = {
enable = true;
capacity = 50;
};
};
virtualization.host = {
enable = true;
vmBuilds = {
enable = true;
cores = 3;
ram = 4096;
};
};
vpn = {
enable = true;
auth = with config.${namespace}.secrets.services.private-internet-access.auth; {
user = user;
password = password;
};
countries = [
"Switzerland"
"Netherlands"
];
port = config.${namespace}.services.qbittorrent.port;
};
};
users.aires.enable = true;
};
}