ctucx.git: nixfiles

ctucx' nixfiles

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 
{ nodes, config, lib, pkgs, ... }:

{

  deployment.buildOnTarget = false;

  #this enables the following services: dns
  deployment.tags          = [ "dnsServer" ];

  documentation.nixos.enable = false;

  imports = [
    ./hardware-configuration.nix

    ./rclone-restic-server.nix

    ./3proxy.nix

    ./websites
  ] ++ (if nodes.briefkasten.config.networking.usePBBUplink != true then [
    ./reverse-proxy-briefkasten.nix
  ] else [ ]);

  dns.zones."ctu.cx".subdomains."${config.networking.hostName}" = (pkgs.dns.lib.combinators.host config.networking.primaryIP4 config.networking.primaryIP);

  age.secrets.wireguard-privkey.file = ../../secrets/wanderduene/wireguard-privkey.age;

  boot = {
    # Use the systemd-boot EFI boot loader.
    loader.systemd-boot.enable = true;
    loader.efi.canTouchEfiVariables = true;

    initrd.network = {
      enable = true;
      ssh    = {
        enable         = true;
        port           = 22;
        hostKeys       = [ /etc/ssh/ssh_host_rsa_key ];
        authorizedKeys = with lib; concatLists (mapAttrsToList (name: user: if elem "wheel" user.extraGroups then user.openssh.authorizedKeys.keys else []) config.users.users);
      };

      postCommands = ''
        ip link set dev ens3 up
        ip addr add ${config.networking.primaryIP}/128 dev ens3
        ip route add default via fe80::1 dev ens3 onlink

        ip addr add ${config.networking.primaryIP4}/22 dev ens3
        ip route add default via ${config.networking.defaultGateway.address} dev ens3 onlink
        echo 'cryptsetup-askpass' >> /root/.profile
      '';
    };
  };

  networking = {
    primaryIP    = "2a03:4000:4d:5e::1";
    primaryIP4   = "194.36.145.49";

    resolvconf.enable = false;
    nameservers       = [ "8.8.8.8" "1.1.1.1" ];

    defaultGateway  = {
      interface = "ens3";
      address   = "194.36.144.1";
    };
    defaultGateway6 = {
      interface = "ens3";
      address   = "fe80::1";
    };

    interfaces.ens3 = {
      ipv4.addresses = [{
        address = config.networking.primaryIP4;
        prefixLength = 24;
      }];

      ipv6.addresses = [{
        address      = config.networking.primaryIP;
        prefixLength = 64;
      }];
    };

    wireguard = {
      enable = true;

      interfaces.wg-mikrotik = {
        listenPort             = 51820;
        privateKeyFile         = config.age.secrets.wireguard-privkey.path;
        generatePrivateKeyFile = true;
        postSetup              = "ip link set dev wg-mikrotik mtu 1500";
        ips                    = [ "172.16.0.1/24" ];

        peers = [
          {
            persistentKeepalive = 10;
            allowedIPs          = [ "172.16.0.0/24" "10.0.0.0/8" ];
            publicKey           = "nvyhYuWJl/dKyV/2+bDrUisvL3mi38PsNzfdIDDwSjY=";
          }
        ];
      };

      interfaces.wg-briefkasten = {
        listenPort             = 51821;
        privateKeyFile         = config.age.secrets.wireguard-privkey.path;
        generatePrivateKeyFile = true;
        postSetup              = "ip link set dev wg-briefkasten mtu 1500";
        ips                    = [ "172.17.0.1/24" ];

        peers = [
          {
            persistentKeepalive = 10;
            allowedIPs          = [ "172.17.0.0/24" ];
            publicKey           = "nvyhYuWJl/dKyV/2+bDrUisvL3mi38PsNzfdIDDwSjY=";
          }
        ];
      };

      interfaces.wg-stasicont = {
        listenPort             = 51822;
        privateKeyFile         = config.age.secrets.wireguard-privkey.path;
        generatePrivateKeyFile = true;
        postSetup              = "ip link set dev wg-stasicont mtu 1500";
        ips                    = [ "172.18.0.1/24" ];

        peers = [
          {
            persistentKeepalive = 10;
            allowedIPs          = [ "172.18.0.0/24" ];
            publicKey           = "Sh5le4IsR5jW1+jSrR5N/dcuTE+OEcEB6ou7bqwriAg=";
          }
        ];
      };

    };

    firewall.allowedTCPPorts = [ 5201 2201 2202 2203 ];
    firewall.allowedUDPPorts = [ 5201 51820 51821 51822 ];
    firewall.extraCommands = ''
      iptables  -A nixos-fw -i wg-mikrotik   -j nixos-fw-accept
      iptables  -A nixos-fw -i wg-briefkasten -j nixos-fw-accept
      iptables  -A nixos-fw -i wg-stasicont   -j nixos-fw-accept
    '';
  };

  ctucxConfig.programs = {
    gpg.enable    = false;
    ssh.enable    = false;
    git.enable    = false;
  };

  services.iperf3 = {
    enable = true;
    bind   = "172.17.0.1";
  };

  system.stateVersion = "23.05";
  home-manager.users.leah.home.stateVersion = "23.05";

}