1 { pkgs, lib, config, inputs, hostName, ... }:
 
   3   domain = "sourcephile.fr";
 
   4   port = toString config.services.nebula.networks.${domain}.listen.port;
 
   5   iface = config.services.nebula.networks.${domain}.tun.device;
 
   9   environment.systemPackages = with pkgs; [ nebula ];
 
  10   systemd.services."nebula@${domain}" = {
 
  11     reloadIfChanged = false;
 
  12     stopIfChanged = false;
 
  13     serviceConfig.LoadCredentialEncrypted = [
 
  14       "${hostName}.key:${builtins.path { path = inputs.self + "/hosts/${hostName}/nebula/${domain}/${hostName}.key.cred"; }}"
 
  17   install.target = lib.mkDefault "\"\${NIXOS_TARGET:-root@${config.networking.hostName}.sp}\"";
 
  19     "${IPv4Prefix}.1" = [ "mermet.sp" ];
 
  20     "${IPv4Prefix}.2" = [ "losurdo.sp" ];
 
  21     "${IPv4Prefix}.3" = [ "oignon.sp" ];
 
  22     "${IPv4Prefix}.4" = [ "patate.sp" ];
 
  23     "${IPv4Prefix}.5" = [ "carotte.sp" ];
 
  24     "${IPv4Prefix}.6" = [ "aubergine.sp" ];
 
  25     "${IPv4Prefix}.7" = [ "courge.sp" ];
 
  26     "${IPv4Prefix}.8" = [ "blackberry.sp" ];
 
  27     "${IPv4Prefix}.9" = [ "pumpkin.sp" ];
 
  29   services.nebula.networks.${domain} = {
 
  31     ca = lib.mkDefault (builtins.path { path = inputs.self + "/domains/${domain}/nebula/ca.crt"; });
 
  32     cert = lib.mkDefault (builtins.path { path = inputs.self + "/hosts/${hostName}/nebula/${domain}/${hostName}.crt"; });
 
  33     key = "/run/credentials/nebula@${domain}.service/${hostName}.key";
 
  34     listen.host = lib.mkDefault "0.0.0.0";
 
  35     tun.device = lib.mkDefault "neb-sourcephile";
 
  37       "${IPv4Prefix}.1" = [ "mermet.${domain}:10001" ];
 
  38       "${IPv4Prefix}.2" = [ "losurdo.${domain}:10002" ];
 
  49         { port = "any"; proto = "icmp"; groups = [ "sourcephile" "intra" ]; }
 
  52         { port = "any"; proto = "icmp"; groups = [ "sourcephile" "intra" ]; }
 
  60           default_timeout = "10m";
 
  64         level = lib.mkDefault "info";
 
  66       pki.disconnect_invalid = true;
 
  70       #cipher = "chachapoly";
 
  74         listen = "127.0.0.1:8080";
 
  76         namespace = "prometheusns";
 
  79         message_metrics = false;
 
  80         lighthouse_metrics = false;
 
  85   networking.nftables.ruleset = ''
 
  88         udp dport ${port} counter accept comment "Nebula ${domain}"
 
  91         udp sport ${port} counter accept comment "Nebula ${domain}"
 
  94         udp dport ${port} counter accept comment "Nebula ${domain}"
 
  97         udp sport ${port} counter accept comment "Nebula ${domain}"
 
  99       chain input-${iface} {
 
 100         tcp dport ssh counter accept comment "SSH"
 
 101         udp dport 60000-60100 counter accept comment "Mosh"
 
 103       chain output-${iface} {
 
 104         tcp dport ssh counter accept comment "SSH"
 
 105         udp dport 60000-60100 counter accept comment "Mosh"
 
 108         iifname ${iface} jump input-${iface} comment "MUST be before the address-based jumps to input-lan"
 
 109         iifname ${iface} log level warn prefix "input-${iface}: " counter drop
 
 112         oifname ${iface} jump output-${iface}
 
 113         oifname ${iface} log level warn prefix "output-${iface}: " counter drop
 
 116   '' + lib.optionalString config.services.printing.enable ''
 
 118       chain output-${iface} {
 
 119         tcp dport { ipp, ipps } counter accept comment "printing: IPP"
 
 122   '' + lib.optionalString config.hardware.sane.enable ''
 
 124       chain output-${iface} {
 
 125         tcp dport sane-port counter accept comment "sane-net: SANE"
 
 129   networking.networkmanager.unmanaged = [ iface ];
 
 130   services.fail2ban.ignoreIP = [
 
 131     "${IPv4Prefix}.1" # mermet.sp
 
 132     "${IPv4Prefix}.2" # losurdo.sp
 
 133     "${IPv4Prefix}.3" # oignon.sp
 
 134     "${IPv4Prefix}.9" # pumpkin.sp