2023-11-15 18:26:04 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
{
|
2023-11-16 00:00:11 +00:00
|
|
|
options.selfprivacy.modules.nextcloud = with lib; {
|
2023-11-15 18:26:04 +00:00
|
|
|
enable = mkOption {
|
2023-12-28 08:54:59 +00:00
|
|
|
type = types.bool;
|
2023-11-15 18:26:04 +00:00
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
location = mkOption {
|
2023-12-28 08:54:59 +00:00
|
|
|
type = types.str;
|
2023-11-15 18:26:04 +00:00
|
|
|
};
|
2024-02-15 09:56:12 +00:00
|
|
|
subdomain = lib.mkOption {
|
|
|
|
default = "cloud";
|
|
|
|
type = lib.types.strMatching "[A-Za-z0-9][A-Za-z0-9\-]{0,61}[A-Za-z0-9]";
|
|
|
|
};
|
2023-11-15 18:26:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
2023-11-25 23:11:23 +00:00
|
|
|
inherit (import ./common.nix config)
|
2024-01-09 21:49:51 +00:00
|
|
|
sp secrets-filepath db-pass-filepath admin-pass-filepath;
|
2024-02-15 09:56:12 +00:00
|
|
|
cfg = sp.modules.nextcloud;
|
|
|
|
hostName = "${cfg.subdomain}.${sp.domain}";
|
2023-11-15 18:26:04 +00:00
|
|
|
in
|
2023-11-29 04:19:04 +00:00
|
|
|
lib.mkIf sp.modules.nextcloud.enable {
|
|
|
|
fileSystems = lib.mkIf sp.useBinds {
|
|
|
|
"/var/lib/nextcloud" = {
|
2024-02-15 09:56:12 +00:00
|
|
|
device = "/volumes/${cfg.location}/nextcloud";
|
2023-12-18 11:33:09 +00:00
|
|
|
options = [
|
|
|
|
"bind"
|
|
|
|
"x-systemd.required-by=nextcloud-setup.service"
|
|
|
|
"x-systemd.required-by=nextcloud-secrets.service"
|
2023-12-22 14:07:14 +00:00
|
|
|
"x-systemd.before=nextcloud-setup.service"
|
|
|
|
"x-systemd.before=nextcloud-secrets.service"
|
2023-12-18 11:33:09 +00:00
|
|
|
];
|
2023-11-29 04:19:04 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
systemd.services.nextcloud-secrets = {
|
|
|
|
before = [ "nextcloud-setup.service" ];
|
|
|
|
requiredBy = [ "nextcloud-setup.service" ];
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
path = with pkgs; [ coreutils jq ];
|
|
|
|
script = ''
|
2023-12-27 11:05:23 +00:00
|
|
|
databasePassword=$(jq -re '.modules.nextcloud.databasePassword' ${secrets-filepath})
|
|
|
|
adminPassword=$(jq -re '.modules.nextcloud.adminPassword' ${secrets-filepath})
|
|
|
|
|
2023-12-18 11:33:09 +00:00
|
|
|
install -C -m 0440 -o nextcloud -g nextcloud -DT \
|
2023-12-27 11:05:23 +00:00
|
|
|
<(printf "%s\n" "$databasePassword") \
|
2023-11-26 05:08:14 +00:00
|
|
|
${db-pass-filepath}
|
2023-11-15 18:26:04 +00:00
|
|
|
|
2023-12-18 11:33:09 +00:00
|
|
|
install -C -m 0440 -o nextcloud -g nextcloud -DT \
|
2023-12-27 11:05:23 +00:00
|
|
|
<(printf "%s\n" "$adminPassword") \
|
2023-11-26 05:08:14 +00:00
|
|
|
${admin-pass-filepath}
|
2023-11-15 18:26:04 +00:00
|
|
|
'';
|
2023-11-29 04:19:04 +00:00
|
|
|
};
|
|
|
|
services.nextcloud = {
|
|
|
|
enable = true;
|
2024-07-26 16:41:39 +00:00
|
|
|
package = pkgs.nextcloud28;
|
2023-11-29 04:19:04 +00:00
|
|
|
inherit hostName;
|
2023-11-15 18:26:04 +00:00
|
|
|
|
2023-11-29 04:19:04 +00:00
|
|
|
# Use HTTPS for links
|
2024-01-09 21:49:51 +00:00
|
|
|
https = true;
|
2023-11-15 18:26:04 +00:00
|
|
|
|
2023-11-29 04:19:04 +00:00
|
|
|
# auto-update Nextcloud Apps
|
|
|
|
autoUpdateApps.enable = true;
|
|
|
|
# set what time makes sense for you
|
|
|
|
autoUpdateApps.startAt = "05:00:00";
|
2023-11-15 18:26:04 +00:00
|
|
|
|
2023-11-29 04:19:04 +00:00
|
|
|
config = {
|
|
|
|
# further forces Nextcloud to use HTTPS
|
|
|
|
overwriteProtocol = "https";
|
2023-11-15 18:26:04 +00:00
|
|
|
|
2023-11-29 04:19:04 +00:00
|
|
|
dbtype = "sqlite";
|
|
|
|
dbuser = "nextcloud";
|
|
|
|
dbname = "nextcloud";
|
|
|
|
dbpassFile = db-pass-filepath;
|
|
|
|
adminpassFile = admin-pass-filepath;
|
|
|
|
adminuser = "admin";
|
2023-11-15 18:26:04 +00:00
|
|
|
};
|
2023-11-29 04:19:04 +00:00
|
|
|
};
|
|
|
|
services.nginx.virtualHosts.${hostName} = {
|
2024-01-09 21:49:51 +00:00
|
|
|
useACMEHost = sp.domain;
|
2023-11-29 04:19:04 +00:00
|
|
|
forceSSL = true;
|
2023-11-25 23:11:23 +00:00
|
|
|
};
|
2023-11-29 04:19:04 +00:00
|
|
|
};
|
2023-11-15 18:26:04 +00:00
|
|
|
}
|