summaryrefslogtreecommitdiffstats
path: root/lass/2configs/riot.nix
blob: 37a6298ca0b1b4f103ae3b6bf486c8afddf8aeb0 (plain)
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
{ config, lib, pkgs, ... }:
{
  containers.riot = {
    config = {
      environment.systemPackages = [
        pkgs.dhcpcd
        pkgs.git
        pkgs.jq
      ];
      networking.useDHCP = lib.mkForce true;
      networking.firewall.enable = false;
      systemd.services.autoswitch = {
        environment = {
          NIX_REMOTE = "daemon";
        };
        wantedBy = [ "multi-user.target" ];
        serviceConfig.ExecStart = pkgs.writers.writeDash "autoswitch" ''
          set -efu
          if test -e /var/src/nixos-config; then
            /run/current-system/sw/bin/nixos-rebuild -I /var/src switch || :
          fi
        '';
        unitConfig.X-StopOnRemoval = false;
      };
    };
    autoStart = true;
    enableTun = true;
    privateNetwork = true;
    hostAddress = "10.233.1.1";
    localAddress = "10.233.1.2";
    forwardPorts = [
      { hostPort = 45622; containerPort = 22; }
    ];
  };

  systemd.network.networks."50-ve-riot" = {
    matchConfig.Name = "ve-riot";

    networkConfig = {
      IPForward = "yes";
      # weirdly we have to use POSTROUTING MASQUERADE here
      # IPMasquerade = "both";
      LinkLocalAddressing = "no";
      KeepConfiguration = "static";
    };
  };

  # networking.nat can be used instead of this
  krebs.iptables.tables.nat.POSTROUTING.rules = [
    { v6 = false; predicate = "-s ${config.containers.riot.localAddress}"; target = "MASQUERADE"; }
  ];
  krebs.iptables.tables.filter.FORWARD.rules = [
    { predicate = "-i ve-riot"; target = "ACCEPT"; }
    { predicate = "-o ve-riot"; target = "ACCEPT"; }
  ];
}