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
|
{
imports = [
./base.nix
./acme.nix { services.nginx.enable = true; } # acme currently uses nginx (but doesn't need it)
../../configs/retiolum.nix
../../configs/fail2ban.nix
# DNS server configuration
{
# requires acme
tv.unbound.enable = true;
tv.unbound.DoH.enable = true;
tv.unbound.DoT.enable = true;
tv.unbound.host = "ns2.viljetic.de";
tv.unbound.useACMEHost = "viljetic.de";
}
# SSH configuration
({ config, options, lib, pkgs, ... }: {
services.openssh = {
enable = true;
allowSFTP = false;
# mkForce to prevent duplicate keys
hostKeys = lib.mkForce (lib.singleton ({
type = "ed25519";
path = "${config.krebs.secret.directory}/ssh.id_ed25519";
}));
# macs and moduliFile are also in configs/sshd.nix
settings.Macs = let
default-macs =
(options.services.openssh.settings.type.getSubOptions throw)
.Macs.default;
mac-blacklist = ["hmac-sha2-512" "hmac-sha2-256" "umac-128@openssh.com"];
in
builtins.filter (mac: !builtins.elem mac mac-blacklist) default-macs;
# "All Diffie-Hellman moduli in use should be at least 3072-bit-long"
# Refs https://infosec.mozilla.org/guidelines/openssh#modern-openssh-67
moduliFile = pkgs.runCommand "ssh-moduli" {} ''
awk '$5 >= 3017' ${config.programs.ssh.package}/etc/ssh/moduli > $out
'';
};
# Exempt these interfaces from configs/sshd.nix's port 22 redirect,
# which would also catch forwarded ssh.
# This is also required to access rut.jane.
hrm.nftables.tables.nat.chains.prerouting.rules.ssh-interfaces = {
order = 800;
text = ''iifname { "lo", "retiolum", "wiregrill" } accept'';
};
})
({ config, ... }: {
hrm.nftables.enable = true;
krebs.build.host = config.krebs.hosts.ne;
})
({ pkgs, ... }: {
boot.kernelPackages = pkgs.linuxPackages_latest;
})
../../configs/networkd.nix
{
networking.interfaces.ens3.useDHCP = true;
networking.nameservers = [ "127.0.0.1" ];
}
# IPv6 configuration
({ config, ... }: {
networking.defaultGateway6 = {
address = "fe80::1";
interface = "ens3";
};
networking.interfaces.ens3.ipv6.addresses = [
{
address = config.krebs.build.host.nets.internet.ip6.addr;
prefixLength = config.krebs.build.host.nets.internet.ip6.prefixLength;
}
];
tv.iptables.extra6.filter.INPUT = [
# Allow Neighbor Discovery
# https://en.wikipedia.org/wiki/Neighbor_Discovery_Protocol
"-p icmpv6 --icmpv6-type 133 -j ACCEPT"
"-p icmpv6 --icmpv6-type 134 -j ACCEPT"
"-p icmpv6 --icmpv6-type 135 -j ACCEPT"
"-p icmpv6 --icmpv6-type 136 -j ACCEPT"
];
})
# wiregrill configuration
# requires secret: wiregrill.key
# see also stockholm's kartei/tv/hosts/ne.nix
({ config, ... }: {
imports = [
../../configs/wiregrill.nix
];
boot.kernel.sysctl."net.ipv4.ip_forward" = 1;
tv.iptables.extra4.nat.POSTROUTING = [ "-s 10.244.3.0/24 ! -d 10.244.3.0/24 -j MASQUERADE" ];
tv.iptables.extra6.nat.POSTROUTING = [ "-s 42:1::/32 ! -d 42:1::/32 -j MASQUERADE" ];
tv.iptables.extra6.filter.FORWARD = [
"-s ${config.krebs.hosts.pi.nets.wiregrill.ip6.addr} -j ACCEPT"
"-s 42:1:a46e::/48 -j ACCEPT" # tv
];
tv.iptables.extra4.filter.FORWARD = [
"-i wiregrill -o wiregrill -j ACCEPT"
"-i wiregrill -o retiolum -j ACCEPT"
"-i retiolum -o wiregrill -j ACCEPT"
];
})
# Nginx configuration
({ lib, ... }: {
imports = [
../../configs/nginx
];
services.nginx.enable = true;
services.nginx.appendHttpConfig = ''
map $sent_http_content_type $charset {
~^text/ utf-8;
}
charset $charset;
charset_types *;
'';
services.nginx.commonHttpConfig = ''
add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload' always;
'';
tv.iptables.input-internet-accept-tcp = [
"http"
"https"
];
# 2025/10/23 12:21:08 [alert] 2056944#2056944: 512 worker_connections are not enough
services.nginx.eventsConfig = ''
worker_connections 2048;
'';
# Oct 23 15:41:42 ni nginx[2658928]: 2025/10/23 15:41:42 [alert] 2658928#2658928: *27810 socket() failed (24: Too many open files) while connecting to upstream, client: ::1, server: cgit, request: "GET ... HTTP/1.0", upstream: "fastcgi://unix:/run/fcgiwrap-cgit.sock:", host: "cgit"
# Oct 23 15:41:42 ni nginx[2658928]: 2025/10/23 15:41:42 [crit] 2658928#2658928: accept4() failed (24: Too many open files)
# cat /proc/$(pgrep -u nginx nginx | head -n 1)/limits | grep --color -C 100 '^Max open files .*'
systemd.services.nginx.serviceConfig = {
LimitNOFILE = 4096;
};
})
# Nginx configuration: public_html
(let
locations."~ ^/~([a-z]+)(?:/(.*))?\$" = {
alias = "/srv/$1/public_html/$2";
};
in {
services.nginx.virtualHosts."ne.r".locations = locations;
services.nginx.virtualHosts."viljetic.de".locations = locations;
services.nginx.virtualHosts."ne.krebsco.de".locations = locations;
})
# Nginx configuration: viljetic-pages
({ pkgs, ... }: {
services.nginx.virtualHosts."viljetic.de" = {
useACMEHost = "viljetic.de";
forceSSL = true;
root = pkgs.viljetic-pages;
};
services.nginx.virtualHosts."www.viljetic.de" = {
useACMEHost = "viljetic.de";
forceSSL = true;
locations."/".return = "301 $scheme://viljetic.de$request_uri";
};
})
# Nginx configuration: ne.krebsco.de
{
security.acme.certs."ne.krebsco.de".email = "tv@krebsco.de";
services.nginx.virtualHosts."ne.krebsco.de" = {
enableACME = true;
forceSSL = true;
};
}
# Git configuration
# depends on nginx
({ config, lib, ... }: {
imports = [
../../configs/gitrepos.nix
];
services.nginx.virtualHosts."cgit.viljetic.de" = {
serverAliases = [
"cgit.ne.viljetic.de"
];
useACMEHost = "viljetic.de";
forceSSL = true;
locations."/".extraConfig = ''
proxy_set_header Host cgit;
proxy_pass http://localhost;
'';
};
security.acme.certs."cgit.krebsco.de".email = "tv@krebsco.de";
services.nginx.virtualHosts."cgit.krebsco.de" = {
serverAliases = [
"cgit.ne.krebsco.de"
];
enableACME = true;
forceSSL = true;
locations."/".extraConfig = ''
proxy_set_header Host cgit;
proxy_pass http://localhost;
'';
};
# secrets ne gencert cgit.ne.r
hrm.systemd.services.nginx.reloadIfCredentialsChange = true;
systemd.services.nginx.serviceConfig.LoadCredential = [
"cgit.ne.r.crt:${config.krebs.secret.directory}/cgit.ne.r.crt"
"cgit.ne.r.key:${config.krebs.secret.directory}/cgit.ne.r.key"
];
services.nginx.virtualHosts."cgit.ne.r" = {
onlySSL = true;
sslCertificate = "/run/credentials/nginx.service/cgit.ne.r.crt";
sslCertificateKey = "/run/credentials/nginx.service/cgit.ne.r.key";
locations."/".extraConfig = ''
proxy_set_header Host cgit;
proxy_pass http://localhost;
'';
};
})
];
}
|