{ flake, lib, ... }: let inherit (flake.config.people) user0; serviceCfg = { name = "photoprism"; }; in { photoprismVM = { user, ip, mac, userMac, ssh, }: { microvm.vms = { "${serviceCfg.name}-${user}" = { autostart = true; restartIfChanged = true; config = { system.stateVersion = "24.05"; time.timeZone = "America/Winnipeg"; users.users.root.openssh.authorizedKeys.keys = flake.config.people.users.${user0}.sshKeys; services = { ${serviceCfg.name} = { enable = true; settings = { PHOTOPRISM_ADMIN_USER = user; PHOTOPRISM_DEFAULT_LOCAL = "en"; }; passwordFile = "/run/secrets/${user}-pass"; storagePath = "/var/lib/${serviceCfg.name}"; originalsPath = "/var/lib/${serviceCfg.name}-media"; importPath = "photos"; address = "0.0.0.0"; }; openssh = { enable = true; settings = { PasswordAuthentication = false; PermitRootLogin = "prohibit-password"; }; }; }; users.users.photoprism = { isSystemUser = true; group = "photoprism"; home = "/var/lib/photoprism"; }; users.groups.photoprism = { }; networking.firewall.allowedTCPPorts = [ 22 2342 ]; systemd = { services = { photoprism = { serviceConfig = { DynamicUser = lib.mkForce false; User = serviceCfg.name; Group = serviceCfg.name; }; }; systemd-networkd.wantedBy = [ "multi-user.target" ]; }; network = { enable = true; networks."20-lan" = { matchConfig.Name = "enp0s5"; addresses = [ { Address = "${ip}/24"; } ]; routes = [ { Destination = "0.0.0.0/0"; Gateway = "192.168.50.1"; } ]; dns = [ "1.1.1.1" "8.8.8.8" ]; }; }; # tmpfiles.rules = [ # "d /var/lib/${serviceCfg.name} 0755 ${serviceCfg.name} ${serviceCfg.name} -" # "d /var/lib/${serviceCfg.name}-media 0755 ${serviceCfg.name} ${serviceCfg.name} -" # "d /var/lib/${serviceCfg.name}-media/photos 0755 ${serviceCfg.name} ${serviceCfg.name} -" # ]; }; microvm = { vcpu = 1; mem = 512; hypervisor = "qemu"; interfaces = [ { type = "tap"; id = "vm-pp-${user}"; mac = mac; } { type = "user"; id = "vmuser-photo"; mac = userMac; } ]; forwardPorts = [ { from = "host"; host.port = ssh; guest.port = 22; } ]; shares = [ { mountPoint = "/nix/.ro-store"; proto = "virtiofs"; source = "/nix/store"; tag = "read_only_nix_store"; } { mountPoint = "/var/lib/${serviceCfg.name}"; proto = "virtiofs"; source = "/mnt/storage/users/${user}/guests/${serviceCfg.name}"; tag = "${serviceCfg.name}_${user}_data"; } { mountPoint = "/var/lib/${serviceCfg.name}-media"; proto = "virtiofs"; source = "/mnt/storage/users/${user}/home/media"; tag = "${serviceCfg.name}_${user}_media"; } { mountPoint = "/run/secrets"; proto = "virtiofs"; source = "/run/secrets/${serviceCfg.name}"; tag = "host_secrets"; } ]; }; }; }; }; systemd.tmpfiles.rules = [ "d /mnt/storage/users/${user}/guests/${serviceCfg.name} 0751 microvm wheel - -" "d /mnt/storage/users/${user}/home/media/photos 0751 microvm wheel - -" ]; sops.secrets = { "${serviceCfg.name}/${user}-pass" = { owner = "root"; mode = "0600"; }; }; }; }