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 {
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
location = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = "sda1";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config =
|
|
|
|
let
|
2023-11-25 23:11:23 +00:00
|
|
|
inherit (import ./common.nix config)
|
|
|
|
sp secrets-filepath db-pass-filepath admin-pass-filepath hostName;
|
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" = {
|
|
|
|
device = "/volumes/${sp.modules.nextcloud.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-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-18 11:33:09 +00:00
|
|
|
install -C -m 0440 -o nextcloud -g nextcloud -DT \
|
2023-12-03 06:37:37 +00:00
|
|
|
<(jq -re '.modules.nextcloud.databasePassword' ${secrets-filepath}) \
|
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-03 06:37:37 +00:00
|
|
|
<(jq -re '.modules.nextcloud.adminPassword' ${secrets-filepath}) \
|
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;
|
2023-12-18 14:13:57 +00:00
|
|
|
package = pkgs.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
|
|
|
|
https = false;
|
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";
|
|
|
|
dbhost = "/run/postgresql"; # nextcloud adds .s.PGSQL.5432 by itself
|
|
|
|
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} = {
|
2023-12-20 12:59:57 +00:00
|
|
|
sslCertificate = "/var/lib/acme/wildcard-${sp.domain}/fullchain.pem";
|
|
|
|
sslCertificateKey = "/var/lib/acme/wildcard-${sp.domain}/key.pem";
|
2023-11-29 04:19:04 +00:00
|
|
|
forceSSL = true;
|
|
|
|
extraConfig = ''
|
|
|
|
add_header Strict-Transport-Security $hsts_header;
|
|
|
|
#add_header Content-Security-Policy "script-src 'self'; object-src 'none'; base-uri 'none';" always;
|
|
|
|
add_header 'Referrer-Policy' 'origin-when-cross-origin';
|
|
|
|
add_header X-Frame-Options DENY;
|
|
|
|
add_header X-Content-Type-Options nosniff;
|
|
|
|
add_header X-XSS-Protection "1; mode=block";
|
|
|
|
proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
|
|
|
|
expires 10m;
|
|
|
|
'';
|
|
|
|
locations = {
|
|
|
|
"/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:80/";
|
2023-11-15 19:43:59 +00:00
|
|
|
};
|
|
|
|
};
|
2023-11-25 23:11:23 +00:00
|
|
|
};
|
2023-11-29 04:19:04 +00:00
|
|
|
};
|
2023-11-15 18:26:04 +00:00
|
|
|
}
|