2025-11-10 21:50:12 -06:00
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
flake,
|
2025-11-27 05:12:15 -06:00
|
|
|
pkgs,
|
2025-11-10 21:50:12 -06:00
|
|
|
...
|
|
|
|
|
}:
|
|
|
|
|
let
|
|
|
|
|
inherit (flake.config.people) user0;
|
|
|
|
|
inherit (flake.config.services) instances;
|
|
|
|
|
serviceCfg = instances.jellyfin;
|
|
|
|
|
hostCfg = instances.web;
|
|
|
|
|
dns0 = instances.web.dns.provider0;
|
|
|
|
|
host = serviceCfg.domains.url0;
|
|
|
|
|
dns0Path = "dns/${dns0}";
|
2025-11-29 05:42:40 -06:00
|
|
|
id = 993;
|
2025-11-10 21:50:12 -06:00
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
microvm.vms = {
|
|
|
|
|
${serviceCfg.name} = {
|
|
|
|
|
autostart = true;
|
|
|
|
|
restartIfChanged = true;
|
|
|
|
|
config = {
|
|
|
|
|
system.stateVersion = "25.05";
|
|
|
|
|
time.timeZone = "America/Winnipeg";
|
|
|
|
|
users.users.root.openssh.authorizedKeys.keys = flake.config.people.users.${user0}.sshKeys;
|
|
|
|
|
services = {
|
|
|
|
|
jellyfin = {
|
|
|
|
|
enable = true;
|
|
|
|
|
openFirewall = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
openssh = {
|
|
|
|
|
enable = true;
|
|
|
|
|
settings = {
|
|
|
|
|
PasswordAuthentication = false;
|
|
|
|
|
PermitRootLogin = "prohibit-password";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-29 05:01:10 -06:00
|
|
|
users.users.jellyfin = {
|
|
|
|
|
isSystemUser = true;
|
|
|
|
|
group = serviceCfg.name;
|
2025-11-29 05:42:40 -06:00
|
|
|
uid = id;
|
2025-11-29 05:01:10 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
users.groups.jellyfin = {
|
2025-11-29 05:42:40 -06:00
|
|
|
gid = id;
|
2025-11-29 05:01:10 -06:00
|
|
|
};
|
|
|
|
|
|
2025-11-10 21:50:12 -06:00
|
|
|
networking.firewall.allowedTCPPorts = [
|
|
|
|
|
22
|
|
|
|
|
serviceCfg.ports.port0
|
|
|
|
|
serviceCfg.ports.port1
|
|
|
|
|
serviceCfg.ports.port2
|
|
|
|
|
];
|
|
|
|
|
|
2025-11-24 19:52:36 -06:00
|
|
|
fileSystems."/tmp" = {
|
|
|
|
|
device = "tmpfs";
|
|
|
|
|
fsType = "tmpfs";
|
|
|
|
|
options = [
|
2025-11-29 05:01:10 -06:00
|
|
|
"size=6G"
|
2025-11-24 19:52:36 -06:00
|
|
|
"mode=1777"
|
|
|
|
|
];
|
|
|
|
|
};
|
2025-11-10 21:50:12 -06:00
|
|
|
|
|
|
|
|
systemd = {
|
|
|
|
|
network = {
|
|
|
|
|
enable = true;
|
|
|
|
|
networks."20-lan" = {
|
|
|
|
|
matchConfig.Name = "enp0s6";
|
|
|
|
|
addresses = [ { Address = "${serviceCfg.interface.ip}/24"; } ];
|
|
|
|
|
routes = [
|
|
|
|
|
{
|
|
|
|
|
Destination = "${hostCfg.localhost.address1}/0";
|
|
|
|
|
Gateway = serviceCfg.interface.gate;
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
dns = [
|
|
|
|
|
"1.1.1.1"
|
|
|
|
|
"8.8.8.8"
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
tmpfiles.rules = [
|
|
|
|
|
"Z ${serviceCfg.varPaths.path0} 0755 ${serviceCfg.name} ${serviceCfg.name} -"
|
|
|
|
|
"Z ${serviceCfg.varPaths.path2} 0755 ${serviceCfg.name} ${serviceCfg.name} -"
|
|
|
|
|
"d ${serviceCfg.varPaths.path1} 0755 ${serviceCfg.name} ${serviceCfg.name} -"
|
2025-11-14 03:58:21 -06:00
|
|
|
"Z ${serviceCfg.varPaths.path2} 0775 ${serviceCfg.name} ${serviceCfg.name} -"
|
2025-11-10 21:50:12 -06:00
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
systemd.services.systemd-networkd.wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
|
|
microvm = {
|
2025-11-27 05:12:15 -06:00
|
|
|
vcpu = 2;
|
2025-11-26 03:29:06 -06:00
|
|
|
mem = 1024 * 3;
|
2025-11-10 21:50:12 -06:00
|
|
|
hypervisor = "qemu";
|
|
|
|
|
interfaces = [
|
|
|
|
|
{
|
|
|
|
|
type = "tap";
|
|
|
|
|
id = serviceCfg.interface.id;
|
|
|
|
|
mac = serviceCfg.interface.mac;
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
type = "user";
|
|
|
|
|
id = serviceCfg.interface.idUser;
|
|
|
|
|
mac = serviceCfg.interface.macUser;
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
forwardPorts = [
|
|
|
|
|
{
|
|
|
|
|
from = "host";
|
|
|
|
|
host.port = serviceCfg.interface.ssh;
|
|
|
|
|
guest.port = 22;
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
shares = [
|
|
|
|
|
{
|
|
|
|
|
mountPoint = "/nix/.ro-store";
|
|
|
|
|
proto = "virtiofs";
|
|
|
|
|
source = "/nix/store";
|
|
|
|
|
tag = "read_only_nix_store";
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
mountPoint = serviceCfg.varPaths.path0;
|
|
|
|
|
proto = "virtiofs";
|
|
|
|
|
source = "${serviceCfg.mntPaths.path0}/data";
|
|
|
|
|
tag = "${serviceCfg.name}_data";
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
mountPoint = serviceCfg.varPaths.path1;
|
|
|
|
|
proto = "virtiofs";
|
|
|
|
|
source = "${serviceCfg.mntPaths.path0}/cache";
|
|
|
|
|
tag = "${serviceCfg.name}_cache";
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
mountPoint = serviceCfg.varPaths.path2;
|
|
|
|
|
proto = "virtiofs";
|
|
|
|
|
source = "${serviceCfg.mntPaths.path0}/media";
|
|
|
|
|
tag = "${serviceCfg.name}_media";
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
};
|
2025-11-27 05:12:15 -06:00
|
|
|
environment.systemPackages = builtins.attrValues {
|
|
|
|
|
inherit (pkgs)
|
|
|
|
|
yazi
|
|
|
|
|
bottom
|
|
|
|
|
trashy
|
|
|
|
|
fastfetch
|
|
|
|
|
;
|
|
|
|
|
};
|
2025-11-10 21:50:12 -06:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
security.acme.certs."${host}" = {
|
|
|
|
|
dnsProvider = dns0;
|
|
|
|
|
environmentFile = config.sops.secrets.${dns0Path}.path;
|
|
|
|
|
group = "caddy";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
services = {
|
|
|
|
|
caddy = {
|
|
|
|
|
virtualHosts = {
|
|
|
|
|
"${host}" = {
|
|
|
|
|
extraConfig = ''
|
|
|
|
|
reverse_proxy ${serviceCfg.interface.ip}:${toString serviceCfg.ports.port0} {
|
|
|
|
|
header_up X-Real-IP {remote_host}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tls ${serviceCfg.ssl.cert} ${serviceCfg.ssl.key}
|
|
|
|
|
encode zstd gzip
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
2025-11-29 05:01:10 -06:00
|
|
|
users = {
|
|
|
|
|
groups.jellyfin = {
|
2025-11-29 05:42:40 -06:00
|
|
|
gid = id;
|
2025-11-29 05:01:10 -06:00
|
|
|
members = [ user0 ];
|
|
|
|
|
};
|
2025-11-10 21:50:12 -06:00
|
|
|
|
2025-11-29 05:01:10 -06:00
|
|
|
users = {
|
|
|
|
|
jellyfin = {
|
|
|
|
|
isSystemUser = true;
|
|
|
|
|
group = serviceCfg.name;
|
2025-11-29 05:42:40 -06:00
|
|
|
uid = id;
|
2025-11-29 05:01:10 -06:00
|
|
|
};
|
|
|
|
|
caddy.extraGroups = [ "acme" ];
|
|
|
|
|
};
|
|
|
|
|
};
|
2025-11-10 21:50:12 -06:00
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
2025-11-14 03:58:21 -06:00
|
|
|
"d ${serviceCfg.mntPaths.path0} 0755 microvm wheel - -"
|
|
|
|
|
"d ${serviceCfg.mntPaths.path0}/data 0755 microvm wheel - -"
|
|
|
|
|
"d ${serviceCfg.mntPaths.path0}/cache 0755 microvm wheel - -"
|
|
|
|
|
"d ${serviceCfg.mntPaths.path0}/media 0775 microvm wheel - -"
|
2025-11-10 21:50:12 -06:00
|
|
|
];
|
|
|
|
|
}
|