From ef332b9af488a6249aa0ee5021d1653d9ac8f9a4 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Thu, 27 Nov 2025 14:00:07 +0100 Subject: [PATCH] fix: add support for nixpacks plan variables in buildtime environment --- app/Jobs/ApplicationDeploymentJob.php | 33 ++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 13938675a..5aa405aac 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -1409,6 +1409,35 @@ private function generate_buildtime_environment_variables() $envs->push($key.'='.escapeBashEnvValue($item)); }); + // Add all variables from nixpacks plan if this is a nixpacks build + // These include NIXPACKS_* variables and other build-time variables detected by nixpacks + if ($this->build_pack === 'nixpacks' && + isset($this->nixpacks_plan_json) && + $this->nixpacks_plan_json->isNotEmpty()) { + + $planVariables = data_get($this->nixpacks_plan_json, 'variables', []); + + if (! empty($planVariables)) { + if (isDev()) { + $this->application_deployment_queue->addLogEntry('[DEBUG] Adding '.count($planVariables).' nixpacks plan variables to buildtime.env'); + } + + foreach ($planVariables as $key => $value) { + // Skip COOLIFY_* and SERVICE_* as they're already added + if (str_starts_with($key, 'COOLIFY_') || str_starts_with($key, 'SERVICE_')) { + continue; + } + + $escapedValue = escapeBashEnvValue($value); + $envs->push($key.'='.$escapedValue); + + if (isDev()) { + $this->application_deployment_queue->addLogEntry("[DEBUG] Nixpacks var: {$key}={$escapedValue}"); + } + } + } + } + // Add SERVICE_NAME variables for Docker Compose builds if ($this->build_pack === 'dockercompose') { if ($this->pull_request_id === 0) { @@ -1462,10 +1491,9 @@ private function generate_buildtime_environment_variables() } } - // Add build-time user variables only + // Add user-defined build-time variables (these override nixpacks plan values if there's a conflict) if ($this->pull_request_id === 0) { $sorted_environment_variables = $this->application->environment_variables() - ->where('key', 'not like', 'NIXPACKS_%') ->where('is_buildtime', true) // ONLY build-time variables ->orderBy($this->application->settings->is_env_sorting_enabled ? 'key' : 'id') ->get(); @@ -1507,7 +1535,6 @@ private function generate_buildtime_environment_variables() } } else { $sorted_environment_variables = $this->application->environment_variables_preview() - ->where('key', 'not like', 'NIXPACKS_%') ->where('is_buildtime', true) // ONLY build-time variables ->orderBy($this->application->settings->is_env_sorting_enabled ? 'key' : 'id') ->get();