dotfiles/modules/services/nextcloud.nix

87 lines
2.2 KiB
Nix
Raw Normal View History

{ config, pkgs, lib, ... }: {
2022-10-02 20:54:26 +00:00
options = {
nextcloudServer = lib.mkOption {
type = lib.types.str;
description = "Hostname for Nextcloud";
2022-12-21 21:18:03 +00:00
default = null;
2022-10-02 20:54:26 +00:00
};
};
2022-12-21 21:38:34 +00:00
config = lib.mkIf (config.nextcloudServer != null) {
2022-10-02 20:54:26 +00:00
services.nextcloud = {
enable = true;
package = pkgs.nextcloud25; # Required to specify
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 = {
adminpassFile = config.secrets.nextcloud.dest;
2022-10-02 20:54:26 +00:00
extraTrustedDomains = [ config.nextcloudServer ];
};
};
# Don't let Nginx use main ports (using Caddy instead)
services.nginx.virtualHosts."localhost".listen = [{
addr = "127.0.0.1";
port = 8080;
}];
# Point Caddy to Nginx
2022-12-21 21:18:03 +00:00
caddy.routes = [{
2022-10-02 20:54:26 +00:00
match = [{ host = [ config.nextcloudServer ]; }];
handle = [{
handler = "reverse_proxy";
upstreams = [{ dial = "localhost:8080"; }];
}];
}];
2022-10-08 15:52:05 +00:00
# Create credentials file for nextcloud
secrets.nextcloud = {
source = ../../private/nextcloud.age;
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" ];
};
## 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 =
"s3://${config.backupS3.bucket}.${config.backupS3.endpoint}/nextcloud";
}];
}];
};
};
# 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-02 20:54:26 +00:00
};
}