2025-11-08 22:25:51 -06:00
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
flake,
|
|
|
|
|
...
|
|
|
|
|
}:
|
2025-10-01 19:51:55 -05:00
|
|
|
let
|
|
|
|
|
inherit (flake.config.people) user0;
|
2025-11-08 22:25:51 -06:00
|
|
|
inherit (flake.config.services) instances;
|
2025-11-08 23:12:57 -06:00
|
|
|
serviceCfg = instances.jellyfin;
|
|
|
|
|
hostCfg = instances.web;
|
2025-11-08 22:25:51 -06:00
|
|
|
dns0 = instances.web.dns.provider0;
|
2025-11-08 23:12:57 -06:00
|
|
|
host = serviceCfg.domains.url0;
|
2025-11-08 22:25:51 -06:00
|
|
|
dns0Path = "dns/${dns0}";
|
2025-10-01 19:51:55 -05:00
|
|
|
in
|
|
|
|
|
{
|
2025-11-09 00:28:01 -06:00
|
|
|
microvm.vms.jellyfin = {
|
2025-11-08 22:25:51 -06:00
|
|
|
autostart = true;
|
|
|
|
|
restartIfChanged = true;
|
|
|
|
|
config = {
|
2025-11-10 01:21:38 -06:00
|
|
|
system.stateVersion = "25.05";
|
2025-11-08 22:25:51 -06:00
|
|
|
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";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
networking.firewall.allowedTCPPorts = [
|
2025-11-08 23:12:57 -06:00
|
|
|
22
|
2025-11-08 22:25:51 -06:00
|
|
|
serviceCfg.ports.port0
|
|
|
|
|
serviceCfg.ports.port1
|
|
|
|
|
serviceCfg.ports.port2
|
|
|
|
|
];
|
2025-11-08 23:12:57 -06:00
|
|
|
|
2025-11-10 01:21:38 -06:00
|
|
|
# fileSystems."/tmp" = {
|
|
|
|
|
# device = "tmpfs";
|
|
|
|
|
# fsType = "tmpfs";
|
|
|
|
|
# options = [
|
|
|
|
|
# "size=4G"
|
|
|
|
|
# "mode=1777"
|
|
|
|
|
# ];
|
|
|
|
|
# };
|
|
|
|
|
|
2025-11-09 02:42:22 -06:00
|
|
|
systemd = {
|
|
|
|
|
network = {
|
|
|
|
|
enable = true;
|
|
|
|
|
networks."20-lan" = {
|
2025-11-10 01:21:38 -06:00
|
|
|
matchConfig.Name = "enp0s6";
|
2025-11-09 02:42:22 -06:00
|
|
|
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"
|
|
|
|
|
];
|
|
|
|
|
};
|
2025-10-01 19:51:55 -05:00
|
|
|
};
|
|
|
|
|
|
2025-11-10 02:14:52 -06:00
|
|
|
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} -"
|
|
|
|
|
"Z ${serviceCfg.varPaths.path2} 0755 ${serviceCfg.name} ${serviceCfg.name} -"
|
|
|
|
|
];
|
2025-11-09 02:42:22 -06:00
|
|
|
};
|
2025-11-08 23:12:57 -06:00
|
|
|
|
2025-11-10 01:21:38 -06:00
|
|
|
systemd.services.systemd-networkd.wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
2025-11-08 22:25:51 -06:00
|
|
|
microvm = {
|
2025-11-09 04:24:22 -06:00
|
|
|
vcpu = 6;
|
|
|
|
|
mem = 8192;
|
2025-11-08 22:25:51 -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;
|
|
|
|
|
}
|
2025-10-01 19:51:55 -05:00
|
|
|
];
|
2025-11-08 22:25:51 -06:00
|
|
|
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";
|
2025-11-10 01:21:38 -06:00
|
|
|
source = "${serviceCfg.mntPaths.path0}/data";
|
2025-11-08 23:12:57 -06:00
|
|
|
tag = "${serviceCfg.name}_data";
|
2025-11-08 22:25:51 -06:00
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
mountPoint = serviceCfg.varPaths.path1;
|
|
|
|
|
proto = "virtiofs";
|
|
|
|
|
source = "${serviceCfg.mntPaths.path0}/cache";
|
2025-11-08 23:12:57 -06:00
|
|
|
tag = "${serviceCfg.name}_cache";
|
2025-11-08 22:25:51 -06:00
|
|
|
}
|
2025-11-10 01:21:38 -06:00
|
|
|
{
|
|
|
|
|
mountPoint = serviceCfg.varPaths.path2;
|
|
|
|
|
proto = "virtiofs";
|
|
|
|
|
source = "${serviceCfg.mntPaths.path0}/media";
|
|
|
|
|
tag = "${serviceCfg.name}_media";
|
|
|
|
|
}
|
2025-11-09 00:28:01 -06:00
|
|
|
];
|
|
|
|
|
};
|
2025-10-01 19:51:55 -05:00
|
|
|
};
|
2025-11-08 22:25:51 -06:00
|
|
|
};
|
2025-10-01 19:51:55 -05:00
|
|
|
|
2025-11-08 23:12:57 -06:00
|
|
|
security.acme.certs."${host}" = {
|
|
|
|
|
dnsProvider = dns0;
|
|
|
|
|
environmentFile = config.sops.secrets.${dns0Path}.path;
|
|
|
|
|
group = "caddy";
|
|
|
|
|
};
|
2025-10-01 19:51:55 -05:00
|
|
|
|
2025-11-08 22:25:51 -06:00
|
|
|
services = {
|
|
|
|
|
caddy = {
|
|
|
|
|
virtualHosts = {
|
|
|
|
|
"${host}" = {
|
|
|
|
|
extraConfig = ''
|
2025-11-08 23:12:57 -06:00
|
|
|
reverse_proxy ${serviceCfg.interface.ip}:${toString serviceCfg.ports.port0} {
|
|
|
|
|
header_up X-Real-IP {remote_host}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-08 22:25:51 -06:00
|
|
|
tls ${serviceCfg.ssl.cert} ${serviceCfg.ssl.key}
|
2025-11-08 23:12:57 -06:00
|
|
|
encode zstd gzip
|
2025-11-08 22:25:51 -06:00
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
2025-10-01 19:51:55 -05:00
|
|
|
};
|
|
|
|
|
};
|
2025-11-08 23:12:57 -06:00
|
|
|
|
|
|
|
|
users.users.caddy.extraGroups = [ "acme" ];
|
|
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
2025-11-10 01:21:38 -06:00
|
|
|
"d ${serviceCfg.mntPaths.path0} 0751 microvm wheel - -"
|
|
|
|
|
"d ${serviceCfg.mntPaths.path0}/data 0751 microvm wheel - -"
|
|
|
|
|
"d ${serviceCfg.mntPaths.path0}/cache 0751 microvm wheel - -"
|
|
|
|
|
"d ${serviceCfg.mntPaths.path0}/media 0751 microvm wheel - -"
|
2025-11-08 23:12:57 -06:00
|
|
|
];
|
2025-10-01 19:51:55 -05:00
|
|
|
}
|