-
Notifications
You must be signed in to change notification settings - Fork 0
/
guests.nix
145 lines (139 loc) · 3.81 KB
/
guests.nix
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
{
config,
lib,
pkgs,
inputs,
...
}:
{
networking.nftables = {
stopRuleset = lib.mkDefault ''
table inet filter {
chain input {
type filter hook input priority filter; policy drop;
ct state invalid drop
ct state {established, related} accept
iifname lo accept
meta l4proto ipv6-icmp accept
meta l4proto icmp accept
tcp dport ${toString (lib.head config.services.openssh.ports)} accept
tcp dport 80 accept
tcp dport 443 accept
}
chain forward {
type filter hook forward priority filter; policy drop;
}
chain output {
type filter hook output priority filter; policy accept;
}
}
'';
firewall = {
enable = false;
localZoneName = "local";
snippets = {
nnf-common.enable = false;
nnf-conntrack.enable = true;
nnf-drop.enable = true;
nnf-loopback.enable = true;
nnf-ssh.enable = true;
nnf-icmp = {
enable = true;
ipv6Types = [
"echo-request"
"destination-unreachable"
"packet-too-big"
"time-exceeded"
"parameter-problem"
"nd-router-advert"
"nd-neighbor-solicit"
"nd-neighbor-advert"
];
ipv4Types = [
"echo-request"
"destination-unreachable"
"router-advertisement"
"time-exceeded"
"parameter-problem"
];
};
};
rules.lan-to-local = {
from = [ "lan" ];
to = [ "local" ];
inherit (config.networking.firewall)
allowedTCPPorts
allowedTCPPortRanges
allowedUDPPorts
allowedUDPPortRanges
;
};
# specific
zones = {
#untrusted.interfaces = [ ];
lan.interfaces = [
"brmgmt9"
"brprim4"
"brdata11"
];
};
};
};
modules.services.microvm = {
enable = true;
guests =
let
mkGuest =
guestName:
{
enableStorageDataset ? false,
...
}:
{
autostart = true;
# temporary state that is wiped on reboot
zfs."/state" = {
pool = "rpool";
dataset = "rpool/encrypted/vms/${guestName}";
};
# persistent state
zfs."/persist" = {
pool = "rpool";
dataset = "rpool/encrypted/safe/vms/${guestName}";
};
#zfs."/storage" = lib.mkIf enableStorageDataset {
# pool = "storage";
# dataset = "safe/guests/${guestName}";
#};
modules = [
./guests/${guestName}.nix
{
#node.secretsDir = ./secrets/${guestName};
networking.nftables.firewall = {
zones.untrusted.interfaces = [
config.modules.services.microvm.guests.${guestName}.networking.mainLinkName
];
};
}
];
networking = config.repo.secrets.home-ops.guests.${guestName}.networking;
};
mkMicrovm = guestName: opts: {
${guestName} = mkGuest guestName opts // {
microvm = {
system = "x86_64-linux";
macvtap = "brprim4";
baseMac = "1c:69:7a:00:00:00"; # TODO move to config
};
extraSpecialArgs = {
#inherit (inputs.self) nodes globals;
#inherit (inputs.self.pkgs.x86_64-linux) lib;
inherit lib;
inherit inputs;
};
};
};
in
({ } // mkMicrovm "hello-world" { enableStorageDataset = true; });
};
}