selfprivacy-nixos-config/sp-modules/nextcloud/module.nix

105 lines
3.2 KiB
Nix
Raw Normal View History

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
{
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
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";
options = [
"bind"
"x-systemd.required-by=nextcloud-setup.service"
"x-systemd.required-by=nextcloud-secrets.service"
"x-systemd.before=nextcloud-setup.service"
"x-systemd.before=nextcloud-secrets.service"
];
2023-11-29 04:19:04 +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})
install -C -m 0440 -o nextcloud -g nextcloud -DT \
<(printf "%s\n" "$databasePassword") \
${db-pass-filepath}
2023-11-15 18:26:04 +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
settings = {
2023-11-29 04:19:04 +00:00
# further forces Nextcloud to use HTTPS
overwriteprotocol = "https";
};
2023-11-15 18:26:04 +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-29 04:19:04 +00:00
};
2023-11-15 18:26:04 +00:00
}