test: setting up nas structure

This commit is contained in:
Nick 2025-12-08 03:32:04 -06:00
parent 312c52d613
commit e341e5878f
19 changed files with 1106 additions and 196 deletions

View file

@ -0,0 +1,168 @@
{
flake,
lib,
...
}:
let
inherit (flake.config.people) user0;
serviceCfg = {
name = "photoprism";
};
in
{
photoprismVM =
{
user,
ip,
mac,
userMac,
ssh,
mnt,
data,
}:
{
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"
];
};
};
};
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}/${serviceCfg.name}";
tag = "${serviceCfg.name}_${user}_data";
}
{
mountPoint = "/var/lib/${serviceCfg.name}-media";
proto = "virtiofs";
source = data;
tag = "${serviceCfg.name}_${user}_media";
}
{
mountPoint = "/run/secrets";
proto = "virtiofs";
source = "/run/secrets/${serviceCfg.name}";
tag = "host_secrets";
}
];
};
};
};
};
systemd.tmpfiles.rules = [
"d ${mnt}/${serviceCfg.name} 0751 microvm wheel - -"
"d ${data}/photos 0751 microvm wheel - -"
];
sops.secrets = {
"${serviceCfg.name}/${user}-pass" = {
owner = "root";
mode = "0600";
};
};
};
}

View file

@ -0,0 +1,52 @@
{
flake,
lib,
nasHelpers,
...
}:
let
inherit (import ./config { inherit flake lib; }) photoprismVM;
inherit (nasHelpers)
ipAddress
guestPath
mediaPath
photoprism
;
inherit (flake.config.people) user0;
id0 = builtins.toString photoprism.id0;
id1 = builtins.toString photoprism.id1;
id2 = builtins.toString photoprism.id2;
photoprismNick = photoprismVM {
user = user0;
ip = ipAddress id0;
mac = "02:00:00:00:${id0}:${id0}";
userMac = "02:00:00:00:00:${id0}";
ssh = photoprism.ssh0;
mnt = guestPath user0;
data = mediaPath user0;
};
# photoprismStacie = photoprismVM {
# user = "stacie";
# ip = ipAddress id1;
# mac = "02:00:00:00:${id1}:${id1}";
# userMac = "02:00:00:00:00:${id1}";
# ssh = photoprism.ssh1;
# mnt = guestPath "stacie";
# data = mediaPath "stacie";
# };
# photoprismGarnet = photoprismVM {
# user = "garnet";
# ip = ipAddress id2;
# mac = "02:00:00:00:${id2}:${id2}";
# userMac = "02:00:00:00:00:${id2}";
# ssh = photoprism.ssh2;
# mnt = guestPath "garnet";
# data = mediaPath "stacie";
# };
in
photoprismNick
# // photoprismStacie // photoprismGarnet