From 8bb083f55b5e77ff9d8fd821ada7eb74338e3414 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 28 Feb 2026 19:15:11 +0100 Subject: [PATCH] nixos/nextcloud: restore using ExecCondition Since systemd 259 it's possible to access service credentials from `ExecCondition`. --- nixos/modules/services/web-apps/nextcloud.nix | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/nixos/modules/services/web-apps/nextcloud.nix b/nixos/modules/services/web-apps/nextcloud.nix index cc54ef70bbcb..cff0f6ff1872 100644 --- a/nixos/modules/services/web-apps/nextcloud.nix +++ b/nixos/modules/services/web-apps/nextcloud.nix @@ -1472,21 +1472,12 @@ in # NOTE: In contrast to the occ wrapper script running phpCli directly will not # set NEXTCLOUD_CONFIG_DIR by itself currently. environment.NEXTCLOUD_CONFIG_DIR = "${datadir}/config"; - script = '' - # NOTE: This early returns the script when nextcloud is in maintenance mode - # or needs `occ upgrade`. Using ExecCondition= is not possible here - # because it doesn't work with systemd credentials. - if [[ $(${lib.getExe occ} status --output=json | ${lib.getExe pkgs.jq} '. | if .maintenance or .needsDbUpgrade then "skip" else "" end' --raw-output) == "skip" ]]; then - echo "Nextcloud is in maintenance mode or needs DB upgrade, exiting." - exit 0 - fi - - ${phpCli} -f ${webroot}/cron.php - ''; serviceConfig = { Type = "exec"; User = "nextcloud"; KillMode = "process"; + ExecCondition = "${phpCli} -f ${webroot}/occ status --exit-code"; + ExecStart = "${phpCli} -f ${webroot}/cron.php"; LoadCredential = runtimeSystemdCredentials; }; }; @@ -1503,14 +1494,6 @@ in nextcloud-update-db = { after = [ "nextcloud-setup.service" ]; script = '' - # NOTE: This early returns the script when nextcloud is in maintenance mode - # or needs `occ upgrade`. Using ExecCondition= is not possible here - # because it doesn't work with systemd credentials. - if [[ $(${lib.getExe occ} status --output=json | ${lib.getExe pkgs.jq} '. | if .maintenance or .needsDbUpgrade then "skip" else "" end' --raw-output) == "skip" ]]; then - echo "Nextcloud is in maintenance mode or needs DB upgrade, exiting." - exit 0 - fi - ${lib.getExe occ} db:add-missing-columns ${lib.getExe occ} db:add-missing-indices ${lib.getExe occ} db:add-missing-primary-keys @@ -1519,6 +1502,7 @@ in Type = "exec"; User = "nextcloud"; LoadCredential = runtimeSystemdCredentials; + ExecCondition = "${phpCli} -f ${webroot}/occ status --exit-code"; }; };