2022-11-18 17:00:20 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
let
|
2023-09-15 13:04:24 +02:00
|
|
|
domain = "nc.staging.ifsr.de";
|
2023-09-06 14:22:56 +02:00
|
|
|
legacy_domain = "oc.ifsr.de";
|
2022-11-18 17:00:20 +01:00
|
|
|
in
|
|
|
|
{
|
|
|
|
sops.secrets = {
|
2023-08-23 20:56:24 +02:00
|
|
|
nextcloud_adminpass.owner = "nextcloud";
|
|
|
|
nextcloud_ldap_search = {
|
|
|
|
key = "portunus/search-password";
|
2022-11-18 17:00:20 +01:00
|
|
|
owner = "nextcloud";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services = {
|
|
|
|
nextcloud = {
|
|
|
|
enable = true;
|
2023-08-30 14:01:49 +02:00
|
|
|
package = pkgs.nextcloud25;
|
2023-05-25 22:58:14 +02:00
|
|
|
enableBrokenCiphersForSSE = false; # disable the openssl warning
|
2023-08-23 20:56:24 +02:00
|
|
|
hostName = domain;
|
2022-11-18 17:40:12 +01:00
|
|
|
https = true; # Use https for all urls
|
2022-11-18 17:00:20 +01:00
|
|
|
phpExtraExtensions = all: [
|
2022-11-18 17:40:12 +01:00
|
|
|
all.ldap # Enable ldap php extension
|
2022-11-18 17:00:20 +01:00
|
|
|
];
|
|
|
|
config = {
|
|
|
|
dbtype = "pgsql";
|
|
|
|
adminpassFile = config.sops.secrets.nextcloud_adminpass.path;
|
|
|
|
adminuser = "root";
|
|
|
|
};
|
2023-08-30 14:01:49 +02:00
|
|
|
# postgres database is configured automatically
|
2023-08-23 22:12:06 +02:00
|
|
|
database.createLocally = true;
|
2022-11-18 17:00:20 +01:00
|
|
|
};
|
|
|
|
|
2022-11-18 17:40:12 +01:00
|
|
|
# Enable ACME and force SSL
|
2023-08-23 20:56:24 +02:00
|
|
|
nginx.virtualHosts.${domain} = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
2022-11-18 17:00:20 +01:00
|
|
|
};
|
2023-09-06 14:22:56 +02:00
|
|
|
nginx.virtualHosts.${legacy_domain} = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/".return = "301 https://nc.ifsr.de";
|
|
|
|
};
|
2022-11-18 17:00:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
# ensure that postgres is running *before* running the setup
|
|
|
|
systemd.services."nextcloud-setup" = {
|
2022-11-18 17:51:09 +01:00
|
|
|
requires = [ "postgresql.service" ];
|
|
|
|
after = [ "postgresql.service" ];
|
2022-11-18 17:00:20 +01:00
|
|
|
};
|
2023-08-23 20:56:24 +02:00
|
|
|
|
|
|
|
# configure some settings automatically
|
|
|
|
systemd.services."phpfpm-nextcloud" =
|
|
|
|
let
|
|
|
|
occ = lib.getExe config.services.nextcloud.occ;
|
|
|
|
ldapConfig = rec {
|
|
|
|
ldapAgentName = "uid=search,ou=users,${ldapBase}";
|
|
|
|
ldapBase = config.services.portunus.ldap.suffix;
|
|
|
|
ldapBaseGroups = "ou=groups,${ldapBase}";
|
|
|
|
ldapBaseUsers = "ou=users,${ldapBase}";
|
|
|
|
ldapConfigurationActive = "1";
|
|
|
|
ldapEmailAttribute = "mail";
|
|
|
|
ldapGroupFilterObjectclass = "groupOfNames";
|
|
|
|
ldapGroupMemberAssocAttr = "member";
|
|
|
|
ldapHost = "localhost";
|
|
|
|
ldapPort = "389";
|
|
|
|
ldapUserDisplayName = "cn";
|
2023-08-23 22:52:53 +02:00
|
|
|
ldapUserFilterObjectclass = "posixAccount";
|
2023-08-23 20:56:24 +02:00
|
|
|
# generated by nextcloud
|
|
|
|
ldapGroupFilter = "(&(|(objectclass=groupOfNames)))";
|
2023-08-23 22:52:53 +02:00
|
|
|
ldapUserFilter = "(|(objectclass=posixAccount))";
|
|
|
|
ldapLoginFilter = "(&(|(objectclass=posixAccount))(uid=%uid))";
|
2023-08-23 20:56:24 +02:00
|
|
|
};
|
2023-08-23 22:12:06 +02:00
|
|
|
preStart = pkgs.writeScript "nextcloud-preStart" ''
|
2023-08-23 20:56:24 +02:00
|
|
|
# enable included LDAP app
|
|
|
|
${occ} app:enable user_ldap
|
|
|
|
|
|
|
|
# set up new LDAP config if it does not exist
|
|
|
|
if ! ${occ} ldap:show-config s01 > /dev/null; then
|
|
|
|
${occ} ldap:create-empty-config
|
|
|
|
fi
|
|
|
|
|
|
|
|
# update LDAP config
|
|
|
|
${lib.concatLines (lib.mapAttrsToList (name: value: "${occ} ldap:set-config s01 '${name}' '${value}'") ldapConfig)}
|
|
|
|
${occ} ldap:set-config s01 'ldapAgentPassword' $(cat ${config.sops.secrets.nextcloud_ldap_search.path})
|
|
|
|
'';
|
2023-08-23 22:12:06 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
# run the whole preStart as nextcloud user, so that the log won't be cluttered by lots of sudo calls
|
|
|
|
serviceConfig.ExecStartPre = "/run/wrappers/bin/sudo -u nextcloud --preserve-env=NEXTCLOUD_CONFIG_DIR --preserve-env=OC_PASS ${preStart}";
|
2023-08-23 20:56:24 +02:00
|
|
|
};
|
2022-11-18 17:00:20 +01:00
|
|
|
}
|