dotfiles/nixos/modules/services/nextcloud.nix

119 lines
2.6 KiB
Nix
Raw Normal View History

2024-10-06 15:25:05 -05:00
{
flake,
config,
pkgs,
...
}: let
inherit (flake.config.people) user0;
2024-10-19 18:22:29 -05:00
inherit (flake.config.people.user.${user0}) name;
inherit (flake.config.system.device) server;
inherit (flake.config.service.instance) nextcloud nginx web;
service = nextcloud;
localhost = web.localhost.address0;
host = "${service.subdomain}.${web.domains.url1}";
2024-10-06 15:25:05 -05:00
in {
services = {
nextcloud = {
appstoreEnable = true;
autoUpdateApps.enable = true;
configureRedis = true;
enable = true;
hostName = host;
https = true;
2024-10-18 12:03:00 -05:00
package = pkgs.nextcloud30;
2024-10-06 15:25:05 -05:00
phpOptions."opcache.interned_strings_buffer" = "24";
2024-10-18 13:31:22 -05:00
extraAppsEnable = true;
extraApps = {
inherit
2024-10-19 18:22:29 -05:00
(config.services.service.package.packages.apps)
2024-10-18 13:57:54 -05:00
contacts
2024-10-18 13:31:22 -05:00
calendar
;
};
2024-10-06 15:25:05 -05:00
config = {
2024-10-19 18:22:29 -05:00
adminpassFile = config.sops.secrets."${service.name}-pass".path;
2024-10-18 13:31:22 -05:00
adminuser = name;
2024-10-06 15:25:05 -05:00
dbtype = "pgsql";
};
database = {
createLocally = true;
};
settings = {
default_phone_region = "CA";
log_type = "file";
mail_sendmailmode = "pipe";
mail_smtpmode = "sendmail";
maintenance_window_start = 4;
overwriteprotocol = "https";
2024-10-18 02:04:02 -05:00
trusted_proxies = [
localhost
];
2024-10-06 15:25:05 -05:00
};
};
2024-10-18 01:52:47 -05:00
nginx = {
2024-10-18 01:50:18 -05:00
enable = true;
virtualHosts.${host}.listen = [
{
2024-10-19 18:22:29 -05:00
addr = web.localhost.address1;
2024-10-18 01:50:18 -05:00
port = nginx.ports.port0;
}
];
};
2024-10-06 15:25:05 -05:00
caddy = {
virtualHosts = {
2024-10-18 01:50:18 -05:00
"${host}" = {
2024-10-06 15:25:05 -05:00
extraConfig = ''
2024-10-18 01:50:18 -05:00
reverse_proxy ${localhost}:${toString nginx.ports.port0}
2024-10-19 18:22:29 -05:00
tls ${service.ssl.cert} ${service.ssl.key}
2024-10-06 15:25:05 -05:00
'';
};
};
};
};
sops = let
sopsPath = secret: {
2024-10-19 18:22:29 -05:00
path = "${service.sops.path0}/${service.name}-${secret}";
owner = service.name;
2024-10-06 15:25:05 -05:00
mode = "600";
};
in {
secrets = builtins.listToAttrs (
map
(secret: {
2024-10-19 18:22:29 -05:00
name = "${service.name}-${secret}";
2024-10-06 15:25:05 -05:00
value = sopsPath secret;
})
2024-11-04 02:09:15 -06:00
[
"pass"
]
2024-10-06 15:25:05 -05:00
);
};
2024-10-19 18:22:29 -05:00
fileSystems."/var/lib/${service.name}" = {
device = service.paths.path0;
fsType = "none";
options = ["bind"];
depends = [server.storage0.mount];
};
2024-10-06 15:25:05 -05:00
2024-10-19 18:22:29 -05:00
systemd.tmpfiles.rules = [
"Z ${service.paths.path0} 750 ${service.name} ${service.name} -"
"Z ${service.sops.path0} 750 ${service.name} ${service.name} -"
];
2024-10-06 15:25:05 -05:00
2024-10-19 18:22:29 -05:00
users.users.${service.name}.extraGroups = ["caddy" "nginx" "postgres"];
2024-10-06 15:25:05 -05:00
networking = {
firewall = {
allowedTCPPorts = [
nginx.ports.port0
2024-10-19 18:22:29 -05:00
service.ports.port0
2024-10-06 15:25:05 -05:00
];
};
};
}