1{ lib, pkgs, ... }:
2{
3 networking.hostName = "clover-demo";
4 networking.hostId = "d3c10e01";
5 networking.useDHCP = true;
6 networking.dhcpcd.denyInterfaces = [ "veth*" "podman*" ];
7 environment.variables.STUDIO_JAVA_OPTIONS = "-XX:TieredStopAtLevel=1";
8 environment.variables.STUDIO_INDEX_POOL = "studio-demo";
9 environment.variables.STUDIO_API_TIMEOUT = "600";
10 environment.variables.STUDIO_MEDIA_READ_ONLY = "true";
11 environment.variables.STUDIO_VM_ACCEL = "qemu";
12 environment.variables.STUDIO_VM_PRESETS_ROOT = "/srv/vm/.library/presets";
13 environment.variables.STUDIO_VM_UPLOADS_ROOT = "/srv/vm/.library/iso";
14 services.nomad.settings.client.cpu_total_compute = 16000;
15 services.nomad.settings.client.preferred_address_family = "ipv4";
16 services.nomad.settings.plugin.nomad-driver-podman.config.client_http_timeout = "10m";
17 services.nomad.extraSettingsPlugins = lib.mkForce [
18 (pkgs.nomad-driver-podman.overrideAttrs (old: {
19 patches = (old.patches or [ ]) ++ [ ./nomad-podman-stats.patch ];
20 doCheck = true;
21 checkPhase = ''
22 runHook preCheck
23 go test . ./api -run 'TestNativeContainerStats|TestMonitorWaitsAfterSlowStats'
24 runHook postCheck
25 '';
26 }))
27 ];
28 services.dnsmasq = {
29 enable = true;
30 settings = {
31 interface = "tailscale0";
32 bind-dynamic = true;
33 address = "/studio.test/100.95.50.31";
34 };
35 };
36 services.caddy.virtualHosts."*.studio.test".extraConfig = ''
37 tls internal
38 respond 404
39 '';
40 networking.firewall.interfaces.tailscale0.allowedUDPPorts = [ 53 ];
41 boot.loader.systemd-boot.enable = true;
42 boot.loader.efi.canTouchEfiVariables = true;
43 boot.initrd.availableKernelModules = [ "virtio_pci" "virtio_blk" "virtio_net" ];
44 # Emulation delays skew HPET watchdog reads and trigger a costly clocksource fallback.
45 boot.kernelParams = [ "tsc=nowatchdog" ];
46 boot.zfs.forceImportRoot = false;
47 fileSystems."/" = {
48 device = "/dev/disk/by-label/nixos";
49 fsType = "ext4";
50 };
51 fileSystems."/boot" = {
52 device = "/dev/disk/by-label/EFI";
53 fsType = "vfat";
54 };
55 services.getty.autologinUser = "root";
56 users.groups.chloe.gid = 3000;
57 systemd.services.studio-demo-pool = {
58 wantedBy = [ "multi-user.target" ];
59 before = [ "studio-media-view.service" "nomad.service" ];
60 serviceConfig.Type = "oneshot";
61 script = ''
62 ${pkgs.coreutils}/bin/mkdir -p /var/lib/studio /srv/clover
63 if ! ${pkgs.zfs}/bin/zpool list studio-demo >/dev/null 2>&1; then
64 if test -e /var/lib/studio/zpool.img; then
65 ${pkgs.zfs}/bin/zpool import -d /var/lib/studio studio-demo
66 else
67 ${pkgs.coreutils}/bin/truncate -s 16G /var/lib/studio/zpool.img
68 ${pkgs.zfs}/bin/zpool create -f -o ashift=12 -O mountpoint=none studio-demo /var/lib/studio/zpool.img
69 fi
70 fi
71 if test "$(${pkgs.coreutils}/bin/stat -c %s /var/lib/studio/zpool.img)" -lt 17179869184; then
72 ${pkgs.coreutils}/bin/truncate -s 16G /var/lib/studio/zpool.img
73 ${pkgs.zfs}/bin/zpool online -e studio-demo /var/lib/studio/zpool.img
74 fi
75 if ! ${pkgs.zfs}/bin/zfs list studio-demo/clover >/dev/null 2>&1; then
76 ${pkgs.zfs}/bin/zfs create -o mountpoint=/srv/clover -o acltype=posixacl studio-demo/clover
77 fi
78 test "$(${pkgs.zfs}/bin/zfs get -H -o value mountpoint studio-demo/clover)" = /srv/clover
79 ${pkgs.zfs}/bin/zfs mount studio-demo/clover 2>/dev/null ||
80 ${pkgs.util-linux}/bin/findmnt -n -o SOURCE --mountpoint /srv/clover | ${pkgs.gnugrep}/bin/grep -qx studio-demo/clover
81 ${pkgs.coreutils}/bin/chown 3000:3000 /srv/clover
82 ${pkgs.coreutils}/bin/chmod 2770 /srv/clover
83 '';
84 };
85 systemd.services.studio-media-source = {
86 serviceConfig = {
87 Type = "oneshot";
88 RemainAfterExit = true;
89 TimeoutStartSec = "240s";
90 ExecStop = "${pkgs.util-linux}/bin/umount /mnt/media-source";
91 };
92 script = ''
93 ${pkgs.coreutils}/bin/mkdir -p /mnt/media-source
94 if ${pkgs.util-linux}/bin/findmnt --mountpoint /mnt/media-source >/dev/null; then
95 exit 0
96 fi
97 for attempt in $(${pkgs.coreutils}/bin/seq 1 90); do
98 if ${pkgs.util-linux}/bin/mount -t 9p -o trans=virtio,version=9p2000.L,access=any,ro media /mnt/media-source; then
99 exit 0
100 fi
101 ${pkgs.coreutils}/bin/sleep 2
102 done
103 exit 1
104 '';
105 };
106 systemd.services.studio-media-view = {
107 after = [ "studio-demo-pool.service" "studio-media-source.service" ];
108 requires = [ "studio-demo-pool.service" "studio-media-source.service" ];
109 serviceConfig = {
110 Type = "oneshot";
111 RemainAfterExit = true;
112 CPUWeight = 1000;
113 ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /srv/clover/Media";
114 ExecStart = "${pkgs.bindfs}/bin/bindfs -r --multithreaded --perms=a+rX /mnt/media-source /srv/clover/Media";
115 ExecStop = "${pkgs.util-linux}/bin/umount /srv/clover/Media";
116 };
117 };
118 systemd.services.nomad = {
119 wants = [ "studio-demo-pool.service" ];
120 requires = [ "studio-media-view.service" ];
121 after = [ "studio-demo-pool.service" "studio-media-view.service" ];
122 };
123
124 system.stateVersion = "26.05";
125}