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
|
{ config, lib, input, pkgs, ... }:
let
sefidelKeys = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILN14b5Fu+StHeMXq4ClyLG4G+/vCAfS7adxceEFria/ openpgp:0x1D5BCD11" ];
maintainerKeys = [ ] ++ sefidelKeys;
poorObfuscation = y: x: "${x}@${y}";
in
{
imports = [ ];
deployment = {
targetHost = "kanata.bee-polaris.ts.net";
targetUser = "root";
};
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
boot.supportedFilesystems = [ "zfs" ];
networking.hostId = "31cc5527";
networking.hostName = "kanata";
# Erase your darlings
boot.initrd.postDeviceCommands = lib.mkAfter ''
zfs rollback -r rpool/local/root@blank
'';
boot.kernelModules = [ "r8169" ];
boot.initrd.kernelModules = [ "r8169" ];
boot.initrd.network.enable = true;
boot.initrd.network.ssh = {
enable = true;
# Using the same port as the actual SSH daemon will cause the clients to
# throw errors related to host key mismatch.
port = 2222;
hostKeys = [
# XXX: This has to be manually generated during NixOS install.
# The files are then copied to initrd secrets during activation.
"/persist/initrd/ssh_host_rsa_key"
"/persist/initrd/ssh_host_ed25519_key"
];
authorizedKeys = maintainerKeys;
};
boot.initrd.network.postCommands = ''
cat <<EOF > /root/.profile
if pgrep -x "zfs" > /dev/null
then
zfs load-key -a
killall zfs
else
echo "ZFS is not running -- this could be a sign of failure."
fi
EOF
'';
modules.tailscale-initrd = {
enable = true;
# XXX: This has to be manually generatd during NixOS install.
# The files are then copied to initrd secrets during activation.
tailscaleStatePath = "/persist/initrd/tailscale-initrd.state";
};
services.openssh.enable = true;
users.users.root.openssh.authorizedKeys.keys = maintainerKeys;
# NOTE: managed by modules.persistence
# TODO: remove?
# fileSystems."/persist".neededForBoot = true;
#
# services.openssh.hostKeys = [
# {
# path = "/persist/ssh/ssh_host_ed25519_key";
# type = "ed25519";
# }
# {
# path = "/persist/ssh/ssh_host_rsa_key";
# type = "rsa";
# bits = 4096;
# }
# ];
sops.defaultSopsFile = ./secrets/secrets.yaml;
powerManagement.cpuFreqGovernor = "ondemand";
sops.secrets.zfs-smol-key = { };
sops.secrets.nextcloud-admin-pass = { owner = "nextcloud"; };
sops.secrets.acme-credentials = { owner = "acme"; };
sops.secrets.grafana-admin-pass = { owner = "grafana"; };
sops.secrets.cf-kusanari-kanata-credentials = { owner = "cloudflared"; };
sops.secrets.nitter-account-jsonl = { };
sops.secrets.interlink-password = { };
sops.secrets.interlink-ovpn = { };
sops.secrets.interlink-ovpn-creds = { };
# TODO: insecure?
sops.secrets.invidious-hmac = { mode = "0444"; };
boot.kernel.sysctl."net.ipv4.ip_forward" = 1;
boot.kernel.sysctl."net.ipv6.conf.all.forwarding" = 1;
networking.firewall.enable = true;
networking.nat = {
enable = true;
internalInterfaces = [ "ve-+" ];
externalInterface = "enp3s0";
# Lazy IPv6 connectivity for the container
enableIPv6 = true;
};
services.tailscale = {
enable = true;
useRoutingFeatures = "both";
openFirewall = true;
};
services.nginx.enable = true;
services.cloudflared = {
enable = true;
tunnels."bf6dcc14-d315-41c7-b798-3fe0e0e968eb" = {
default = "http_status:404";
};
};
networking.firewall.allowedTCPPorts = [ 80 443 ];
modules = {
persistence.directories = [
"/var/lib/tailscale"
"/var/lib/nixos-containers"
];
persistence = {
enable = true;
storagePath = "/persist";
};
# NOTE: This module only populates route entries,
# each service needs to be enabled individually.
expose = {
enable = true;
routes = {
"dns.kusanari.network" = "http://localhost:4000";
"metrics.kusanari.network" = "http://localhost:4001";
"nitter.kusanari.network" = "http://localhost:4002";
"invidious.kusanari.network" = "http://localhost:4003";
# Nginx pre-configured routes
# NOTE: Routes with port 80 or 443 will NOT create corresponding nginx virtualHosts.
"nextcloud.kusanari.network" = "http://localhost:80";
};
ssl = {
enable = true;
acmeHost = "kusanari.network";
};
tailscaleIp = "100.93.1.1";
# kusanari-kanata @ core
cloudflareUUID = "bf6dcc14-d315-41c7-b798-3fe0e0e968eb";
secrets.cloudflare-credentials = config.sops.secrets.cf-kusanari-kanata-credentials.path;
};
services.nginx.enable = true;
services.acme = {
enable = true;
email = poorObfuscation "sefidel.net" "postmaster";
certs = {
"kusanari.network" = {
subDomains = [
"nitter"
"nextcloud"
"jellyfin"
"dns"
"metrics"
"invidious"
];
};
};
secrets.acme-credentials = config.sops.secrets.acme-credentials.path;
};
services.metrics = {
enable = true;
realHost = "metrics.kusanari.network";
secrets.adminPassword = config.sops.secrets.grafana-admin-pass.path;
};
services.postgresql.enable = true;
services.blocky.enable = true;
services.nextcloud = rec {
enable = true;
ssl = {
enable = true;
acmeHost = domain;
};
domain = "kusanari.network";
realHost = "nextcloud.kusanari.network";
secrets.admin-pass = config.sops.secrets.nextcloud-admin-pass.path;
};
services.nitter = {
enable = true;
title = "Kusanari Nitter";
domain = "kusanari.network";
realHost = "nitter.kusanari.network";
secrets.nitter-guest-accounts = config.sops.secrets.nitter-account-jsonl.path;
};
services.invidious = {
enable = true;
domain = "kusanari.network";
realHost = "invidious.kusanari.network";
secrets.invidious-hmac-key = config.sops.secrets.invidious-hmac.path;
};
};
containers.v-ext-proxy = {
autoStart = true;
enableTun = true;
# Tailscale authkeys expire after 90 days, which means if a system
# restarts, there's a high chance that the key will be invalid.
# Therefore, we use classic authentication with non-ephemeral storage.
ephemeral = false;
privateNetwork = true;
hostAddress = "172.16.1.1";
localAddress = "172.16.1.2";
bindMounts."/run/secrets/interlink-password".hostPath = config.sops.secrets.interlink-password.path;
# bindMounts."/run/secrets/interlink-ovpn".hostPath = config.sops.secrets.interlink-ovpn.path;
# bindMounts."/run/secrets/interlink-ovpn-creds".hostPath = config.sops.secrets.interlink-ovpn-creds.path;
config = { config, pkgs, lib, ... }: {
services.tailscale = {
enable = true;
useRoutingFeatures = "both";
extraUpFlags = [
"--advertise-exit-node=true"
];
};
networking.openconnect.interfaces.openconnect0 = {
autoStart = true;
gateway = "133.242.23.15"; # JP#11
# gateway = "133.242.17.239"; # JP#1
protocol = "anyconnect";
user = "sk146241";
passwordFile = "/run/secrets/interlink-password";
extraOptions = {
servercert = "pin-sha256:42cxGem/A2lRRPLefN3tSlPHFD1mK0BLh7tbUJeXvhE="; # JP#11
# servercert = "pin-sha256:OvJIFf7gPPbnR7tdG0Uj10GET5eynt+o5pfKBIEA+ws="; # JP#1
};
};
systemd.services.openconnect-openconnect0 = {
serviceConfig = {
# XXX: On initial startup, the service would fail with
# 'No route to host'.
Restart = "on-failure";
RestartSec = "5s";
};
};
# services.openvpn.servers.interlink-sekai = {
# autoStart = true;
# config = "config /run/secrets/interlink-ovpn";
# up = "echo nameserver $nameserver | ${pkgs.openresolv}/sbin/resolvconf -m 0 -a $dev";
# down = "${pkgs.openresolv}/sbin/resolvconf -d $dev";
# };
system.stateVersion = "24.05";
};
};
# This option defines the first version of NixOS you have installed on this particular machine,
# and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
#
# Most users should NEVER change this value after the initial install, for any reason,
# even if you've upgraded your system to a new NixOS release.
#
# This value does NOT affect the Nixpkgs version your packages and OS are pulled from,
# so changing it will NOT upgrade your system - see https://nixos.org/manual/nixos/stable/#sec-upgrading for how
# to actually do that.
#
# This value being lower than the current NixOS release does NOT mean your system is
# out of date, out of support, or vulnerable.
#
# Do NOT change this value unless you have manually inspected all the changes it would make to your configuration,
# and migrated your data accordingly.
#
# For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
system.stateVersion = "24.05"; # Did you read the comment?
}
|