self-hosting/modules/nextcloud.nix

81 lines
2.2 KiB
Nix
Raw Normal View History

2021-07-17 00:24:30 +02:00
{ config, lib, pkgs, ... }:
let
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
'';
in
{
2021-11-29 02:04:29 +01:00
sops.secrets = {
sshfsKey = {
key = "sshfs_keys/private";
restartUnits = [ "var-lib-nextcloud-data.mount" ];
};
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
environment.systemPackages = with pkgs; [
sshfs
];
2021-11-29 02:04:29 +01:00
systemd.services.nextcloud-data-sshfs = {
wantedBy = [ "multi-user.target" ];
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
2021-12-26 23:01:12 +01:00
"${pkgs.sshfs}/bin/mount.fuse.sshfs www-data@10.0.2.3:/nix/var/data/nextcloud/data "
2021-11-29 02:04:29 +01:00
+ "/var/lib/nextcloud/data -o ${options}";
ExecStopPost = "-${pkgs.fuse}/bin/fusermount -u /var/lib/nextcloud/data";
KillMode = "process";
2021-07-17 00:24:30 +02:00
};
2021-11-29 02:04:29 +01:00
};
2021-07-17 00:24:30 +02:00
2021-12-07 01:55:01 +01:00
services.nginx.virtualHosts."${config.services.nextcloud.hostName}" = {
enableACME = true;
forceSSL = true;
2021-07-17 00:24:30 +02:00
};
2021-12-07 01:55:01 +01:00
2021-07-17 00:24:30 +02:00
services.nextcloud = {
enable = true;
package = pkgs.nextcloud22;
2021-07-17 00:24:30 +02:00
hostName = "cloud.${config.networking.domain}";
config = {
dbtype = "pgsql";
dbuser = "nextcloud";
dbhost = "10.0.1.11";
dbname = "nextcloud";
2021-11-29 02:04:29 +01:00
dbpassFile = "${config.sops.secrets.nextcloudDbPassword.path}";
adminpassFile = "${config.sops.secrets.nextcloudAdminPassword.path}";
2021-07-17 00:24:30 +02:00
adminuser = "root";
2021-08-05 00:33:34 +02:00
overwriteProtocol = "https";
defaultPhoneRegion = "BE";
2021-07-17 00:24:30 +02:00
};
};
}