system.scm (14077B)
1 ;; T480, coreboot (libreboot-style 26.10). nvme0n1p1 esp, p2 luks2 argon2id 2 ;; -> ext4 labelled "xiii-root" (must match e2label). grub 2.14 unlocks luks2 argon2id; 3 ;; if it can't, convert the keyslot: cryptsetup luksConvertKey --pbkdf argon2id --pbkdf-memory 131072 4 ;; grub prompt is uk qwerty. 5 6 (use-modules (gnu) 7 (gnu services networking) 8 (gnu services desktop) 9 (gnu services dbus) 10 (gnu services sysctl) 11 (gnu services shepherd) 12 (gnu services ssh) 13 (gnu system privilege) 14 (gnu system setuid) 15 (guix packages) 16 (guix utils)) 17 18 (load "private.scm") 19 20 (use-package-modules admin base bash curl fonts linux pciutils ssh version-control) 21 22 ;; userns stay on, the unprivileged daemon needs them 23 (define %sysctl-hardening 24 '(("kernel.dmesg_restrict" . "1") 25 ("kernel.kptr_restrict" . "2") 26 ("kernel.yama.ptrace_scope" . "1") 27 ("kernel.kexec_load_disabled" . "1") 28 ("kernel.unprivileged_bpf_disabled" . "1") 29 ("net.core.bpf_jit_harden" . "2") 30 ("kernel.perf_event_paranoid" . "3") 31 ("kernel.io_uring_disabled" . "2") 32 ("kernel.sysrq" . "0") 33 ("dev.tty.ldisc_autoload" . "0") 34 ("fs.protected_fifos" . "2") 35 ("fs.protected_regular" . "2") 36 ("fs.protected_symlinks" . "1") 37 ("fs.protected_hardlinks" . "1") 38 ("fs.suid_dumpable" . "0") 39 ("net.core.rmem_max" . "16777216") 40 ("net.core.wmem_max" . "16777216") 41 ("net.core.rmem_default" . "1048576") 42 ("net.core.wmem_default" . "1048576") 43 ("net.ipv4.tcp_rmem" . "4096 131072 16777216") 44 ("net.ipv4.tcp_wmem" . "4096 65536 16777216") 45 ("net.ipv4.conf.all.rp_filter" . "2") ; loose, for mihomo tun 46 ("net.ipv4.conf.default.rp_filter" . "2") 47 ("net.ipv4.conf.all.accept_redirects" . "0") 48 ("net.ipv4.conf.default.accept_redirects" . "0") 49 ("net.ipv6.conf.all.accept_redirects" . "0") 50 ("net.ipv6.conf.default.accept_redirects" . "0") 51 ("net.ipv4.conf.all.send_redirects" . "0") 52 ("net.ipv4.conf.default.send_redirects" . "0") 53 ("net.ipv4.conf.all.accept_source_route" . "0") 54 ("net.ipv4.conf.default.accept_source_route" . "0") 55 ("net.ipv6.conf.all.accept_source_route" . "0") 56 ("net.ipv6.conf.default.accept_source_route" . "0") 57 ("net.ipv4.tcp_syncookies" . "1") 58 ("net.ipv4.icmp_echo_ignore_broadcasts" . "1"))) 59 60 (define %nftables-ruleset 61 (plain-file "nftables.conf" (string-append "\ 62 table inet filter { 63 chain input { 64 type filter hook input priority 0; policy drop; 65 ct state invalid drop 66 ct state { established, related } accept 67 iif lo accept 68 # Meta is mihomo's tun interface; its system stack hands connections back in here 69 iifname Meta accept 70 # yggdrasil: only the hark vps may reach sshd 71 iifname ygg0 ip6 saddr " %vps-ygg " tcp dport 2022 accept 72 iif != lo ip daddr 127.0.0.0/8 drop 73 iif != lo ip6 daddr ::1/128 drop 74 ip protocol icmp icmp type { destination-unreachable, time-exceeded, parameter-problem } accept 75 meta l4proto ipv6-icmp icmpv6 type { destination-unreachable, packet-too-big, time-exceeded, parameter-problem, mld-listener-query, nd-router-advert, nd-neighbor-solicit, nd-neighbor-advert } accept 76 } 77 chain forward { 78 type filter hook forward priority 0; policy drop; 79 } 80 chain output { 81 type filter hook output priority 0; policy accept; 82 } 83 } 84 "))) 85 86 (define %privileged-programs 87 (cons* (privileged-program 88 (program (file-append inetutils "/bin/ping")) 89 (capabilities "cap_net_raw=ep")) 90 (privileged-program 91 (program (file-append inetutils "/bin/ping6")) 92 (capabilities "cap_net_raw=ep")) 93 (map file-like->setuid-program 94 (list (file-append shadow "/bin/passwd") 95 (file-append shadow "/bin/newuidmap") 96 (file-append shadow "/bin/newgidmap") 97 (file-append (specification->package "opendoas") "/bin/doas") 98 (file-append fuse "/bin/fusermount3"))))) 99 100 ;; whonix machine-id, shared on purpose 101 (define %whonix-machine-id 102 (simple-service 'shared-machine-id activation-service-type 103 #~(call-with-output-file "/etc/machine-id" 104 (lambda (port) (display "b08dfa6083e7567a1921a715000001fb\n" port))))) 105 106 ;; mask correctable pcie rxerr spam from the ath9k 107 (define %ath9k-aer-quiet 108 (simple-service 'ath9k-aer-quiet shepherd-root-service-type 109 (list (shepherd-service 110 (provision '(ath9k-aer-quiet)) 111 (requirement '(udev)) 112 (one-shot? #t) 113 (documentation 114 "Turn off ASPM L0s on the wifi card (it makes the link throw 115 RxErr/BadDLLP errors) and mask RxErr AER reports from it.") 116 (start #~(lambda _ 117 (false-if-exception 118 (call-with-output-file 119 "/sys/bus/pci/devices/0000:01:00.0/link/l0s_aspm" 120 (lambda (port) (display "0" port)))) 121 (zero? (system* #$(file-append pciutils "/sbin/setpci") 122 "-s" "01:00.0" 123 "ECAP_AER+14.l=00000001:00000001")))))))) 124 125 ;; zstd is a module, so set it after boot 126 (define %zswap-zstd 127 (simple-service 'zswap-zstd shepherd-root-service-type 128 (list (shepherd-service 129 (provision '(zswap-zstd)) 130 (requirement '(file-systems)) 131 (one-shot? #t) 132 (documentation "Use zstd for zswap.") 133 (start #~(lambda _ 134 (call-with-output-file 135 "/sys/module/zswap/parameters/compressor" 136 (lambda (port) (display "zstd" port))) 137 #t)))))) 138 139 (define %mihomo 140 (simple-service 'mihomo shepherd-root-service-type 141 (list (shepherd-service 142 (provision '(mihomo)) 143 (requirement '(networking)) 144 (documentation "mihomo proxy, config in /etc/mihomo.") 145 (start #~(make-forkexec-constructor 146 (list #$(file-append 147 (local-file "/etc/mihomo/mihomo" "mihomo-bin" 148 #:recursive? #t)) 149 "-d" "/etc/mihomo") 150 #:log-file "/var/log/mihomo.log")) 151 (stop #~(make-kill-destructor)) 152 (respawn? #t))))) 153 154 (define %linkwatch 155 (simple-service 'linkwatch shepherd-root-service-type 156 (list (shepherd-service 157 (provision '(linkwatch)) 158 (requirement '(mihomo)) 159 (documentation "Refresh mihomo rules, log VPS ping loss.") 160 (start #~(make-forkexec-constructor 161 (list #$(file-append bash-minimal "/bin/sh") 162 #$(local-file "dots/bin/linkwatch.sh") 163 %vps-ip) 164 #:environment-variables 165 (list (string-append "PATH=" #$inetutils "/bin:" #$curl "/bin:" 166 #$coreutils "/bin:" #$sed "/bin")) 167 #:log-file "/var/log/linkwatch.log")) 168 (stop #~(make-kill-destructor)) 169 (respawn? #t))))) 170 171 (define %hark-pub 172 (plain-file "hark-into-xiii.pub" (string-append 173 "from=\"127.0.0.1,::1," %vps-ygg "\" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKAeU3T+bmy5xBXDZGXn2YZuRlSo+uuygcaLTwP3JKdS hark-into-xiii\n"))) 174 175 ;; off by default: doas herd start/stop hark-tunnel 176 (define %hark-tunnel 177 (simple-service 'hark-tunnel shepherd-root-service-type 178 (list (shepherd-service 179 (provision '(hark-tunnel)) 180 (requirement '(networking ssh-daemon)) 181 (documentation "Reverse ssh tunnel for hark (VPS :2222 -> :2022).") 182 (start #~(make-forkexec-constructor 183 (list #$(file-append openssh "/bin/ssh") 184 "-i" "/etc/xiii-tun/id_ed25519" "-N" "-T" 185 "-o" "BatchMode=yes" 186 "-o" "ExitOnForwardFailure=yes" 187 "-o" "ServerAliveInterval=15" 188 "-o" "ServerAliveCountMax=3" 189 "-o" "UserKnownHostsFile=/etc/xiii-tun/known_hosts" 190 "-o" "StrictHostKeyChecking=yes" 191 "-R" "2222:127.0.0.1:2022" 192 (string-append "utopia@" %vps-ip)) 193 #:log-file "/var/log/hark-tunnel.log")) 194 (stop #~(make-kill-destructor)) 195 (auto-start? #f) 196 (respawn? #t) 197 (respawn-delay 20))))) 198 199 (operating-system 200 (host-name "XIII") 201 (timezone "Europe/Samara") 202 203 (kernel-arguments 204 (cons* "slab_nomerge" 205 "modprobe.blacklist=pcspkr" 206 "video.brightness_switch_enabled=0" 207 "randomize_kstack_offset=on" 208 "page_alloc.shuffle=1" 209 "init_on_alloc=1" 210 "proc_mem.force_override=never" 211 "zswap.enabled=1" 212 "zswap.shrinker_enabled=1" 213 %default-kernel-arguments)) 214 (locale "en_US.utf8") 215 216 (keyboard-layout (keyboard-layout "us" "colemak")) 217 218 (bootloader 219 (bootloader-configuration 220 (bootloader grub-efi-removable-bootloader) 221 (targets '("/boot/efi")))) 222 223 (mapped-devices 224 (list (mapped-device 225 (source (uuid "c91d48ca-fd71-4b0d-a714-257be36343ac")) 226 (target "cryptroot") 227 (type luks-device-mapping)))) 228 229 (file-systems 230 (append 231 (list (file-system 232 (mount-point "/") 233 (device (file-system-label "xiii-root")) 234 (type "ext4") 235 (dependencies mapped-devices)) 236 (file-system 237 (mount-point "/boot/efi") 238 (device (uuid "AFED-ED88" 'fat32)) 239 (type "vfat"))) 240 %base-file-systems)) 241 242 (swap-devices 243 (list (swap-space 244 (target "/swapfile") 245 (dependencies (filter (file-system-mount-point-predicate "/") 246 file-systems))))) 247 248 (users 249 (cons (user-account 250 (name "freya") 251 (group "users") 252 (supplementary-groups '("wheel" "audio" "video" "input" "netdev"))) 253 %base-user-accounts)) 254 255 (privileged-programs %privileged-programs) 256 257 (packages 258 (append 259 (specifications->packages 260 '("niri" 261 "wlsunset" "nvi" 262 "foot" "wmenu" "wbg" 263 "iwd" "cryptsetup" "git" "mpv" 264 "brightnessctl" "alsa-utils" 265 "wl-clipboard" "cliphist" 266 "font-spleen" "font-ipa-ex")) 267 %base-packages)) 268 269 (services 270 (append 271 (list (service yggdrasil-service-type 272 (yggdrasil-configuration 273 (autoconf? #f) 274 (json-config '((peers . #("tls://server.i113d.ru:12632" "ws://mskaeza.i113d.ru:12634")) 275 (IfName . "ygg0"))))) 276 (service iwd-service-type 277 (iwd-configuration 278 (shepherd-provision '(iwd wireless-daemon networking)) 279 (config 280 (iwd-settings 281 (general (iwd-general-settings 282 (enable-network-configuration? #t) 283 (extra-options '(("AddressRandomization" . "network"))))) 284 (network (iwd-network-settings 285 (name-resolving-service 'resolvconf))))))) 286 (service elogind-service-type 287 (elogind-configuration 288 (handle-lid-switch 'ignore) 289 (handle-lid-switch-external-power 'ignore))) 290 (service dbus-root-service-type) 291 (service polkit-service-type) 292 (service upower-service-type 293 (upower-configuration 294 (ignore-lid? #t) 295 (use-percentage-for-policy? #t) 296 (percentage-low 20) 297 (percentage-critical 10) 298 (percentage-action 5) 299 (critical-power-action 'power-off))) 300 (service ntp-service-type) 301 (service nftables-service-type 302 (nftables-configuration (ruleset %nftables-ruleset))) 303 (simple-service 'doas-conf activation-service-type 304 #~(let ((tmp "/etc/doas.conf.new")) 305 (copy-file #$(plain-file "doas.conf" "permit persist setenv { TERMINFO_DIRS PATH } :wheel\n") tmp) 306 (chown tmp 0 0) 307 (rename-file tmp "/etc/doas.conf"))) 308 %whonix-machine-id 309 %ath9k-aer-quiet 310 %zswap-zstd 311 %mihomo 312 %linkwatch 313 (service openssh-service-type 314 (openssh-configuration 315 (port-number 2022) 316 (permit-root-login 'prohibit-password) 317 (password-authentication? #f) 318 (authorized-keys `(("root" ,%hark-pub))))) 319 %hark-tunnel 320 (udev-rules-service 'brightnessctl (specification->package "brightnessctl"))) 321 (modify-services %base-services 322 (console-font-service-type config => 323 (map (lambda (tty) (cons (car tty) #~(string-append #$font-spleen:psf "/share/consolefonts/spleen-12x24.psfu"))) config)) 324 (sysctl-service-type config => 325 (sysctl-configuration 326 (inherit config) 327 (settings (append (sysctl-configuration-settings config) 328 %sysctl-hardening)))) 329 (guix-service-type config => 330 (guix-configuration 331 (inherit config) 332 (privileged? #f) 333 (http-proxy "http://127.0.0.1:1080") 334 (substitute-urls (cons* "https://mirror.yandex.ru/mirrors/guix" "https://cache-fi.guix.moe" 335 (append %default-substitute-urls 336 (list "https://substitutes.nonguix.org")))) 337 (authorized-keys 338 (cons (plain-file "nonguix.pub" "(public-key (ecc (curve Ed25519) (q #C1FD53E5D4CE971933EC50C9F307AE2171A2D3B52C804642A7A35F84F3A4EA98#)))") 339 %default-authorized-guix-keys))))))))