diff --git a/machines/gerd/services/nextcloud.nix b/machines/gerd/services/nextcloud.nix index 26dde09..e9d0b49 100644 --- a/machines/gerd/services/nextcloud.nix +++ b/machines/gerd/services/nextcloud.nix @@ -30,7 +30,6 @@ let ldapBase = config.mine.shared.settings.ldap.dc; ldapBaseUsers = config.mine.shared.settings.ldap.dc; ldapBaseGroups = config.mine.shared.settings.ldap.dc; - ldapConfigurationActive = 1; ldapLoginFilter = "(&(objectclass=person)(${config.mine.shared.settings.ldap.attr.uid}=%uid))"; # EDIT: nextcloud_users group, contains the users who can login to Nextcloud @@ -43,31 +42,33 @@ let ldapEmailAttribute = config.mine.shared.settings.ldap.attr.email; ldapUserFilterMode = 1; ldapExpertUsernameAttr = config.mine.shared.settings.ldap.attr.uid; + ldapConfigurationActive = 1; }; - ldap_commands = lib.mapAttrsToList (n: v: "${occ} ldap:set-config s01 ${n} '${builtins.toString v}'") ldap_settings; + ldap_commands = lib.mapAttrsToList (n: v: "${occ} ldap:set-config $NEW_CONFIG_ID ${n} '${builtins.toString v}'") ldap_settings; in pkgs.writeShellScript "nextcloud-add-ldap.sh" '' # enable ldap service, remove config and create new empty one ${occ} app:install user_ldap ${occ} app:enable user_ldap - # ensure previous configs are deleted - CONFIGS=$(${occ} ldap:show-config --output=json | ${pkgs.jq}/bin/jq -r '. | keys | .[]') - echo "$CONFIGS" | while read configId; do - ${occ} ldap:delete-config "$configId" - done - # create new empty config - ${occ} ldap:create-empty-config + NEW_CONFIG_ID="$(${occ} ldap:create-empty-config -p)" # setup ldap password BIND_USERPASS="$(cat $CREDENTIALS_DIRECTORY/lldap-bind-user-pass)" - ${occ} ldap:set-config s01 ldapAgentPassword "$BIND_USERPASS" + ${occ} ldap:set-config $NEW_CONFIG_ID ldapAgentPassword "$BIND_USERPASS" + # set settings + ${builtins.concatStringsSep "\n" ldap_commands} + + # delete all other configurations + CONFIGS=$(${occ} ldap:show-config --output=json | ${pkgs.jq}/bin/jq -r '. | keys | .[]') + echo "$CONFIGS" | while read CONFIG_ID; do + if [[ "$NEW_CONFIG_ID" != "$CONFIG_ID" ]]; then + ${occ} ldap:delete-config "$CONFIG_ID" + fi + done # promote ldap admin group to admins ${occ} ldap:promote-group ${config.mine.shared.settings.ldap.groups.admin} || true - - # set settings - ${builtins.concatStringsSep "\n" ldap_commands} ''; # script for resetting nextcloud admin password on each startup