2024-10-19 15:04:13 -05:00
|
|
|
{
|
|
|
|
flake,
|
|
|
|
config,
|
|
|
|
...
|
|
|
|
}: let
|
2024-10-19 18:22:29 -05:00
|
|
|
inherit (flake.config.system.device) server;
|
|
|
|
inherit (flake.config.service.instance) web wiki;
|
|
|
|
service = wiki;
|
2024-10-27 12:41:30 -05:00
|
|
|
localhost = web.localhost.address1;
|
2024-10-19 18:22:29 -05:00
|
|
|
host = "${service.subdomain}.${web.domains.url1}";
|
2024-10-19 15:04:13 -05:00
|
|
|
in {
|
|
|
|
services = {
|
|
|
|
wiki-js = {
|
|
|
|
enable = true;
|
2024-10-27 13:56:48 -05:00
|
|
|
environmentFile = config.sops.secrets."${service.name}/pass".path;
|
2024-10-27 12:34:00 -05:00
|
|
|
settings = {
|
2024-10-27 12:53:17 -05:00
|
|
|
port = service.ports.port0;
|
|
|
|
bindIP = localhost;
|
2024-10-27 12:34:00 -05:00
|
|
|
db = {
|
2024-10-27 12:50:56 -05:00
|
|
|
db = "wiki-js";
|
2024-10-27 12:34:00 -05:00
|
|
|
host = "/run/postgresql";
|
2024-10-27 12:50:56 -05:00
|
|
|
type = "postgres";
|
|
|
|
user = "wiki-js";
|
2024-10-27 12:34:00 -05:00
|
|
|
};
|
|
|
|
};
|
2024-10-19 15:04:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
caddy = {
|
|
|
|
virtualHosts = {
|
|
|
|
"${host}" = {
|
|
|
|
extraConfig = ''
|
2024-10-19 18:22:29 -05:00
|
|
|
reverse_proxy ${localhost}:${toString service.ports.port0}
|
2024-10-19 15:04:13 -05:00
|
|
|
|
2024-10-19 18:22:29 -05:00
|
|
|
tls ${service.ssl.cert} ${service.ssl.key}
|
2024-10-19 15:04:13 -05:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-10-19 16:00:30 -05:00
|
|
|
postgresql = {
|
2024-10-19 18:22:29 -05:00
|
|
|
ensureDatabases = [service.name];
|
2024-10-19 16:00:30 -05:00
|
|
|
ensureUsers = [
|
|
|
|
{
|
2024-10-19 18:22:29 -05:00
|
|
|
name = service.name;
|
2024-10-19 16:00:30 -05:00
|
|
|
ensureDBOwnership = true;
|
|
|
|
}
|
|
|
|
];
|
2024-10-19 15:26:09 -05:00
|
|
|
};
|
|
|
|
};
|
2024-10-19 15:04:13 -05:00
|
|
|
|
2024-10-19 16:04:58 -05:00
|
|
|
sops = let
|
|
|
|
sopsPath = secret: {
|
2024-10-27 13:56:16 -05:00
|
|
|
path = "${service.sops.path0}/${secret}";
|
2024-10-19 16:04:58 -05:00
|
|
|
owner = "root";
|
|
|
|
mode = "600";
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
secrets = builtins.listToAttrs (
|
|
|
|
map
|
|
|
|
(secret: {
|
2024-10-27 13:54:58 -05:00
|
|
|
name = "${service.name}/${secret}";
|
2024-10-19 16:04:58 -05:00
|
|
|
value = sopsPath secret;
|
|
|
|
})
|
2024-11-04 02:09:15 -06:00
|
|
|
[
|
|
|
|
"pass"
|
|
|
|
"ssh"
|
|
|
|
]
|
2024-10-19 16:04:58 -05:00
|
|
|
);
|
|
|
|
};
|
2024-10-19 16:00:30 -05:00
|
|
|
|
2024-10-19 18:22:29 -05:00
|
|
|
fileSystems."/var/lib/${service.name}" = {
|
|
|
|
device = service.paths.path0;
|
2024-10-19 15:04:13 -05:00
|
|
|
fsType = "none";
|
|
|
|
options = ["bind"];
|
|
|
|
depends = [server.storage0.mount];
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
2024-10-19 18:22:29 -05:00
|
|
|
"Z ${service.paths.path0} 755 ${service.name} ${service.name} -"
|
|
|
|
"Z ${service.sops.path0} 755 ${service.name} ${service.name} -"
|
2024-10-19 15:04:13 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
networking = {
|
|
|
|
firewall = {
|
|
|
|
allowedTCPPorts = [
|
2024-10-19 18:22:29 -05:00
|
|
|
service.ports.port0
|
|
|
|
service.ports.port1
|
2024-10-19 15:04:13 -05:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|