diff options
| author | tv <tv@krebsco.de> | 2026-11-23 14:59:44 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-23 15:18:49 +0000 |
| commit | 91545e73f20e45a197fc4383f2a12d32ffe9c5b2 (patch) | |
| tree | b9118f05d77b45288e095f6d84f2706c3f4a3cb8 /systems/ne | |
| parent | efa35f0a45257f74335093d927de47b8fcf102ce (diff) | |
ne: init
Diffstat (limited to 'systems/ne')
| -rw-r--r-- | systems/ne/acme.nix | 39 | ||||
| -rw-r--r-- | systems/ne/base.nix | 68 | ||||
| -rw-r--r-- | systems/ne/config.nix | 231 | ||||
| -rw-r--r-- | systems/ne/spec.nix | 3 |
4 files changed, 341 insertions, 0 deletions
diff --git a/systems/ne/acme.nix b/systems/ne/acme.nix new file mode 100644 index 00000000..c54d487d --- /dev/null +++ b/systems/ne/acme.nix @@ -0,0 +1,39 @@ +{ config, pkgs, ... }: { + security.acme.acceptTerms = true; + + security.acme.certs."viljetic.de" = { + domain = "viljetic.de"; + extraDomainNames = [ + "*.viljetic.de" + ]; + email = "tomislav@viljetic.de"; + reloadServices = [ + "knsupdate-viljetic.de.service" + "nginx.service" + ]; + keyType = "ec384"; + dnsProvider = "rfc2136"; + environmentFile = + # format: + # RFC2136_NAMESERVER=ns1.viljetic.de + # RFC2136_TSIG_ALGORITHM=hmac-sha256. + # RFC2136_TSIG_KEY=acme + # RFC2136_TSIG_SECRET=<base64-encoded-secret> + "${config.krebs.secret.directory}/lego-knot-credentials"; + }; + + # This is an alternative to + # security.acme.certs."viljetic.de".group = "nginx"; + users.users.nginx.extraGroups = [ "acme" ]; + +/* +Aug 20 11:05:22 ni acme-viljetic.de-start[406499]: 2022/08/20 11:05:22 [INFO] acme: Registering account for tomislav@viljetic.de +Aug 20 11:05:22 ni acme-viljetic.de-start[406499]: !!!! HEADS UP !!!! +Aug 20 11:05:22 ni acme-viljetic.de-start[406499]: Your account credentials have been saved in your Let's Encrypt +Aug 20 11:05:22 ni acme-viljetic.de-start[406499]: configuration directory at "accounts". +Aug 20 11:05:22 ni acme-viljetic.de-start[406499]: You should make a secure backup of this folder now. This +Aug 20 11:05:22 ni acme-viljetic.de-start[406499]: configuration directory will also contain certificates and +Aug 20 11:05:22 ni acme-viljetic.de-start[406499]: private keys obtained from Let's Encrypt so making regular +Aug 20 11:05:22 ni acme-viljetic.de-start[406499]: backups of this folder is ideal. +*/ +} diff --git a/systems/ne/base.nix b/systems/ne/base.nix new file mode 100644 index 00000000..758dbf61 --- /dev/null +++ b/systems/ne/base.nix @@ -0,0 +1,68 @@ +{ config, lib, modulesPath, pkgs, ... }: { + imports = [ + (modulesPath + "/profiles/qemu-guest.nix") + ]; + + boot.initrd.availableKernelModules = [ + "ata_piix" "uhci_hcd" "virtio_pci" "sr_mod" "virtio_blk" + ]; + + boot.kernel.sysctl = { + "net.ipv6.conf.all.use_tempaddr" = 0; + }; + + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + environment.systemPackages = [ + pkgs.git + pkgs.rsync + ]; + + fileSystems = { + "/boot" = { + device = "/dev/vda1"; + fsType = "vfat"; + options = [ + "dmask=0077" + "fmask=0077" + "nodev" + "noexec" + "nosuid" + ]; + }; + "/" = { + device = "/dev/vda2"; + fsType = "btrfs"; + options = [ + "defaults" + "noatime" + "commit=120" # default: 30 [seconds] + "compress=zstd" # default: lzo + "ssd" # because /sys/block/vda/queue/rotational is 1... + ]; + }; + }; + + systemd.repart.enable = true; + systemd.repart.partitions."10-root".Type = "root"; + systemd.services.systemd-growfs-root.wantedBy = [ "multi-user.target" ]; + + documentation.info.enable = false; + documentation.man.enable = false; + documentation.nixos.enable = false; + + i18n.defaultLocale = "en_US.UTF-8"; + i18n.supportedLocales = [ "en_US.UTF-8/UTF-8" ]; + + services.ntp.enable = false; + services.openssh.enable = true; + services.udisks2.enable = false; + + users.mutableUsers = false; + users.users.root.openssh.authorizedKeys.keys = lib.mkDefault [ + config.krebs.users.tv.pubkey + ]; + + system.stateVersion = "25.05"; +} 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; + ''; + }; + }) + ]; +} diff --git a/systems/ne/spec.nix b/systems/ne/spec.nix new file mode 100644 index 00000000..efab0596 --- /dev/null +++ b/systems/ne/spec.nix @@ -0,0 +1,3 @@ +{ + system = "x86_64-linux"; +} |
