summaryrefslogtreecommitdiffstats
path: root/systems/ne/config.nix
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-23 14:59:44 +0000
committertv <tv@krebsco.de>2026-11-23 15:18:49 +0000
commit91545e73f20e45a197fc4383f2a12d32ffe9c5b2 (patch)
treeb9118f05d77b45288e095f6d84f2706c3f4a3cb8 /systems/ne/config.nix
parentefa35f0a45257f74335093d927de47b8fcf102ce (diff)
ne: init
Diffstat (limited to 'systems/ne/config.nix')
-rw-r--r--systems/ne/config.nix231
1 files changed, 231 insertions, 0 deletions
diff --git a/systems/ne/config.nix b/systems/ne/config.nix
new file mode 100644
index 00000000..eff9a17d
--- /dev/null
+++ b/systems/ne/config.nix
@@ -0,0 +1,231 @@
+{
+ imports = [
+ ./base.nix
+ ./acme.nix { services.nginx.enable = true; } # acme currently uses nginx (but doesn't need it)
+
+ ../../configs/retiolum.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
+ '';
+ };
+
+ tv.iptables.extra.nat.OUTPUT = [
+ "-o lo -p tcp --dport 11423 -j REDIRECT --to-ports 22"
+ ];
+
+ # This is also required to access rut.jane.
+ tv.iptables.extra.nat.PREROUTING = [
+ "-i lo -j ACCEPT"
+ "-i retiolum -j ACCEPT"
+ "-i wiregrill -j ACCEPT"
+ "-p tcp --dport 22 -j REDIRECT --to-ports 0"
+ "-p tcp --dport 11423 -j REDIRECT --to-ports 22"
+ ];
+ })
+
+ ({ config, ... }: {
+ krebs.build.host = config.krebs.hosts.ne;
+ })
+
+ ({ pkgs, ... }: {
+ boot.kernelPackages = pkgs.linuxPackages_latest;
+ })
+
+ {
+ networking.useNetworkd = true;
+ }
+
+ # 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
+ ];
+ 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;
+ '';
+ };
+ })
+ ];
+}