fruitbasket/modules/nextcloud.nix

100 lines
3.2 KiB
Nix
Raw Permalink Normal View History

2022-11-18 17:00:20 +01:00
{ config, pkgs, lib, ... }:
let
2023-11-08 18:40:11 +01:00
domain = "nc.${config.networking.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 = {
nextcloud = {
enable = true;
2023-11-09 18:03:04 +01:00
configureRedis = true;
2024-06-21 14:59:46 +02:00
package = pkgs.nextcloud29;
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";
};
# postgres database is configured automatically
database.createLocally = true;
2023-11-09 15:35:26 +01:00
# enable HEIC image preview
2024-06-21 13:31:41 +02:00
settings.enabledPreviewProviders = [
2023-11-09 15:35:26 +01:00
"OC\\Preview\\BMP"
"OC\\Preview\\GIF"
"OC\\Preview\\JPEG"
"OC\\Preview\\Krita"
"OC\\Preview\\MarkDown"
"OC\\Preview\\MP3"
"OC\\Preview\\OpenDocument"
"OC\\Preview\\PNG"
"OC\\Preview\\TXT"
"OC\\Preview\\XBitmap"
"OC\\Preview\\HEIC"
];
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 = "posixAccount";
# generated by nextcloud
ldapGroupFilter = "(&(|(objectclass=groupOfNames)))";
ldapUserFilter = "(|(objectclass=posixAccount))";
ldapLoginFilter = "(&(|(objectclass=posixAccount))(uid=%uid))";
};
preStart = pkgs.writeScript "nextcloud-preStart" ''
# enable included LDAP app
${occ} app:enable user_ldap
2023-11-08 18:40:11 +01:00
${occ} app:enable calendar
${occ} app:enable tasks
${occ} app:enable polls
# 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})
'';
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}";
};
2022-11-18 17:00:20 +01:00
}