2022-10-16 03:18:58 +00:00
|
|
|
{ config, pkgs, lib, ... }: {
|
2022-10-02 20:54:26 +00:00
|
|
|
|
2023-07-04 22:20:43 +00:00
|
|
|
config = lib.mkIf config.services.nextcloud.enable {
|
2022-10-02 20:54:26 +00:00
|
|
|
|
|
|
|
services.nextcloud = {
|
2023-04-16 20:59:37 +00:00
|
|
|
package = pkgs.nextcloud26; # Required to specify
|
2023-03-03 20:54:27 +00:00
|
|
|
datadir = "/data/nextcloud";
|
2022-10-02 20:54:26 +00:00
|
|
|
https = true;
|
|
|
|
hostName = "localhost";
|
2022-10-04 12:29:29 +00:00
|
|
|
maxUploadSize = "50G";
|
2022-10-02 20:54:26 +00:00
|
|
|
config = {
|
2022-10-16 03:18:58 +00:00
|
|
|
adminpassFile = config.secrets.nextcloud.dest;
|
2023-07-07 16:16:07 +00:00
|
|
|
extraTrustedDomains = [ config.hostnames.content ];
|
2022-10-02 20:54:26 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# Don't let Nginx use main ports (using Caddy instead)
|
|
|
|
services.nginx.virtualHosts."localhost".listen = [{
|
|
|
|
addr = "127.0.0.1";
|
|
|
|
port = 8080;
|
|
|
|
}];
|
|
|
|
|
2022-10-16 03:18:58 +00:00
|
|
|
# Point Caddy to Nginx
|
2022-12-21 21:18:03 +00:00
|
|
|
caddy.routes = [{
|
2023-07-07 16:16:07 +00:00
|
|
|
match = [{ host = [ config.hostnames.content ]; }];
|
2022-10-02 20:54:26 +00:00
|
|
|
handle = [{
|
|
|
|
handler = "reverse_proxy";
|
|
|
|
upstreams = [{ dial = "localhost:8080"; }];
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
|
2022-10-08 15:52:05 +00:00
|
|
|
# Create credentials file for nextcloud
|
2022-10-16 03:18:58 +00:00
|
|
|
secrets.nextcloud = {
|
2023-03-01 04:54:48 +00:00
|
|
|
source = ../../../private/nextcloud.age;
|
2022-10-16 03:18:58 +00:00
|
|
|
dest = "${config.secretsDirectory}/nextcloud";
|
|
|
|
owner = "nextcloud";
|
|
|
|
group = "nextcloud";
|
|
|
|
permissions = "0440";
|
|
|
|
};
|
|
|
|
systemd.services.nextcloud-secret = {
|
2022-10-08 15:52:05 +00:00
|
|
|
requiredBy = [ "nextcloud-setup.service" ];
|
|
|
|
before = [ "nextcloud-setup.service" ];
|
|
|
|
};
|
|
|
|
|
2023-03-03 20:54:27 +00:00
|
|
|
# Grant user access to Nextcloud directories
|
|
|
|
users.users.${config.user}.extraGroups = [ "nextcloud" ];
|
|
|
|
|
2022-10-08 15:52:05 +00:00
|
|
|
## Backup config
|
|
|
|
|
|
|
|
# Open to groups, allowing for backups
|
|
|
|
systemd.services.phpfpm-nextcloud.serviceConfig.StateDirectoryMode =
|
|
|
|
lib.mkForce "0770";
|
|
|
|
|
|
|
|
# Allow litestream and nextcloud to share a sqlite database
|
2022-10-16 19:06:56 +00:00
|
|
|
users.users.litestream.extraGroups = [ "nextcloud" ];
|
2022-10-08 15:52:05 +00:00
|
|
|
users.users.nextcloud.extraGroups = [ "litestream" ];
|
|
|
|
|
|
|
|
# Backup sqlite database with litestream
|
|
|
|
services.litestream = {
|
|
|
|
settings = {
|
|
|
|
dbs = [{
|
2022-10-15 19:00:37 +00:00
|
|
|
path = "${config.services.nextcloud.datadir}/data/nextcloud.db";
|
2022-10-08 15:52:05 +00:00
|
|
|
replicas = [{
|
|
|
|
url =
|
2022-12-22 00:31:25 +00:00
|
|
|
"s3://${config.backup.s3.bucket}.${config.backup.s3.endpoint}/nextcloud";
|
2022-10-08 15:52:05 +00:00
|
|
|
}];
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# Don't start litestream unless nextcloud is up
|
|
|
|
systemd.services.litestream = {
|
2022-10-16 19:06:56 +00:00
|
|
|
after = [ "phpfpm-nextcloud.service" ];
|
|
|
|
requires = [ "phpfpm-nextcloud.service" ];
|
2022-10-03 04:05:07 +00:00
|
|
|
};
|
2022-10-02 20:54:26 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|