nixos-config/services/nextcloud.nix

113 lines
2.3 KiB
Nix
Raw Normal View History

2022-04-10 11:54:58 +02:00
{
lib,
config,
pkgs,
...
}:
2021-03-23 19:31:59 +01:00
# TODO: setup prometheus exporter
let
2022-04-10 11:54:58 +02:00
inherit
(lib)
2022-01-11 16:08:21 +01:00
mkEnableOption
mkIf
mkOption
2022-04-10 11:54:58 +02:00
;
2022-01-11 16:08:21 +01:00
2021-03-23 19:31:59 +01:00
cfg = config.my.services.nextcloud;
my = config.my;
domain = config.networking.domain;
hostname = config.networking.hostName;
fqdn = "${hostname}.${domain}";
2021-03-23 19:31:59 +01:00
dbName = "nextcloud";
2022-04-10 11:54:58 +02:00
in {
options.my.services.nextcloud = let
inherit (lib) types;
in {
2022-01-11 16:08:21 +01:00
enable = mkEnableOption "NextCloud";
adminpassFile = mkOption {
type = types.path;
description = ''
Path to a file containing the admin's password, must be readable by
'nextcloud' user.
'';
};
2021-03-23 19:31:59 +01:00
};
2022-01-11 16:08:21 +01:00
config = mkIf cfg.enable {
2021-03-23 19:31:59 +01:00
services.postgresql = {
enable = true;
2022-04-10 11:54:58 +02:00
ensureDatabases = [dbName];
2021-03-23 19:31:59 +01:00
ensureUsers = [
{
name = "nextcloud";
ensureDBOwnership = true;
2021-03-23 19:31:59 +01:00
}
];
};
# not handled by module
2022-04-10 11:54:58 +02:00
systemd.services.nextcloud-setup = {
requires = ["postgresql.service"];
after = ["postgresql.service"];
};
2021-03-23 19:31:59 +01:00
services.postgresqlBackup = {
2022-04-10 11:54:58 +02:00
databases = [dbName];
2021-03-23 19:31:59 +01:00
};
services.nextcloud = {
enable = true;
hostName = "cloud.${domain}";
https = true;
package = pkgs.nextcloud27;
2021-03-23 19:31:59 +01:00
maxUploadSize = "1G";
config = {
overwriteProtocol = "https";
defaultPhoneRegion = "FR";
dbtype = "pgsql";
dbuser = "nextcloud";
dbname = dbName;
dbhost = "/run/postgresql";
adminuser = "admin";
adminpassFile = cfg.adminpassFile;
2021-03-23 19:31:59 +01:00
};
};
users.groups.media.members = ["nextcloud"];
2021-03-23 19:31:59 +01:00
services.nginx = {
virtualHosts = {
"cloud.${domain}" = {
forceSSL = true;
useACMEHost = fqdn;
2021-03-23 19:31:59 +01:00
};
};
};
security.acme.certs.${fqdn}.extraDomainNames = ["cloud.${domain}"];
my.services.restic-backup = let
nextcloudHome = config.services.nextcloud.home;
2022-04-10 11:54:58 +02:00
in
mkIf cfg.enable {
paths = [nextcloudHome];
exclude = [
# borg can fail if *.part files disappear during backup
"${nextcloudHome}/data/*/uploads"
# image previews can take up a lot of space
"${nextcloudHome}/data/appdata_*/preview"
# specific account for huge files I don't care about losing
"${nextcloudHome}/data/misc"
];
};
2021-03-23 19:31:59 +01:00
};
}