2024-10-24 19:06:25 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2024-10-24 19:04:33 +00:00
|
|
|
let
|
|
|
|
oldPkgs = import nixpkgs-old {
|
|
|
|
system = "x86_64-linux"; # Same architecture as above
|
|
|
|
};
|
|
|
|
in
|
2023-11-15 18:26:04 +00:00
|
|
|
{
|
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
|
|
|
};
|
|
|
|
};
|
2024-07-30 16:19:06 +00:00
|
|
|
systemd = {
|
|
|
|
services = {
|
|
|
|
phpfpm-nextcloud.serviceConfig.Slice = lib.mkForce "nextcloud.slice";
|
|
|
|
nextcloud-setup.serviceConfig.Slice = "nextcloud.slice";
|
|
|
|
nextcloud-cron.serviceConfig.Slice = "nextcloud.slice";
|
|
|
|
nextcloud-update-db.serviceConfig.Slice = "nextcloud.slice";
|
|
|
|
nextcloud-update-plugins.serviceConfig.Slice = "nextcloud.slice";
|
|
|
|
nextcloud-secrets = {
|
|
|
|
before = [ "nextcloud-setup.service" ];
|
|
|
|
requiredBy = [ "nextcloud-setup.service" ];
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
path = with pkgs; [ coreutils jq ];
|
|
|
|
script = ''
|
|
|
|
databasePassword=$(jq -re '.modules.nextcloud.databasePassword' ${secrets-filepath})
|
|
|
|
adminPassword=$(jq -re '.modules.nextcloud.adminPassword' ${secrets-filepath})
|
2023-12-27 11:05:23 +00:00
|
|
|
|
2024-07-30 16:19:06 +00:00
|
|
|
install -C -m 0440 -o nextcloud -g nextcloud -DT \
|
|
|
|
<(printf "%s\n" "$databasePassword") \
|
|
|
|
${db-pass-filepath}
|
2023-11-15 18:26:04 +00:00
|
|
|
|
2024-07-30 16:19:06 +00:00
|
|
|
install -C -m 0440 -o nextcloud -g nextcloud -DT \
|
|
|
|
<(printf "%s\n" "$adminPassword") \
|
|
|
|
${admin-pass-filepath}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
slices.nextcloud = {
|
|
|
|
description = "Nextcloud service slice";
|
|
|
|
};
|
2023-11-29 04:19:04 +00:00
|
|
|
};
|
|
|
|
services.nextcloud = {
|
|
|
|
enable = true;
|
2024-10-24 19:04:33 +00:00
|
|
|
package = oldPkgs.nextcloud26;
|
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
|
|
|
|
2024-07-30 16:19:06 +00:00
|
|
|
settings = {
|
2023-11-29 04:19:04 +00:00
|
|
|
# further forces Nextcloud to use HTTPS
|
2024-07-30 16:19:06 +00:00
|
|
|
overwriteprotocol = "https";
|
|
|
|
};
|
2023-11-15 18:26:04 +00:00
|
|
|
|
2024-07-30 16:19:06 +00:00
|
|
|
config = {
|
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
|
|
|
}
|