forked from
lass.pds.lassul.us/superconfig
This repository has no description
2.7 kB
92 lines
1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 domains = [
9 "hackerfleet.eu"
10 "hackerfleet.de"
11 ];
12in
13{
14 containers.riot = {
15 config = {
16 environment.systemPackages = [
17 pkgs.git
18 pkgs.jq
19 ];
20 services.openssh.enable = true;
21 users.users.root.openssh.authorizedKeys.keys = [
22 "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6o6sdTu/CX1LW2Ff5bNDqGEAGwAsjf0iIe5DCdC7YikCct+7x4LTXxY+nDlPMeGcOF88X9/qFwdyh+9E4g0nUAZaeL14Uc14QDqDt/aiKjIXXTepxE/i4JD9YbTqStAnA/HYAExU15yqgUdj2dnHu7OZcGxk0ZR1OY18yclXq7Rq0Fd3pN3lPP1T4QHM9w66r83yJdFV9szvu5ral3/QuxQnCNohTkR6LoJ4Ny2RbMPTRtb+jPbTQYTWUWwV69mB8ot5nRTP4MRM9pu7vnoPF4I2S5DvSnx4C5zdKzsb7zmIvD4AmptZLrXj4UXUf00Xf7Js5W100Ne2yhYyhq+35 riot@lagrange"
23 ];
24 networking.defaultGateway = "10.233.1.1";
25 systemd.services.autoswitch = {
26 environment = {
27 NIX_REMOTE = "daemon";
28 };
29 wantedBy = [ "multi-user.target" ];
30 serviceConfig.ExecStart = pkgs.writers.writeDash "autoswitch" ''
31 set -efu
32 if test -e /etc/nixos/configuration.nix; then
33 /run/current-system/sw/bin/nixos-rebuild switch \
34 -I nixpkgs=channel:$(cat /etc/nixos/channel) \
35 -I nixos-config=/etc/nixos/configuration.nix \
36 || :
37 fi
38 '';
39 unitConfig.X-StopOnRemoval = false;
40 };
41 system.stateVersion = config.system.nixos.release;
42 };
43 autoStart = true;
44 enableTun = true;
45 privateNetwork = true;
46 hostAddress = "10.233.1.1";
47 localAddress = "10.233.1.2";
48 };
49 systemd.services."container@riot".restartIfChanged = lib.mkForce false;
50
51 systemd.network.networks."50-ve-riot" = {
52 matchConfig.Name = "ve-riot";
53
54 networkConfig = {
55 # weirdly we have to use POSTROUTING MASQUERADE here
56 # and set ip_forward manually
57 # IPForward = "yes";
58 # IPMasquerade = "both";
59 LinkLocalAddressing = "no";
60 KeepConfiguration = "static";
61 };
62 };
63
64 boot.kernel.sysctl."net.ipv4.ip_forward" = lib.mkDefault 1;
65
66 networking.firewall.extraForwardRules = ''
67 iifname "ve-riot" accept
68 oifname "ve-riot" accept
69 '';
70 # ssh into the container on 45622
71 networking.nftables.tables.riot = {
72 family = "ip";
73 content = ''
74 chain prerouting {
75 type nat hook prerouting priority dstnat; policy accept;
76 tcp dport 45622 dnat to ${config.containers.riot.localAddress}:22
77 }
78 chain postrouting {
79 type nat hook postrouting priority srcnat; policy accept;
80 ip saddr ${config.containers.riot.localAddress} masquerade
81 }
82 '';
83 };
84
85 # non container stuff
86
87 services.nginx.virtualHosts.riot = {
88 serverName = null;
89 serverAliases = domains;
90 };
91
92}