dotfiles/modules/nixos/services/nextcloud/default.nix

146 lines
3.2 KiB
Nix
Raw Normal View History

2025-03-29 23:08:26 -05:00
{
flake,
config,
pkgs,
...
}:
let
inherit (flake.config.people) user0;
inherit (flake.config.people.users.${user0}) name;
inherit (flake.config.machines.devices) ceres;
2025-06-09 03:04:37 -05:00
inherit (flake.config.services.instances)
nextcloud
nginx
smtp
web
;
2025-03-29 23:08:26 -05:00
service = nextcloud;
localhost = web.localhost.address0;
2025-06-09 02:32:50 -05:00
host = "${service.subdomain}.${web.domains.url0}";
2025-03-29 23:08:26 -05:00
in
{
services = {
nextcloud = {
appstoreEnable = true;
autoUpdateApps.enable = true;
configureRedis = true;
enable = true;
hostName = host;
https = true;
2025-06-09 02:24:08 -05:00
package = pkgs.nextcloud31;
2025-03-29 23:08:26 -05:00
phpOptions."opcache.interned_strings_buffer" = "24";
extraAppsEnable = true;
extraApps = {
2025-06-09 02:22:57 -05:00
inherit (pkgs.nextcloud31Packages.apps)
2025-03-29 23:08:26 -05:00
contacts
calendar
2025-06-09 02:07:27 -05:00
deck
2025-03-29 23:08:26 -05:00
;
};
config = {
adminpassFile = config.sops.secrets."${service.name}-pass".path;
adminuser = name;
dbtype = "pgsql";
};
database = {
createLocally = true;
};
settings = {
default_phone_region = "CA";
log_type = "file";
2025-06-09 03:23:19 -05:00
mail_domain = host;
2025-06-09 03:04:37 -05:00
mail_sendmailmode = "smtp";
mail_smtpmode = "smtp";
2025-06-09 03:23:19 -05:00
mail_smtphost = localhost;
2025-06-09 03:04:37 -05:00
mail_smtpport = smtp.ports.port0;
2025-06-09 03:31:21 -05:00
mail_smtpsecure = "";
2025-06-09 03:27:26 -05:00
mail_smtpauth = false;
2025-06-09 03:04:37 -05:00
mail_smtpname = smtp.hostname;
2025-06-09 03:23:19 -05:00
mail_from_address = "noreply";
2025-06-09 03:04:37 -05:00
mail_smtppassword = config.sops.secrets."${service.name}-smtp".path;
2025-03-29 23:08:26 -05:00
maintenance_window_start = 4;
overwriteprotocol = "https";
trusted_proxies = [
localhost
];
};
};
nginx = {
enable = true;
virtualHosts.${host}.listen = [
{
addr = web.localhost.address1;
port = nginx.ports.port0;
}
];
};
caddy = {
virtualHosts = {
"${host}" = {
extraConfig = ''
reverse_proxy ${localhost}:${toString nginx.ports.port0}
tls ${service.ssl.cert} ${service.ssl.key}
'';
};
};
};
};
sops =
let
sopsPath = secret: {
path = "${service.sops.path0}/${service.name}-${secret}";
owner = service.name;
mode = "600";
};
in
{
secrets = builtins.listToAttrs (
map
(secret: {
name = "${service.name}-${secret}";
value = sopsPath secret;
})
[
"pass"
2025-06-09 03:04:37 -05:00
"smtp"
2025-03-29 23:08:26 -05:00
]
);
};
fileSystems."/var/lib/${service.name}" = {
device = service.paths.path0;
fsType = "none";
options = [
"bind"
];
depends = [
ceres.storage0.mount
];
};
systemd.tmpfiles.rules = [
"Z ${service.paths.path0} 750 ${service.name} ${service.name} -"
2025-06-09 02:29:45 -05:00
"Z ${service.paths.path0}/config 750 ${service.name} ${service.name} -"
2025-03-29 23:08:26 -05:00
"Z ${service.sops.path0} 750 ${service.name} ${service.name} -"
];
users.users.${service.name}.extraGroups = [
"caddy"
"nginx"
"postgres"
];
networking = {
firewall = {
allowedTCPPorts = [
nginx.ports.port0
service.ports.port0
];
};
};
}