fruitbasket/modules/nextcloud.nix

97 lines
2.8 KiB
Nix
Raw Normal View History

2022-11-18 17:00:20 +01:00
{ config, pkgs, lib, ... }:
let
2022-12-17 19:12:41 +01:00
domain = "nc.${config.fsr.domain}";
2022-11-18 17:00:20 +01:00
in
{
sops.secrets = {
nextcloud_adminpass.owner = "nextcloud";
nextcloud_ldap_search = {
key = "portunus/search-password";
2022-11-18 17:00:20 +01:00
owner = "nextcloud";
};
};
services = {
postgresql = {
enable = true;
ensureUsers = [{
name = "nextcloud";
ensurePermissions = {
"DATABASE nextcloud" = "ALL PRIVILEGES";
};
}];
2022-11-18 17:00:20 +01:00
ensureDatabases = [ "nextcloud" ];
};
nextcloud = {
enable = true;
2023-05-25 22:58:14 +02:00
package = pkgs.nextcloud26; # Use current latest nextcloud package
enableBrokenCiphersForSSE = false; # disable the openssl warning
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";
dbuser = "nextcloud";
dbhost = "/run/postgresql";
2022-11-18 17:13:58 +01:00
dbname = "nextcloud";
2022-11-18 17:00:20 +01:00
adminpassFile = config.sops.secrets.nextcloud_adminpass.path;
adminuser = "root";
};
};
2022-11-18 17:40:12 +01:00
# Enable ACME and force SSL
nginx.virtualHosts.${domain} = {
enableACME = true;
forceSSL = true;
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
};
# 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";
ldapUserFilterObjectclass = "inetOrgPerson";
# generated by nextcloud
ldapGroupFilter = "(&(|(objectclass=groupOfNames)))";
ldapUserFilter = "(|(objectclass=inetOrgPerson))";
ldapLoginFilter = "(&(|(objectclass=inetOrgPerson))(uid=%uid))";
};
in
{
preStart = ''
# 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})
'';
};
2022-11-18 17:00:20 +01:00
}