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