self-hosting/modules/nextcloud.nix

102 lines
3.1 KiB
Nix
Raw Normal View History

2021-07-17 00:24:30 +02:00
{ config, lib, pkgs, ... }:
let
2024-03-26 23:37:53 +01:00
cfg = config.custom.services.nextcloud;
2021-07-17 00:24:30 +02:00
uidFile = pkgs.writeText "uidfile" ''
2021-12-26 23:01:12 +01:00
nextcloud:993
2021-07-17 00:24:30 +02:00
'';
gidFile = pkgs.writeText "gidfile" ''
2021-12-26 23:01:12 +01:00
nextcloud:991
2021-07-17 00:24:30 +02:00
'';
2023-03-28 17:59:53 +02:00
in {
2024-03-26 23:37:53 +01:00
options.custom.services.nextcloud = {
enable = lib.mkEnableOption "nextcloud";
2021-11-29 02:04:29 +01:00
};
2024-03-26 23:37:53 +01:00
config = lib.mkIf cfg.enable {
sops.secrets = {
sshfsKey = { key = "sshfs_keys/private"; };
nextcloudDbPassword = {
owner = config.users.users.nextcloud.name;
key = "nextcloud/db_password";
restartUnits = [ "nextcloud-setup.service" ];
};
nextcloudAdminPassword = {
owner = config.users.users.nextcloud.name;
key = "nextcloud/admin_password";
restartUnits = [ "nextcloud-setup.service" ];
};
2021-07-17 00:24:30 +02:00
};
2024-03-26 23:37:53 +01:00
environment.systemPackages = with pkgs; [ sshfs ];
2021-07-17 00:24:30 +02:00
2024-03-26 23:37:53 +01:00
systemd.services.nextcloud-data-sshfs = {
wantedBy = [ "multi-user.target" "nextcloud-setup.service" ];
before = [ "phpfpm-nextcloud.service" ];
restartIfChanged = false;
serviceConfig = {
ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /var/lib/nextcloud/data";
ExecStart = let
options = builtins.concatStringsSep "," [
"identityfile=${config.sops.secrets.sshfsKey.path}"
"ServerAliveInterval=15"
"idmap=file"
"uidfile=${uidFile}"
"gidfile=${gidFile}"
"allow_other"
"default_permissions"
"nomap=ignore"
];
in "${pkgs.sshfs}/bin/mount.fuse.sshfs www-data@10.0.2.3:/nix/var/data/nextcloud/data "
+ "/var/lib/nextcloud/data -o ${options}";
ExecStopPost =
"-${pkgs.fuse}/bin/fusermount -u /var/lib/nextcloud/data";
KillMode = "process";
};
};
2024-03-12 05:13:57 +01:00
2024-03-26 23:37:53 +01:00
services.nginx.virtualHosts."${config.services.nextcloud.hostName}" = {
enableACME = true;
forceSSL = true;
2021-07-17 00:24:30 +02:00
};
2022-07-27 23:50:41 +02:00
2024-03-26 23:37:53 +01:00
services.nextcloud = {
enable = true;
2024-05-24 18:26:14 +02:00
package = pkgs.nextcloud29;
2024-03-26 23:37:53 +01:00
hostName = "cloud.${config.networking.domain}";
https = true;
maxUploadSize = "1G";
config = {
dbtype = "pgsql";
dbuser = "nextcloud";
dbhost = "10.0.1.11";
dbname = "nextcloud";
dbpassFile = "${config.sops.secrets.nextcloudDbPassword.path}";
adminpassFile = "${config.sops.secrets.nextcloudAdminPassword.path}";
adminuser = "root";
};
settings = {
overwriteProtocol = "https";
default_phone_region = "BE";
maintenance_window_start = 1;
};
2024-03-12 05:13:57 +01:00
2024-03-26 23:37:53 +01:00
phpOptions = {
short_open_tag = "Off";
expose_php = "Off";
error_reporting = "E_ALL & ~E_DEPRECATED & ~E_STRICT";
display_errors = "stderr";
"opcache.enable_cli" = "1";
"opcache.interned_strings_buffer" = "12";
"opcache.max_accelerated_files" = "10000";
"opcache.memory_consumption" = "128";
"opcache.revalidate_freq" = "1";
"opcache.fast_shutdown" = "1";
"openssl.cafile" = "/etc/ssl/certs/ca-certificates.crt";
catch_workers_output = "yes";
};
2022-07-27 23:50:41 +02:00
};
2021-07-17 00:24:30 +02:00
};
}