diff options
Diffstat (limited to 'hosts')
| -rw-r--r-- | hosts/skadhi/default.nix | 11 | ||||
| -rw-r--r-- | hosts/skadhi/fs.nix | 6 | ||||
| -rw-r--r-- | hosts/skadhi/hw.nix | 6 | ||||
| -rw-r--r-- | hosts/skadhi/networking/default.nix | 30 | ||||
| -rw-r--r-- | hosts/skadhi/networking/ruleset.nft | 223 |
5 files changed, 267 insertions, 9 deletions
diff --git a/hosts/skadhi/default.nix b/hosts/skadhi/default.nix index 96be2e5b..1f3f5306 100644 --- a/hosts/skadhi/default.nix +++ b/hosts/skadhi/default.nix | |||
| @@ -1,9 +1,8 @@ | |||
| 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 ./fs.nix | 4 | ./hw.nix ./fs.nix ./networking |
| 5 | tmpfs-root default-locale openssh niri-unstable networkmanager lanzaboote zswap initrd-all-crypto-modules | 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 = { |
| @@ -77,5 +76,11 @@ | |||
| 77 | enable = true; | 76 | enable = true; |
| 78 | config.hwaccel = true; | 77 | config.hwaccel = true; |
| 79 | }; | 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 | }; | ||
| 80 | }; | 85 | }; |
| 81 | } | 86 | } |
diff --git a/hosts/skadhi/fs.nix b/hosts/skadhi/fs.nix index cbeef6f9..64d49f7d 100644 --- a/hosts/skadhi/fs.nix +++ b/hosts/skadhi/fs.nix | |||
| @@ -17,7 +17,6 @@ | |||
| 17 | "/var/lib/systemd" | 17 | "/var/lib/systemd" |
| 18 | config.boot.lanzaboote.pkiBundle | 18 | config.boot.lanzaboote.pkiBundle |
| 19 | ]; | 19 | ]; |
| 20 | timezone = true; | ||
| 21 | }; | 20 | }; |
| 22 | 21 | ||
| 23 | disko.devices = { | 22 | disko.devices = { |
| @@ -52,6 +51,7 @@ | |||
| 52 | content = { | 51 | content = { |
| 53 | type = "btrfs"; | 52 | type = "btrfs"; |
| 54 | extraArgs = let | 53 | extraArgs = let |
| 54 | dirs = map (p: "/persistent/${p}") ["/etc"]; | ||
| 55 | subvols = ["/persistent"] ++ map (p: "/persistent/${p}") ["/nix" "/var/log"]; | 55 | subvols = ["/persistent"] ++ map (p: "/persistent/${p}") ["/nix" "/var/log"]; |
| 56 | restricted = map (p: "/persistent/${p}") ["/root"]; | 56 | restricted = map (p: "/persistent/${p}") ["/root"]; |
| 57 | in [ | 57 | in [ |
| @@ -60,10 +60,10 @@ | |||
| 60 | "--rootdir" (toString (pkgs.runCommand "rootdir" { | 60 | "--rootdir" (toString (pkgs.runCommand "rootdir" { |
| 61 | } '' | 61 | } '' |
| 62 | mkdir $out | 62 | mkdir $out |
| 63 | install -d ${lib.concatMapStringsSep " " (p: "$out/${p}") subvols} | 63 | install -d ${lib.concatMapStringsSep " " (p: "$out/${p}") (dirs ++ subvols)} |
| 64 | install -m 0700 -d ${lib.concatMapStringsSep " " (p: "$out/${p}") restricted} | 64 | install -m 0700 -d ${lib.concatMapStringsSep " " (p: "$out/${p}") restricted} |
| 65 | '')) | 65 | '')) |
| 66 | ] ++ lib.concatMap (p: ["--subvol" p]) subvols; | 66 | ] ++ lib.concatMap (p: ["--subvol" p]) (subvols ++ restricted); |
| 67 | subvolumes = { | 67 | subvolumes = { |
| 68 | "/persistent".mountpoint = "/persistent"; | 68 | "/persistent".mountpoint = "/persistent"; |
| 69 | "/swap" = { | 69 | "/swap" = { |
diff --git a/hosts/skadhi/hw.nix b/hosts/skadhi/hw.nix index 02fb5c0e..ad353208 100644 --- a/hosts/skadhi/hw.nix +++ b/hosts/skadhi/hw.nix | |||
| @@ -1,16 +1,16 @@ | |||
| 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 | ''; |
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 @@ | |||
| 1 | define icmp_protos = { ipv6-icmp, icmp, igmp } | ||
| 2 | |||
| 3 | table 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 | |||
| 33 | table 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 | |||
| 188 | table 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 | |||
| 201 | table 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 | |||
| 212 | table 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 | } | ||
