summaryrefslogtreecommitdiff
path: root/hosts
diff options
context:
space:
mode:
Diffstat (limited to 'hosts')
-rw-r--r--hosts/skadhi/default.nix45
-rw-r--r--hosts/skadhi/fs.nix82
-rw-r--r--hosts/skadhi/hw.nix65
-rw-r--r--hosts/skadhi/networking/default.nix30
-rw-r--r--hosts/skadhi/networking/ruleset.nft223
5 files changed, 360 insertions, 85 deletions
diff --git a/hosts/skadhi/default.nix b/hosts/skadhi/default.nix
index 66aa58d7..1f3f5306 100644
--- a/hosts/skadhi/default.nix
+++ b/hosts/skadhi/default.nix
@@ -1,36 +1,24 @@
1{ flake, flakeInputs, pkgs, config, lib, ... }: 1{ flake, flakeInputs, pkgs, config, lib, ... }:
2{ 2{
3 imports = with flake.nixosModules.systemProfiles; [ 3 imports = with flake.nixosModules.systemProfiles; [
4 ./hw.nix 4 ./hw.nix ./fs.nix ./networking
5 tmpfs-root default-locale openssh niri-unstable networkmanager lanzaboote zswap 5 tmpfs-root default-locale openssh lanzaboote zswap initrd-all-crypto-modules
6 flakeInputs.nixVirt.nixosModules.default
7 ]; 6 ];
8 7
9 config = { 8 config = {
10 system.stateVersion = "26.05"; 9 system.stateVersion = "26.05";
11 10
12 fileSystems."/persistent".neededForBoot = true;
13 environment.persistence."/persistent" = {
14 hideMounts = true;
15 directories = [
16 "/nix"
17 "/root"
18 "/var/log"
19 "/var/lib/nixos"
20 "/var/lib/sops-nix"
21 "/var/lib/systemd"
22 config.boot.lanzaboote.pkiBundle
23 ];
24 timezone = true;
25 };
26
27 boot = { 11 boot = {
28 initrd.systemd = { 12 initrd = {
29 emergencyAccess = config.users.users.root.hashedPassword; 13 systemd = {
30 extraBin = { 14 emergencyAccess = config.users.users.root.hashedPassword;
31 "vim" = lib.getExe pkgs.vim; 15 extraBin = {
32 "grep" = lib.getExe pkgs.gnugrep; 16 "vim" = lib.getExe pkgs.vim;
17 "grep" = lib.getExe pkgs.gnugrep;
18 };
33 }; 19 };
20
21 kernelModules = [ "dm-integrity" ];
34 }; 22 };
35 23
36 lanzaboote.configurationLimit = 15; 24 lanzaboote.configurationLimit = 15;
@@ -83,5 +71,16 @@
83 }; 71 };
84 72
85 services.userborn.importLegacyState = false; 73 services.userborn.importLegacyState = false;
74
75 services.kmscon = {
76 enable = true;
77 config.hwaccel = true;
78 };
79
80 environment.persistence."/persistent".timezone = true;
81 time.timeZone = null;
82 systemd.tmpfiles.settings = {
83 "10-localtime"."/etc/localtime".L.argument = "/persistent/etc/localtime";
84 };
86 }; 85 };
87} 86}
diff --git a/hosts/skadhi/fs.nix b/hosts/skadhi/fs.nix
new file mode 100644
index 00000000..64d49f7d
--- /dev/null
+++ b/hosts/skadhi/fs.nix
@@ -0,0 +1,82 @@
1{ flake, flakeInputs, pkgs, config, lib, ... }:
2{
3 imports = with flake.nixosModules.systemProfiles; [
4 disko
5 ];
6
7 config = {
8 fileSystems."/persistent".neededForBoot = true;
9 environment.persistence."/persistent" = {
10 hideMounts = true;
11 directories = [
12 "/nix"
13 "/root"
14 "/var/log"
15 "/var/lib/nixos"
16 "/var/lib/sops-nix"
17 "/var/lib/systemd"
18 config.boot.lanzaboote.pkiBundle
19 ];
20 };
21
22 disko.devices = {
23 disk.nvm = {
24 type = "disk";
25 device = "/dev/nvme0n1";
26 content = {
27 type = "gpt";
28 partitions = {
29 ESP = {
30 size = "512M";
31 type = "EF00";
32 content = {
33 type = "filesystem";
34 format = "vfat";
35 mountpoint = "/boot";
36 mountOptions = [
37 "fmask=0033" "dmask=0022"
38 ];
39 };
40 };
41 luks = {
42 size = "100%";
43 content = {
44 type = "luks";
45 name = "nvm";
46 extraFormatArgs = [
47 "--cipher" "aegis128-random"
48 "--key-size" "128"
49 "--integrity" "aead"
50 ];
51 content = {
52 type = "btrfs";
53 extraArgs = let
54 dirs = map (p: "/persistent/${p}") ["/etc"];
55 subvols = ["/persistent"] ++ map (p: "/persistent/${p}") ["/nix" "/var/log"];
56 restricted = map (p: "/persistent/${p}") ["/root"];
57 in [
58 "--csum" "blake2"
59 "--compress" "zstd:15"
60 "--rootdir" (toString (pkgs.runCommand "rootdir" {
61 } ''
62 mkdir $out
63 install -d ${lib.concatMapStringsSep " " (p: "$out/${p}") (dirs ++ subvols)}
64 install -m 0700 -d ${lib.concatMapStringsSep " " (p: "$out/${p}") restricted}
65 ''))
66 ] ++ lib.concatMap (p: ["--subvol" p]) (subvols ++ restricted);
67 subvolumes = {
68 "/persistent".mountpoint = "/persistent";
69 "/swap" = {
70 mountpoint = "/.swap";
71 swap.swapfile.size = "96G";
72 };
73 };
74 };
75 };
76 };
77 };
78 };
79 };
80 };
81 };
82}
diff --git a/hosts/skadhi/hw.nix b/hosts/skadhi/hw.nix
index 0eb16b7a..ad353208 100644
--- a/hosts/skadhi/hw.nix
+++ b/hosts/skadhi/hw.nix
@@ -1,79 +1,20 @@
1{ flake, flakeInputs, pkgs, config, lib, ... }: 1{ flake, flakeInputs, pkgs, config, lib, ... }:
2{ 2{
3 imports = with flake.nixosModules.systemProfiles; [ 3 imports = [
4 flakeInputs.nixos-hardware.nixosModules.framework-13-7040-amd 4 flakeInputs.nixos-hardware.nixosModules.framework-13-7040-amd
5 disko
6 ]; 5 ];
7 6
8 config = { 7 config = {
9 hardware.framework.laptop13.audioEnhancement.enable = true; 8 hardware.framework.laptop13.audioEnhancement.enable = true;
9 hardware.enableRedistributableFirmware = true;
10 services.fstrim.enable = false; 10 services.fstrim.enable = false;
11 11
12 services.udev.extraRules = '' 12 services.udev.extraRules = ''
13 ACTION=="add", SUBSYSTEM=="acpi", DRIVERS=="button", ATTRS{hid}=="PNP0C0D", ATTR{power/wakeup}="disabled" 13 ACTION=="add", SUBSYSTEM=="platform", DRIVER=="acpi-button", KERNEL=="PNP0C0D:00", ATTR{power/wakeup}="disabled"
14 ACTION=="add", SUBSYSTEM=="serio", DRIVERS=="atkbd", ATTR{power/wakeup}="disabled" 14 ACTION=="add", SUBSYSTEM=="serio", DRIVERS=="atkbd", ATTR{power/wakeup}="disabled"
15 ACTION=="add", SUBSYSTEM=="i2c", DRIVERS=="i2c_hid_acpi", ATTRS{name}=="PIXA3854:00", ATTR{power/wakeup}="disabled" 15 ACTION=="add", SUBSYSTEM=="i2c", DRIVERS=="i2c_hid_acpi", ATTRS{name}=="PIXA3854:00", ATTR{power/wakeup}="disabled"
16 ''; 16 '';
17 17
18 nixpkgs.system = "x86_64-linux"; 18 nixpkgs.system = "x86_64-linux";
19
20 disko.devices = {
21 disk.nvm = {
22 type = "disk";
23 device = "/dev/nvme0n1";
24 content = {
25 type = "gpt";
26 partitions = {
27 ESP = {
28 size = "512M";
29 type = "EF00";
30 content = {
31 type = "filesystem";
32 format = "vfat";
33 mountpoint = "/boot";
34 mountOptions = [
35 "fmask=0033" "dmask=0022"
36 ];
37 };
38 };
39 luks = {
40 size = "100%";
41 content = {
42 type = "luks";
43 name = "nvm";
44 extraFormatArgs = [
45 "--cipher" "aegis128-random"
46 "--key-size" "128"
47 "--integrity" "aead"
48 ];
49 content = {
50 type = "btrfs";
51 extraArgs = let
52 subvols = ["/persistent"] ++ map (p: "/persistent/${p}") ["/nix" "/var/log"];
53 restricted = map (p: "/persistent/${p}") ["/root"];
54 in [
55 "--csum" "blake2"
56 "--compress" "zstd:15"
57 "--rootdir" (toString (pkgs.runCommand "rootdir" {
58 } ''
59 mkdir $out
60 install -d ${lib.concatMapStringsSep " " (p: "$out/${p}") subvols}
61 install -m 0700 -d ${lib.concatMapStringsSep " " (p: "$out/${p}") restricted}
62 ''))
63 ] ++ lib.concatMap (p: ["--subvol" p]) subvols;
64 subvolumes = {
65 "/persistent".mountpoint = "/persistent";
66 "/swap" = {
67 mountpoint = "/.swap";
68 swap.swapfile.size = "96G";
69 };
70 };
71 };
72 };
73 };
74 };
75 };
76 };
77 };
78 }; 19 };
79} 20}
diff --git a/hosts/skadhi/networking/default.nix b/hosts/skadhi/networking/default.nix
new file mode 100644
index 00000000..ea5a62e2
--- /dev/null
+++ b/hosts/skadhi/networking/default.nix
@@ -0,0 +1,30 @@
1{ flake, config, ... }:
2{
3 imports = with flake.nixosModules.systemProfiles; [
4 networkmanager
5 ];
6
7 config = {
8 environment.persistence."/persistent".directories = [
9 "/etc/NetworkManager/system-connections"
10 ];
11
12 networking = {
13 domain = "yggdrasil";
14 search = [ "yggdrasil" ];
15 hosts = {
16 "127.0.0.1" = [ "${config.networking.hostName}.yggdrasil" config.networking.hostName ];
17 "::1" = [ "${config.networking.hostName}.yggdrasil" config.networking.hostName ];
18 };
19
20 firewall.enable = false;
21 nftables = {
22 enable = true;
23 rulesetFile = ./ruleset.nft;
24 };
25
26 useDHCP = false;
27 useNetworkd = true;
28 };
29 };
30}
diff --git a/hosts/skadhi/networking/ruleset.nft b/hosts/skadhi/networking/ruleset.nft
new file mode 100644
index 00000000..62339f69
--- /dev/null
+++ b/hosts/skadhi/networking/ruleset.nft
@@ -0,0 +1,223 @@
1define icmp_protos = { ipv6-icmp, icmp, igmp }
2
3table arp filter {
4 limit lim_arp {
5 rate over 50 mbytes/second burst 50 mbytes
6 }
7
8 counter arp-rx {}
9 counter arp-tx {}
10
11 counter arp-ratelimit-rx {}
12 counter arp-ratelimit-tx {}
13
14 chain input {
15 type filter hook input priority filter
16 policy accept
17
18 limit name lim_arp counter name arp-ratelimit-rx drop
19
20 counter name arp-rx
21 }
22
23 chain output {
24 type filter hook output priority filter
25 policy accept
26
27 limit name lim_arp counter name arp-ratelimit-tx drop
28
29 counter name arp-tx
30 }
31}
32
33table inet filter {
34 limit lim_reject {
35 rate over 1000/second burst 1000 packets
36 }
37
38 limit lim_icmp {
39 rate over 50 mbytes/second burst 50 mbytes
40 }
41
42 counter invalid-fw {}
43
44 counter fw-lo {}
45
46 counter reject-ratelimit-fw {}
47 counter reject-fw {}
48 counter reject-tcp-fw {}
49 counter reject-icmp-fw {}
50
51
52 counter invalid-rx {}
53 counter rx-lo {}
54 counter invalid-local4-rx {}
55 counter invalid-local6-rx {}
56
57 counter icmp-ratelimit-rx {}
58 counter icmp-rx {}
59
60 counter ssh-rx {}
61 counter mosh-rx {}
62 counter wg-rx {}
63 counter yggdrasil-gre-rx {}
64 counter miniserve-rx {}
65 counter ausweisapp2-rx {}
66
67 counter established-rx {}
68
69 counter reject-ratelimit-rx {}
70 counter reject-rx {}
71 counter reject-tcp-rx {}
72 counter reject-icmp-rx {}
73
74
75 counter tx-lo {}
76
77 counter icmp-ratelimit-tx {}
78 counter icmp-tx {}
79
80 counter ssh-tx {}
81 counter mosh-tx {}
82 counter wg-tx {}
83 counter yggdrasil-gre-tx {}
84 counter miniserve-tx {}
85
86 counter tx {}
87
88 counter fw-libvirt {}
89 counter libvirt-dhcp {}
90 counter libvirt-dns {}
91
92
93 chain forward_tmp {}
94 chain forward {
95 type filter hook forward priority filter
96 policy drop
97
98
99 ct state invalid log level debug prefix "drop invalid forward: " counter name invalid-fw drop
100
101
102 iifname lo counter name fw-lo accept
103
104 jump forward_tmp
105
106 iifname virbr0 oifname != {lo, wgrz, yggdrasil-wg-4, yggdrasil-wg-6, yggdrasil, ip6tnl, ip6gre, yggre-surtr-6, yggre-surtr-4, yggre-vidhar-4} counter name fw-libvirt accept
107 oifname virbr0 ct state {established, related} counter name fw-libvirt accept
108
109
110 limit name lim_reject log level debug prefix "drop forward: " counter name reject-ratelimit-fw drop
111 log level debug prefix "reject forward: " counter name reject-fw
112 meta l4proto tcp ct state new counter name reject-tcp-fw reject with tcp reset
113 ct state new counter name reject-icmp-fw reject
114 }
115
116 chain input_tmp {}
117 chain input {
118 type filter hook input priority filter
119 policy drop
120
121
122 ct state invalid log level debug prefix "drop invalid input: " counter name invalid-rx drop
123
124
125 iifname lo counter name rx-lo accept
126 iif != lo ip daddr 127.0.0.1/8 counter name invalid-local4-rx reject
127 iif != lo ip6 daddr ::1/128 counter name invalid-local6-rx reject
128
129 meta l4proto $icmp_protos limit name lim_icmp counter name icmp-ratelimit-rx drop
130 meta l4proto $icmp_protos counter name icmp-rx accept
131
132 jump input_tmp
133
134 tcp dport 22 counter name ssh-rx accept
135 udp dport 60000-61000 counter name mosh-rx accept
136
137 tcp dport 8080 counter name miniserve-rx accept
138 udp dport 24727 counter name ausweisapp2-rx accept
139
140 udp dport 51820-51822 counter name wg-rx accept
141 iifname "yggdrasil-wg-*" meta l4proto gre counter name yggdrasil-gre-rx accept
142
143 iifname virbr0 udp dport 67 counter name libvirt-dhcp accept
144 iifname virbr0 udp dport 547 counter name libvirt-dhcp accept
145 iifname virbr0 udp dport 53 counter name libvirt-dns accept
146 iifname virbr0 tcp dport 53 counter name libvirt-dns accept
147
148 iifname wgrz ip saddr 10.200.116.1 meta l4proto gre counter accept
149
150 ct state {established, related} counter name established-rx accept
151
152
153 limit name lim_reject log level debug prefix "drop input: " counter name reject-ratelimit-rx drop
154 log level debug prefix "reject input: " counter name reject-rx
155 meta l4proto tcp ct state new counter name reject-tcp-rx reject with tcp reset
156 ct state new counter name reject-icmp-rx reject
157 }
158
159 chain output {
160 type filter hook output priority filter
161 policy accept
162
163
164 oifname lo counter name tx-lo accept
165
166 meta l4proto $icmp_protos limit name lim_icmp counter name icmp-ratelimit-tx drop
167 meta l4proto $icmp_protos counter name icmp-tx accept
168
169
170 tcp sport 22 counter name ssh-tx
171 udp sport 60000-61000 counter name mosh-tx
172
173 udp sport 51820-51822 counter name wg-tx
174 iifname "yggdrasil-wg-*" meta l4proto gre counter name yggdrasil-gre-tx
175
176 tcp sport 8080 counter name miniserve-tx accept
177
178 oifname virbr0 udp sport 67 counter name libvirt-dhcp accept
179 oifname virbr0 udp sport 547 counter name libvirt-dhcp accept
180 oifname virbr0 udp sport 53 counter name libvirt-dns accept
181 oifname virbr0 tcp sport 53 counter name libvirt-dns accept
182
183
184 counter name tx
185 }
186}
187
188table ip nat {
189 counter libvirt-nat {}
190
191 chain postrouting_tmp {}
192 chain postrouting {
193 type nat hook postrouting priority srcnat
194 policy accept
195
196 iifname virbr0 oifname != virbr0 counter name libvirt-nat masquerade
197 jump postrouting_tmp
198 }
199}
200
201table ip6 nat {
202 counter libvirt-nat {}
203
204 chain postrouting {
205 type nat hook postrouting priority srcnat
206 policy accept
207
208 iifname virbr0 oifname != virbr0 counter name libvirt-nat masquerade
209 }
210}
211
212table ip mss_clamp {
213 counter libvirt-mss-clamp {}
214
215 chain postrouting_tmp {}
216 chain postrouting {
217 type filter hook postrouting priority mangle
218 policy accept
219
220 iifname virbr0 oifname != virbr0 tcp flags & (syn|rst) == syn counter name libvirt-mss-clamp tcp option maxseg size set rt mtu
221 jump postrouting_tmp
222 }
223}