How can I get borg access to the nextcloud-occ path?

I’d like to incorporate the nextcloud-occ command maintenance:mode --on inside a pre-hook in my borg backup service module, but borg doesn’t seem to have access to the nextcloud-occ path and throws a command not found error in the logs. The systemctl commands work fine. Here is the code snippet I’ve tried:

  services.borgbackup = {
    jobs = {
      cypress = {
        archiveBaseName = "cypress";
        dateFormat = "+%Y.%m.%d-T%H:%M:%S";
        doInit = true; # run borg init if backup directory does not already contain the repository
        failOnWarnings = false;
        extraCreateArgs = [
          "--progress"
          "--stats"
        ];
        startAt = "*-*-* 02:30:00"; # everyday at 2:30am
        preHook = ''
          echo "spinning down services and starting sql database dumps"
          ${lib.getExe config.services.nextcloud.occ} maintenance:mode --on
          sleep 10 
          systemctl stop lldap.service
          systemctl start postgresqlBackup-lldap.service
          systemctl start postgresqlBackup-nextcloud.service
          sleep 120
        '';
        postHook = ''
          echo "spinning services back up"
          ${lib.getExe config.services.nextcloud.occ} maintenance:mode --off
          systemctl start lldap.service
        '';
        repo = "borg@${configVars.thinkpadLanIp}:."; # this automatically picks up the location of the remote borg repository assuming remote is running a nixos borg module
        encryption = {
          mode = "repokey-blake2"; # encrypt using password and save encryption key inside repository
          passCommand = "cat ${config.sops.secrets.borgCryptPasswd.path}";
        };
        environment = { 
          BORG_RSH = "ssh -p 28764 -o StrictHostKeyChecking=no -i /root/.ssh/borg-ed25519-cypress";
          BORG_RELOCATED_REPO_ACCESS_IS_OK = "yes"; # supress warning about repo location being moved since last backup (e.g. changing directory location or IP address)
        };
        compression = "auto,zstd,8";
        paths = [
          "/var/lib/private/lldap"
          "/var/lib/nextcloud"
          "/var/lib/redis-nextcloud"
          "/var/lib/tailscale"
          "/var/backup/postgresql/lldap.sql.gz"
          "/var/backup/postgresql/nextcloud.sql.gz"
        ];
        prune.keep = {
          daily = 7; # keep the last seven daily archives
          monthly = 3; # keep the last three monthly archives
        };
      };
    };
  };

Can you share the actual logs, please?
Also, a set -x at the beginning of preHook may help for further details.

Here are the logs with set -x:

Jan 27 15:26:21 cypress systemd[1]: Started BorgBackup job cypress.
Jan 27 15:26:22 cypress borgbackup-job-cypress-start[425311]: + echo 'spinning down services and starting sql database dumps'
Jan 27 15:26:22 cypress borgbackup-job-cypress-start[425311]: spinning down services and starting sql database dumps
Jan 27 15:26:22 cypress borgbackup-job-cypress-start[425311]: + /nix/store/j4f1mnvnxm79kqa0azdpnp4axg5r83yn-nextcloud-occ/bin/nextcloud-occ maintenance:mode --on
Jan 27 15:26:22 cypress sudo[425314]:     root : PWD=/nix/store/5s96wn0fcja5xfd8w6f288inzh6ms2ng-nextcloud-30.0.5-with-apps ; USER=nextcloud ; COMMAND=/nix/store/6wgd8c9vq93mqxzc7jhkl86mv6qbc360-coreutils-9.5/bin/env NEXTCLOUD_CONFIG_DIR=/var/lib/nextcloud/config /nix/store/dmyv2kr23zlzi0wlhf42llzcsck4n0fz-php-with-extensions-8.3.15/bin/php occ maintenance:mode --on
Jan 27 15:26:22 cypress sudo[425314]: pam_unix(sudo:session): session opened for user nextcloud(uid=993) by (uid=0)
Jan 27 15:26:22 cypress borgbackup-job-cypress-start[425316]: Cannot write into "config" directory!
Jan 27 15:26:22 cypress borgbackup-job-cypress-start[425316]: This can usually be fixed by giving the web server write access to the config directory.
Jan 27 15:26:22 cypress borgbackup-job-cypress-start[425316]: But, if you prefer to keep config.php file read only, set the option "config_is_read_only" to true in it.
Jan 27 15:26:22 cypress borgbackup-job-cypress-start[425316]: See https://docs.nextcloud.com/server/30/go.php?to=admin-config
Jan 27 15:26:22 cypress sudo[425314]: pam_unix(sudo:session): session closed for user nextcloud
Jan 27 15:26:22 cypress borgbackup-job-cypress-start[425311]: + sleep 10

I don’t see any command not found errors here. And the non-writable config thing was (IIRC) non-fatal?

My mistake… no command not found errors. What is happening is that Cannot write into "config" directory! error is preventing the command from turning maintenance mode on, which requires writing into nextcloud’s config.php file. What I don’t understand is that running the nextcloud-occ maintenance:mode --on command from the terminal as my regular user (i.e. not in this borg preHook) can/does modify the config.php file and works just fine.

Bump for any ideas…still can’t get this to turn on nextcloud maintenance mode.