dotfiles/nixos/modules/services/nextcloud.nix
2024-10-18 12:00:20 -05:00

128 lines
3 KiB
Nix
Executable file

{
flake,
config,
pkgs,
...
}: let
inherit (flake.config.people) user0;
inherit (flake.config.people.user.${user0}) domain;
inherit (flake.config.system.device) server wildcard;
inherit (flake.config.service.instance) nextcloud nginx;
localhost = wildcard.ip.address0;
host = "${nextcloud.subdomain}.${domain.url1}";
in {
services = {
nextcloud = {
appstoreEnable = true;
autoUpdateApps.enable = true;
configureRedis = true;
enable = true;
hostName = host;
https = true;
package = pkgs.nextcloud29;
phpOptions."opcache.interned_strings_buffer" = "24";
extraAppsEnable = true;
extraApps = {
inherit
(config.services.nextcloud.package.packages.apps)
calendar
;
};
config = {
adminpassFile = config.sops.secrets."${nextcloud.name}-pass".path;
adminuser = "admin";
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";
enabledPreviewProviders = [
"OC\\Preview\\BMP"
"OC\\Preview\\GIF"
"OC\\Preview\\JPEG"
"OC\\Preview\\Krita"
"OC\\Preview\\MarkDown"
"OC\\Preview\\MP3"
"OC\\Preview\\OpenDocument"
"OC\\Preview\\PNG"
"OC\\Preview\\TXT"
"OC\\Preview\\XBitmap"
"OC\\Preview\\HEIC"
];
trusted_proxies = [
localhost
];
};
};
nginx = {
enable = true;
virtualHosts.${host}.listen = [
{
addr = wildcard.ip.address1;
port = nginx.ports.port0;
}
];
};
caddy = {
virtualHosts = {
"${host}" = {
extraConfig = ''
reverse_proxy ${localhost}:${toString nginx.ports.port0}
tls ${nextcloud.ssl.cert} ${nextcloud.ssl.key}
'';
};
};
};
};
sops = let
sopsSecrets = ["pass"];
sopsPath = secret: {
path = "${nextcloud.sops.path0}/${nextcloud.name}-${secret}";
owner = nextcloud.name;
mode = "600";
};
in {
secrets = builtins.listToAttrs (
map
(secret: {
name = "${nextcloud.name}-${secret}";
value = sopsPath secret;
})
sopsSecrets
);
};
# fileSystems."/var/lib/${nextcloud.name}" = {
# device = nextcloud.paths.path0;
# fsType = "none";
# options = ["bind"];
# depends = [server.storage0.mount];
# };
# systemd.tmpfiles.rules = [
# "Z ${nextcloud.paths.path0} 750 ${nextcloud.name} ${nextcloud.name} -"
# "Z ${nextcloud.sops.path0} 750 ${nextcloud.name} ${nextcloud.name} -"
# ];
users.users.${nextcloud.name}.extraGroups = ["caddy" "nginx" "postgres"];
networking = {
firewall = {
allowedTCPPorts = [
nginx.ports.port0
nextcloud.ports.port0
];
};
};
}