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
|
2022-03-11 18:42:51 +01:00
|
|
|
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;
|
2022-06-12 17:18:58 +02:00
|
|
|
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";
|
2022-03-11 18:42:51 +01:00
|
|
|
|
|
|
|
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";
|
2023-12-05 16:00:25 +01:00
|
|
|
ensureDBOwnership = true;
|
2021-03-23 19:31:59 +01:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2021-03-24 00:14:43 +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-24 00:14:43 +01:00
|
|
|
};
|
|
|
|
|
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;
|
2023-12-05 10:20:03 +01:00
|
|
|
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";
|
|
|
|
|
2022-03-11 18:42:51 +01:00
|
|
|
adminuser = "admin";
|
|
|
|
adminpassFile = cfg.adminpassFile;
|
2021-03-23 19:31:59 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-11-07 16:33:39 +01:00
|
|
|
users.groups.media.members = ["nextcloud"];
|
|
|
|
|
2021-03-23 19:31:59 +01:00
|
|
|
services.nginx = {
|
|
|
|
virtualHosts = {
|
|
|
|
"cloud.${domain}" = {
|
|
|
|
forceSSL = true;
|
2022-06-12 17:18:58 +02:00
|
|
|
useACMEHost = fqdn;
|
2021-03-23 19:31:59 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-06-12 17:18:58 +02:00
|
|
|
security.acme.certs.${fqdn}.extraDomainNames = ["cloud.${domain}"];
|
|
|
|
|
2021-08-09 20:19:27 +02:00
|
|
|
my.services.restic-backup = let
|
2021-03-24 00:31:45 +01:00
|
|
|
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
|
|
|
};
|
|
|
|
}
|