| 1 | { config, lib, pkgs, ... }: |
| 2 | let |
| 3 | dashboard = pkgs.callPackage ./dashboard.nix { }; |
| 4 | dashboardPort = "7072"; |
| 5 | internalPort = 8448; |
| 6 | proxyToken = "/var/lib/snowglobe/dashboard-proxy.token"; |
| 7 | hostTools = lib.fileset.toSource { |
| 8 | root = ../.; |
| 9 | fileset = lib.fileset.unions [ ../tools/dashboard-host.py ../service/copyparty/manage.py ../service/copyparty/copyparty.conf ../tools/shale-labels.py ../tools/shale-access.py ../config/shale.json ../config/site.pkl ../dashboard/src/host-protocol.json ../tools/vms.py ../tools/vm-computer.py ../tools/vm-ai.py ../tools/vm-rfb.py ../tools/mac-computer.py ../guest/computer-windows.cs ../guest/computer-legacy-mac.py ../guest/computer-linux.py ../guest/computer-linux-launch ../guest/computer-linux.nix ../tools/mac-vms.py ../tools/vm-ssh.py ../tools/dashboard-run.py ../tools/release.py ../guest/protocol.json ]; |
| 10 | }; |
| 11 | computerAhk = pkgs.callPackage ./computer-ahk.nix { }; |
| 12 | nativePkl = pkgs.callPackage ./pkl.nix { }; |
| 13 | hostPython = pkgs.callPackage ./host-python.nix { }; |
| 14 | screen = pkgs.callPackage ./vm-screen.nix { }; |
| 15 | secureOvmf = pkgs.OVMF.override { |
| 16 | secureBoot = true; |
| 17 | msVarsTemplate = true; |
| 18 | tpmSupport = true; |
| 19 | }; |
| 20 | secureAavmf = pkgs.runCommand "aavmf-secure-2025.02" { |
| 21 | src = pkgs.fetchurl { |
| 22 | url = "https://deb.debian.org/debian/pool/main/e/edk2/qemu-efi-aarch64_2025.02-8+deb13u1_all.deb"; |
| 23 | sha256 = "a00b2411a79c8aeafd95a7c868ac3cd1aab592f1af9fff965f02d81a625276ed"; |
| 24 | }; |
| 25 | nativeBuildInputs = [ pkgs.dpkg ]; |
| 26 | } '' |
| 27 | dpkg-deb -x "$src" unpacked |
| 28 | mkdir -p "$out" |
| 29 | install -m444 unpacked/usr/share/AAVMF/AAVMF_CODE.secboot.fd "$out/code.fd" |
| 30 | install -m444 unpacked/usr/share/AAVMF/AAVMF_VARS.ms.fd "$out/vars.fd" |
| 31 | ''; |
| 32 | windowsArmQemu = (pkgs.qemu.override { |
| 33 | minimal = true; |
| 34 | vncSupport = true; |
| 35 | tpmSupport = true; |
| 36 | enableBlobs = true; |
| 37 | hostCpuTargets = [ "aarch64-softmmu" ]; |
| 38 | }).overrideAttrs (old: { |
| 39 | version = "11.1.2"; |
| 40 | src = pkgs.fetchurl { |
| 41 | url = "https://download.qemu.org/qemu-11.1.2.tar.xz"; |
| 42 | sha256 = "05l0hfx3kdkl719xqdps2nqcb5h2zn79nmri68qvw65vwj0mc6vk"; |
| 43 | }; |
| 44 | patches = []; |
| 45 | nativeBuildInputs = old.nativeBuildInputs ++ (with pkgs.python3Packages; [ qemu-qmp setuptools wheel pip ]); |
| 46 | buildInputs = old.buildInputs ++ [ pkgs.pixman pkgs.libtasn1 ]; |
| 47 | }); |
| 48 | in |
| 49 | { |
| 50 | nixpkgs.overlays = [ (final: prev: { |
| 51 | nomad = prev.stdenvNoCC.mkDerivation rec { |
| 52 | pname = "nomad"; |
| 53 | version = "2.1.1"; |
| 54 | src = prev.fetchurl { |
| 55 | url = "https://releases.hashicorp.com/nomad/${version}/nomad_${version}_linux_amd64.zip"; |
| 56 | hash = "sha256-BzCE92kP2up1b/Hv+LZpslw6bBd3jxmuDEdgaXPtPzk="; |
| 57 | }; |
| 58 | nativeBuildInputs = [ prev.unzip prev.autoPatchelfHook ]; |
| 59 | buildInputs = [ final.glibc ]; |
| 60 | sourceRoot = "."; |
| 61 | dontBuild = true; |
| 62 | installPhase = '' |
| 63 | runHook preInstall |
| 64 | install -Dm755 nomad $out/bin/nomad |
| 65 | install -Dm444 LICENSE.txt $out/share/licenses/nomad/LICENSE.txt |
| 66 | runHook postInstall |
| 67 | ''; |
| 68 | meta = prev.nomad.meta // { platforms = [ "x86_64-linux" ]; }; |
| 69 | }; |
| 70 | }) ]; |
| 71 | |
| 72 | nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "nomad" "nvidia-x11" "nvidia-kernel-modules" "gpu-unlock-firmware" ]; |
| 73 | |
| 74 | networking.firewall = { |
| 75 | enable = true; |
| 76 | allowedTCPPorts = [ 22 ]; |
| 77 | allowedUDPPortRanges = [{ from = 50000; to = 50031; }]; |
| 78 | interfaces.podman0.allowedTCPPorts = [ 443 internalPort 10428 15432 18428 ]; |
| 79 | interfaces.podman0.allowedTCPPortRanges = [{ from = 20000; to = 32000; }]; |
| 80 | interfaces.tailscale0.allowedTCPPorts = [ 80 443 445 8081 8082 ]; |
| 81 | }; |
| 82 | |
| 83 | services.openssh.enable = true; |
| 84 | services.caddy = { |
| 85 | enable = true; |
| 86 | package = (pkgs.caddy.withPlugins { |
| 87 | plugins = [ "github.com/caddyserver/replace-response@v0.0.0-20250618171559-80962887e4c6" ]; |
| 88 | hash = "sha256-iWtaVD4LrOgCFZc90crAlHYbHHxz8zCFnvD2ZLRkO0Q="; |
| 89 | }).overrideAttrs (old: { |
| 90 | patches = (old.patches or []) ++ [ ./caddy-body-timeout.patch ]; |
| 91 | }); |
| 92 | extraConfig = "import /var/lib/caddy/routes.caddy"; |
| 93 | virtualHosts = { |
| 94 | ":8082".extraConfig = "reverse_proxy 127.0.0.1:4646"; |
| 95 | }; |
| 96 | }; |
| 97 | systemd.services.caddy.environment = { |
| 98 | OTEL_SERVICE_NAME = "snowglobe-caddy"; |
| 99 | OTEL_EXPORTER_OTLP_TRACES_ENDPOINT = "http://127.0.0.1:10428/insert/opentelemetry/v1/traces"; |
| 100 | OTEL_TRACES_SAMPLER = "parentbased_traceidratio"; |
| 101 | OTEL_TRACES_SAMPLER_ARG = "0.25"; |
| 102 | }; |
| 103 | |
| 104 | boot.supportedFilesystems = [ "zfs" ]; |
| 105 | virtualisation.podman.enable = true; |
| 106 | virtualisation.containers.containersConf.settings.network.default_subnet = "10.88.0.0/16"; |
| 107 | virtualisation.libvirtd.enable = true; |
| 108 | virtualisation.libvirtd.qemu.swtpm.enable = true; |
| 109 | systemd.services.podman.environment.LOGGING = "--log-level=warn"; |
| 110 | |
| 111 | services.nomad = { |
| 112 | enable = true; |
| 113 | enableDocker = false; |
| 114 | dropPrivileges = false; |
| 115 | extraSettingsPlugins = [ pkgs.nomad-driver-podman ]; |
| 116 | extraPackages = [ pkgs.cni-plugins ]; |
| 117 | settings = { |
| 118 | datacenter = "clover"; |
| 119 | bind_addr = "0.0.0.0"; |
| 120 | addresses.http = "127.0.0.1"; |
| 121 | advertise.http = "127.0.0.1"; |
| 122 | server = { |
| 123 | enabled = true; |
| 124 | bootstrap_expect = 1; |
| 125 | }; |
| 126 | acl.enabled = true; |
| 127 | client = { |
| 128 | enabled = true; |
| 129 | host_network.loopback.cidr = "127.0.0.1/8"; |
| 130 | }; |
| 131 | plugin.nomad-driver-podman.config.socket_path = "unix:///run/podman/podman.sock"; |
| 132 | telemetry.collection_interval = "15s"; |
| 133 | ui.enabled = true; |
| 134 | }; |
| 135 | }; |
| 136 | |
| 137 | systemd.services.snowglobe-log-shipper = { |
| 138 | wantedBy = [ "multi-user.target" ]; |
| 139 | after = [ "nomad.service" ]; |
| 140 | wants = [ "nomad.service" ]; |
| 141 | unitConfig.ConditionPathExists = "/opt/snowglobe/current/tools/log-shipper.py"; |
| 142 | path = [ pkgs.systemd ]; |
| 143 | serviceConfig = { |
| 144 | ExecStart = "${pkgs.python3}/bin/python3 /opt/snowglobe/current/tools/log-shipper.py"; |
| 145 | Restart = "always"; |
| 146 | RestartSec = 5; |
| 147 | }; |
| 148 | }; |
| 149 | |
| 150 | systemd.services.nomad = { |
| 151 | after = [ "podman.socket" ]; |
| 152 | requires = [ "podman.socket" ]; |
| 153 | }; |
| 154 | |
| 155 | systemd.services.snowglobe-substation-watch = { |
| 156 | wantedBy = [ "multi-user.target" ]; |
| 157 | wants = [ "nomad.service" "caddy.service" ]; |
| 158 | after = [ "nomad.service" "caddy.service" ]; |
| 159 | unitConfig.ConditionPathExists = [ "/var/lib/snowglobe/nomad.token" "/opt/snowglobe/current/tools/substation-watch.py" ]; |
| 160 | environment.SNOWGLOBE_DOMAIN = config.environment.variables.SNOWGLOBE_DOMAIN; |
| 161 | path = [ pkgs.systemd pkgs.iproute2 pkgs.tcpdump ]; |
| 162 | serviceConfig = { |
| 163 | ExecStart = "${pkgs.python3}/bin/python3 /opt/snowglobe/current/tools/substation-watch.py"; |
| 164 | Restart = "always"; |
| 165 | RestartSec = 3; |
| 166 | UMask = "0077"; |
| 167 | }; |
| 168 | }; |
| 169 | |
| 170 | systemd.services.snowglobe-router = { |
| 171 | wantedBy = [ "multi-user.target" ]; |
| 172 | wants = [ "nomad.service" "caddy.service" ]; |
| 173 | after = [ "nomad.service" "caddy.service" ]; |
| 174 | unitConfig.ConditionPathExists = "/var/lib/snowglobe/router.token"; |
| 175 | environment = { |
| 176 | SNOWGLOBE_DOMAIN = config.environment.variables.SNOWGLOBE_DOMAIN; |
| 177 | SNOWGLOBE_DASHBOARD_PORT = dashboardPort; |
| 178 | SNOWGLOBE_INTERNAL_PORT = toString internalPort; |
| 179 | SNOWGLOBE_PROXY_TOKEN_FILE = proxyToken; |
| 180 | }; |
| 181 | serviceConfig = { |
| 182 | ExecStart = "${pkgs.python3}/bin/python3 ${../tools/router.py}"; |
| 183 | Restart = "always"; |
| 184 | RestartSec = 5; |
| 185 | }; |
| 186 | }; |
| 187 | |
| 188 | users.groups.snowglobe-dashboard.gid = 994; |
| 189 | users.users.snowglobe-dashboard = { |
| 190 | uid = 997; |
| 191 | isSystemUser = true; |
| 192 | group = "snowglobe-dashboard"; |
| 193 | }; |
| 194 | systemd.services.snowglobe-vm-screen = { |
| 195 | wantedBy = [ "multi-user.target" ]; |
| 196 | wants = [ "snowglobe-host.service" ]; |
| 197 | after = [ "snowglobe-host.service" ]; |
| 198 | environment.XDG_RUNTIME_DIR = "/run/snowglobe-vm-screen"; |
| 199 | serviceConfig = { |
| 200 | ExecStart = "${screen}/bin/snowglobe-vm-screen"; |
| 201 | User = "snowglobe-dashboard"; |
| 202 | Group = "snowglobe-dashboard"; |
| 203 | RuntimeDirectory = "snowglobe-vm-screen"; |
| 204 | RuntimeDirectoryMode = "0700"; |
| 205 | RuntimeDirectoryPreserve = "yes"; |
| 206 | UMask = "0077"; |
| 207 | ProtectSystem = "strict"; |
| 208 | ProtectHome = true; |
| 209 | PrivateTmp = true; |
| 210 | NoNewPrivileges = true; |
| 211 | CapabilityBoundingSet = ""; |
| 212 | MemoryMax = "2G"; |
| 213 | TasksMax = 128; |
| 214 | DevicePolicy = "closed"; |
| 215 | RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" "AF_NETLINK" ]; |
| 216 | Restart = "always"; |
| 217 | RestartSec = 2; |
| 218 | }; |
| 219 | }; |
| 220 | # Every dashboard build leaves an image; pre-start reloads any release's image from the Nix store. |
| 221 | systemd.timers.snowglobe-image-prune = { |
| 222 | wantedBy = [ "timers.target" ]; |
| 223 | timerConfig = { OnCalendar = "daily"; Persistent = true; }; |
| 224 | }; |
| 225 | systemd.services.snowglobe-image-prune = { |
| 226 | path = [ pkgs.podman ]; |
| 227 | serviceConfig.Type = "oneshot"; |
| 228 | # rmi refuses images a container still uses. |
| 229 | script = '' |
| 230 | for image in $(podman images --quiet --filter reference=localhost/snowglobe-dashboard); do |
| 231 | podman rmi "$image" || true |
| 232 | done |
| 233 | ''; |
| 234 | }; |
| 235 | systemd.timers.snowglobe-vm-expiry = { |
| 236 | wantedBy = [ "timers.target" ]; |
| 237 | timerConfig = { OnBootSec = "1min"; OnUnitActiveSec = "1min"; }; |
| 238 | }; |
| 239 | systemd.services.snowglobe-vm-expiry = { |
| 240 | path = [ pkgs.python3 pkgs.libvirt ]; |
| 241 | serviceConfig = { |
| 242 | Type = "oneshot"; |
| 243 | ExecStart = "${pkgs.python3}/bin/python3 ${hostTools}/tools/vm-ai.py reap"; |
| 244 | UMask = "0077"; |
| 245 | ProtectSystem = "strict"; |
| 246 | ProtectHome = true; |
| 247 | PrivateTmp = true; |
| 248 | NoNewPrivileges = true; |
| 249 | ReadWritePaths = [ "/srv/vm" ]; |
| 250 | }; |
| 251 | }; |
| 252 | systemd.services.snowglobe-host = { |
| 253 | wantedBy = [ "multi-user.target" ]; |
| 254 | wants = [ "podman.socket" ]; |
| 255 | after = [ "podman.socket" ]; |
| 256 | path = [ pkgs.zfs pkgs.util-linux pkgs.python3 pkgs.libvirt pkgs.qemu pkgs.gptfdisk pkgs.cdrkit pkgs.openssl pkgs.openssh pkgs.podman pkgs.nomad pkgs.systemd pkgs.rsync pkgs.nixos-rebuild nativePkl ] |
| 257 | ++ lib.optional (builtins.elem "nvidia" config.services.xserver.videoDrivers) (lib.getBin config.hardware.nvidia.package); |
| 258 | environment = (lib.filterAttrs (name: _: lib.hasPrefix "SNOWGLOBE_" name) config.environment.variables) // { |
| 259 | SNOWGLOBE_POOL = lib.attrByPath [ "SNOWGLOBE_POOL" ] "snowglobe-demo" config.environment.variables; |
| 260 | SNOWGLOBE_DASHBOARD_USER = "snowglobe-dashboard"; |
| 261 | SNOWGLOBE_COMPUTER_AHK = toString computerAhk; |
| 262 | SNOWGLOBE_VM_ACCEL = lib.attrByPath [ "SNOWGLOBE_VM_ACCEL" ] "kvm" config.environment.variables; |
| 263 | }; |
| 264 | serviceConfig = { |
| 265 | ExecStart = "${hostPython}/bin/python3 ${hostTools}/tools/dashboard-host.py"; |
| 266 | Type = "notify"; |
| 267 | Group = "snowglobe-dashboard"; |
| 268 | StateDirectory = "snowglobe/host"; |
| 269 | StateDirectoryMode = "0700"; |
| 270 | RuntimeDirectory = "snowglobe-host"; |
| 271 | RuntimeDirectoryMode = "0750"; |
| 272 | RuntimeDirectoryPreserve = "yes"; |
| 273 | UMask = "0077"; |
| 274 | ProtectSystem = "strict"; |
| 275 | ReadWritePaths = [ "/srv/vm" "-/srv/prod/shale/data" "-/srv/prod/copyparty/cfg" "/srv/staging" "/srv/clover" "/var/lib/snowglobe/dashboard" ] ++ lib.optionals (config.networking.hostName != "snowglobe-rehearsal") [ "/srv/clover/Media/vm" ]; |
| 276 | ProtectHome = true; |
| 277 | PrivateTmp = true; |
| 278 | NoNewPrivileges = true; |
| 279 | CapabilityBoundingSet = [ "CAP_SYS_ADMIN" "CAP_DAC_READ_SEARCH" "CAP_DAC_OVERRIDE" "CAP_CHOWN" ]; |
| 280 | MemoryMax = (builtins.fromJSON (builtins.readFile ../dashboard/src/host-protocol.json)).memory; |
| 281 | TasksMax = 64; |
| 282 | DevicePolicy = "closed"; |
| 283 | DeviceAllow = [ "/dev/zfs rw" "char-pts rw" ] ++ lib.optional (builtins.elem "nvidia" config.services.xserver.videoDrivers) "char-nvidia* rw"; |
| 284 | RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" ]; |
| 285 | IPAddressDeny = "any"; |
| 286 | IPAddressAllow = [ "127.0.0.1/32" config.virtualisation.containers.containersConf.settings.network.default_subnet ]; |
| 287 | Restart = "always"; |
| 288 | RestartSec = 2; |
| 289 | }; |
| 290 | }; |
| 291 | systemd.services.snowglobe-dashboard = let |
| 292 | environment = (lib.filterAttrs (name: _: lib.hasPrefix "SNOWGLOBE_" name) config.environment.variables) // { |
| 293 | SNOWGLOBE_DATA_DIR = "/data"; |
| 294 | SNOWGLOBE_PROXY_TOKEN_FILE = "/run/secrets/dashboard-proxy.token"; |
| 295 | SNOWGLOBE_NOMAD_TOKEN_FILE = "/run/secrets/dashboard-nomad.token"; |
| 296 | SNOWGLOBE_CA_BUNDLE = "/run/secrets/ca-bundle.crt"; |
| 297 | SNOWGLOBE_INDEX_DIR = "/data/index"; |
| 298 | SNOWGLOBE_INTERNAL_URL = "https://dashboard.internal.${config.environment.variables.SNOWGLOBE_DOMAIN}:${toString internalPort}"; |
| 299 | SNOWGLOBE_FILES_URL = "https://file.${config.environment.variables.SNOWGLOBE_DOMAIN}"; |
| 300 | SNOWGLOBE_AUTH_REQUIRED = "1"; |
| 301 | SNOWGLOBE_AUTH_RP_ID = "auth.${config.environment.variables.SNOWGLOBE_DOMAIN}"; |
| 302 | SNOWGLOBE_FILE_ORIGIN = "https://file.${config.environment.variables.SNOWGLOBE_DOMAIN}"; |
| 303 | SNOWGLOBE_PUBLIC_ORIGIN = "https://snowglobe.${config.environment.variables.SNOWGLOBE_DOMAIN}"; |
| 304 | SNOWGLOBE_JELLYFIN_URL = "https://jelly.${config.environment.variables.SNOWGLOBE_DOMAIN}"; |
| 305 | SNOWGLOBE_SHALE_URL = "https://shale.${config.environment.variables.SNOWGLOBE_DOMAIN}"; |
| 306 | SNOWGLOBE_PUBLISHED_ROOT = "/srv/clover/Published"; |
| 307 | SNOWGLOBE_DOMAIN = config.environment.variables.SNOWGLOBE_DOMAIN; |
| 308 | SNOWGLOBE_POOL = lib.attrByPath [ "SNOWGLOBE_POOL" ] "snowglobe-demo" config.environment.variables; |
| 309 | SNOWGLOBE_NODE_NAME = config.networking.hostName; |
| 310 | SNOWGLOBE_MEDIA_READ_ONLY = lib.attrByPath [ "SNOWGLOBE_MEDIA_READ_ONLY" ] "false" config.environment.variables; |
| 311 | SNOWGLOBE_CLOVER_READ_ONLY = lib.attrByPath [ "SNOWGLOBE_CLOVER_READ_ONLY" ] "false" config.environment.variables; |
| 312 | }; |
| 313 | in { |
| 314 | inherit environment; |
| 315 | wantedBy = [ "multi-user.target" ]; |
| 316 | wants = [ "nomad.service" "snowglobe-router.service" "snowglobe-host.service" "snowglobe-vm-screen.service" ]; |
| 317 | after = [ "nomad.service" "snowglobe-host.service" "snowglobe-vm-screen.service" ]; |
| 318 | unitConfig.ConditionPathExists = [ "/var/lib/snowglobe/dashboard.token" "/var/lib/snowglobe/ca-bundle.crt" "/opt/snowglobe/current" ]; |
| 319 | path = [ pkgs.podman pkgs.coreutils pkgs.curl pkgs.openssl pkgs.systemd ]; |
| 320 | serviceConfig = { |
| 321 | Type = "notify"; |
| 322 | NotifyAccess = "all"; |
| 323 | ExecStart = pkgs.writeShellScript "snowglobe-dashboard-start" '' |
| 324 | uid=$(id -u snowglobe-dashboard) |
| 325 | gid=$(id -g snowglobe-dashboard) |
| 326 | optional=() |
| 327 | if test -d /srv/prod/ytdl/data && test -d '/srv/clover/Documents/Config/Youtube Downloader'; then |
| 328 | optional+=(--volume=/srv/prod/ytdl/data:/srv/prod/ytdl/data:rw |
| 329 | --env=SNOWGLOBE_YT_STATE=/srv/prod/ytdl/data |
| 330 | '--env=SNOWGLOBE_YT_CONFIG=/srv/clover/Documents/Config/Youtube Downloader' |
| 331 | --env=SNOWGLOBE_YT_MEDIA=/srv/clover/Media) |
| 332 | fi |
| 333 | exec podman run --rm --replace --name=snowglobe-dashboard --pull=never \ |
| 334 | --sdnotify=conmon --cgroups=no-conmon --log-driver=journald \ |
| 335 | --user="$uid:$gid" \ |
| 336 | --group-add=${toString config.users.groups.chloe.gid} --network=podman \ |
| 337 | --read-only --read-only-tmpfs=false --cap-drop=ALL --security-opt=no-new-privileges \ |
| 338 | --memory=2g --cpus=4 --pids-limit=256 --cpu-shares=1024 \ |
| 339 | --publish=127.0.0.1:${dashboardPort}:7072 \ |
| 340 | --tmpfs=/tmp:rw,noexec,nosuid,nodev,size=256m,mode=1777 \ |
| 341 | --tmpfs=/run:rw,noexec,nosuid,nodev,size=16m,mode=755 \ |
| 342 | --env=HOME=/data --env=XDG_CACHE_HOME=/data/cache \ |
| 343 | --volume=/var/lib/snowglobe/dashboard:/data:rw \ |
| 344 | --volume=/run/snowglobe-host:/run/snowglobe-host:ro \ |
| 345 | --volume=/run/snowglobe-vm-screen:/run/snowglobe-vm-screen:ro \ |
| 346 | --volume=${proxyToken}:/run/secrets/dashboard-proxy.token:ro \ |
| 347 | --volume=/var/lib/snowglobe/dashboard.token:/run/secrets/dashboard-nomad.token:ro \ |
| 348 | --volume=/var/lib/snowglobe/ca-bundle.crt:/run/secrets/ca-bundle.crt:ro \ |
| 349 | --mount=type=bind,src=/srv/clover,dst=/srv/clover,bind-nonrecursive,bind-propagation=rslave,ro="$SNOWGLOBE_CLOVER_READ_ONLY" \ |
| 350 | --mount=type=bind,src=/srv/clover/Media,dst=/srv/clover/Media,bind-nonrecursive,bind-propagation=rslave,ro="$SNOWGLOBE_MEDIA_READ_ONLY" \ |
| 351 | ${lib.concatMapStringsSep " " (name: lib.escapeShellArg "--env=${name}") (builtins.attrNames environment)} \ |
| 352 | ${lib.concatMapStringsSep " " (name: lib.escapeShellArg "--add-host=${name}.${config.environment.variables.SNOWGLOBE_DOMAIN}:host-gateway") [ "dashboard.internal" "auth" "jelly" "db" "shale" ]} \ |
| 353 | "''${optional[@]}" ${lib.escapeShellArg "${dashboard.image.imageName}:${dashboard.image.imageTag}"} |
| 354 | ''; |
| 355 | ExecStop = "${pkgs.podman}/bin/podman stop --ignore --time=8 snowglobe-dashboard"; |
| 356 | ExecStopPost = "${pkgs.podman}/bin/podman rm --ignore --force snowglobe-dashboard"; |
| 357 | CPUWeight = 1000; |
| 358 | KillMode = "mixed"; |
| 359 | TimeoutStartSec = 180; |
| 360 | TimeoutStopSec = 30; |
| 361 | Restart = "always"; |
| 362 | RestartSec = 5; |
| 363 | }; |
| 364 | preStart = '' |
| 365 | umask 0077 |
| 366 | if ! test -e ${proxyToken}; then |
| 367 | openssl rand -hex 32 > ${proxyToken}.pending |
| 368 | mv ${proxyToken}.pending ${proxyToken} |
| 369 | fi |
| 370 | chown root:snowglobe-dashboard ${proxyToken} /var/lib/snowglobe/dashboard.token |
| 371 | chmod 0640 ${proxyToken} /var/lib/snowglobe/dashboard.token |
| 372 | chown -R snowglobe-dashboard:snowglobe-dashboard /var/lib/snowglobe/dashboard |
| 373 | systemd-tmpfiles --create --prefix=/srv/prod/ytdl/data |
| 374 | if ! podman image exists ${lib.escapeShellArg "${dashboard.image.imageName}:${dashboard.image.imageTag}"}; then |
| 375 | podman load --quiet --input ${dashboard.image} |
| 376 | fi |
| 377 | ''; |
| 378 | postStart = '' |
| 379 | for attempt in $(seq 1 30); do |
| 380 | if printf 'header = "Snowglobe-Proxy-Token: %s"\n' "$(cat ${proxyToken})" | curl --config - --fail --silent http://127.0.0.1:${dashboardPort}/ >/dev/null; then |
| 381 | exit 0 |
| 382 | fi |
| 383 | sleep 1 |
| 384 | done |
| 385 | exit 1 |
| 386 | ''; |
| 387 | }; |
| 388 | |
| 389 | systemd.tmpfiles.rules = [ |
| 390 | "d /srv/prod 0755 root root -" |
| 391 | "A+ /srv/prod/shale/data - - - - u:root:rwX,d:u:root:rwx" |
| 392 | "d /srv/staging 0755 root root -" |
| 393 | "d /srv/vm 0755 root root -" |
| 394 | "d /srv/logs 0770 clo chloe -" |
| 395 | "A+ /srv/prod/ytdl/data - - - - g:chloe:rwX,m::rwX,d:g:chloe:rwx,d:m::rwx" |
| 396 | "d /var/lib/snowglobe 0700 root root -" |
| 397 | "d /var/lib/snowglobe/dashboard 0700 snowglobe-dashboard snowglobe-dashboard -" |
| 398 | "d /var/lib/snowglobe/routes 0700 root root -" |
| 399 | "d /var/lib/caddy/snowglobe 0755 caddy caddy -" |
| 400 | "f /var/lib/caddy/routes.caddy 0640 caddy caddy -" |
| 401 | "d /var/lib/swtpm-localca 0750 tss tss -" |
| 402 | ]; |
| 403 | |
| 404 | environment.variables.SNOWGLOBE_NODE_NAME = config.networking.hostName; |
| 405 | environment.variables.SNOWGLOBE_DOMAIN = lib.mkDefault "snowglobe.test"; |
| 406 | environment.variables.SNOWGLOBE_VM_SECURE_OVMF_CODE = secureOvmf.firmware; |
| 407 | environment.variables.SNOWGLOBE_VM_SECURE_OVMF_VARS = secureOvmf.variablesMs; |
| 408 | environment.variables.SNOWGLOBE_VM_SECURE_AAVMF_CODE = "${secureAavmf}/code.fd"; |
| 409 | environment.variables.SNOWGLOBE_VM_SECURE_AAVMF_VARS = "${secureAavmf}/vars.fd"; |
| 410 | environment.variables.SNOWGLOBE_VM_WINDOWS_ARM_EMULATOR = "${windowsArmQemu}/bin/qemu-system-aarch64"; |
| 411 | environment.systemPackages = with pkgs; [ acl curl jq openssl python3 rsync zfs qemu ] ++ [ nativePkl ]; |
| 412 | } |