coolify icon indicating copy to clipboard operation
coolify copied to clipboard

[Bug]: Nixpacks using UV fails from missing NIX ENV

Open m1guer opened this issue 1 month ago • 13 comments


Operating System: Ubuntu 22.x

Steps to Reproduce:

  1. Commit changes to GitHub.
  2. Wait for the deployment to start or initiate a force deployment.
  3. After a few seconds, the system will "crash" due to a missing environment variable.

Oops something is not okay, are you okay? 😢
#0 building with "default" instance using docker driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 2.77kB done
#1 DONE 0.0s
#2 [internal] load metadata for ghcr.io/railwayapp/nixpacks:ubuntu-1745885067
#2 DONE 0.5s
#3 [internal] load .dockerignore
#3 transferring context: 2B done
#3 DONE 0.0s
#4 [stage-0  1/11] FROM ghcr.io/railwayapp/nixpacks:ubuntu-1745885067@sha256:d45c89d80e13d7ad0fd555b5130f22a866d9dd10e861f589932303ef2314c7de
#4 DONE 0.0s
#5 [internal] load build context
#5 transferring context: 375.08kB 0.0s done
#5 DONE 0.1s
#6 [stage-0  3/11] COPY .nixpacks/nixpkgs-bc8f8d1be58e8c8383e683a06e1e1e57893fff87.nix .nixpacks/nixpkgs-bc8f8d1be58e8c8383e683a06e1e1e57893fff87.nix
#6 CACHED
#7 [stage-0  2/11] WORKDIR /app/
#7 CACHED
#8 [stage-0  4/11] RUN nix-env -if .nixpacks/nixpkgs-bc8f8d1be58e8c8383e683a06e1e1e57893fff87.nix && nix-collect-garbage -d
#8 CACHED
#9 [stage-0  5/11] RUN sudo apt-get update && sudo apt-get install -y --no-install-recommends curl wget
#9 CACHED
#10 [stage-0  6/11] COPY . /app/.
#10 DONE 0.1s
#11 [stage-0  7/11] RUN --mount=type=cache,id=eogo8s0cg4okc0kg8sskoogk-/root/cache/uv,target=/root/.cache/uv python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install uv== && uv sync --no-dev --frozen
#11 3.993
#11 3.993 [notice] A new release of pip is available: 24.2 -> 25.3
#11 3.993 [notice] To update, run: pip install --upgrade pip
#11 3.994 ERROR: Invalid requirement: 'uv==': Expected end or semicolon (after name and no valid version specifier)
#11 3.994     uv==
#11 3.994       ^
#11 ERROR: process "/bin/bash -ol pipefail -c python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install uv==$NIXPACKS_UV_VERSION && uv sync --no-dev --frozen" did not complete successfully: exit code: 1
------
> [stage-0  7/11] RUN --mount=type=cache,id=eogo8s0cg4okc0kg8sskoogk-/root/cache/uv,target=/root/.cache/uv python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install uv== && uv sync --no-dev --frozen:
3.993
3.993 [notice] A new release of pip is available: 24.2 -> 25.3
3.993 [notice] To update, run: pip install --upgrade pip
3.994 ERROR: Invalid requirement: 'uv==': Expected end or semicolon (after name and no valid version specifier)
3.994     uv==
3.994       ^
------
5 warnings found (use docker --debug to expand):
- SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "PASSWORD") (line 12)
- SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ENV "SECRET_KEY") (line 12)
- UndefinedVar: Usage of undefined variable '$NIXPACKS_PATH' (line 18)
- SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "PASSWORD") (line 11)
- SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "SECRET_KEY") (line 11)
Dockerfile:20
--------------------
18 |     ENV NIXPACKS_PATH=/opt/venv/bin:$NIXPACKS_PATH
19 |     COPY . /app/.
20 | >>> RUN --mount=type=cache,id=eogo8s0cg4okc0kg8sskoogk-/root/cache/uv,target=/root/.cache/uv python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install uv==$NIXPACKS_UV_VERSION && uv sync --no-dev --frozen
21 |
22 |     # build phase
--------------------
ERROR: failed to build: failed to solve: process "/bin/bash -ol pipefail -c python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install uv==$NIXPACKS_UV_VERSION && uv sync --no-dev --frozen" did not complete successfully: exit code: 1
exit status 1
Deployment failed. Removing the new version of your application.

m1guer avatar Nov 07 '25 21:11 m1guer

I'm having this same problem and here is a bit more info.

  • Building using nixpacks in my dev laptop works fine
  • Building on coolify correctly generates the ENV (note the NIXPACKS_UV_VERSION in variables

From: Generating nixpacks configuration with: nixpacks plan -f json --env ...

{
"providers": [],
"buildImage": "ghcr.io/railwayapp/nixpacks:ubuntu-1745885067",
"variables": {
"COOLIFY_BRANCH": "main",
"COOLIFY_CONTAINER_NAME": "jg4s8og0swok00og8sckws4k-043952948938",
"COOLIFY_FQDN": "nathan.cn02.woodburn.au,nathan.woodburn.au,nathan.woodburn/,nathan.woodburn.hns.link,nathanwoodburn,randomgenerator,podcast.woodburn.au",
"COOLIFY_RESOURCE_UUID": "jg4s8og0swok00og8sckws4k",
"COOLIFY_URL": "https://nathan.cn02.woodburn.au,https://nathan.woodburn.au,https://nathan.woodburn/,https://nathan.woodburn.hns.link,https://nathanwoodburn,https://randomgenerator,https://podcast.woodburn.au",
"NIXPACKS_METADATA": "python",
"NIXPACKS_UV_VERSION": "0.4.30",
"PIP_DEFAULT_TIMEOUT": "100",
"PIP_DISABLE_PIP_VERSION_CHECK": "1",
"PIP_NO_CACHE_DIR": "1",
"PYTHONDONTWRITEBYTECODE": "1",
"PYTHONFAULTHANDLER": "1",
"PYTHONHASHSEED": "random",
"PYTHONUNBUFFERED": "1",
"SOURCE_COMMIT": "c15a5d5a8be3410f1c14040f26810fbcef47f165",
"UV_PROJECT_ENVIRONMENT": "/opt/venv"
},
"phases": {
"install": {
"dependsOn": [
"setup"
],
"cmds": [
"python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install uv==$NIXPACKS_UV_VERSION && uv sync --no-dev --frozen"
],
"cacheDirectories": [
"/root/.cache/uv"
],
"paths": [
"/opt/venv/bin"
]
},
"setup": {
"nixPkgs": [
"python313",
"gcc"
],
"nixLibs": [
"zlib",
"stdenv.cc.cc.lib"
],
"nixOverlays": [],
"nixpkgsArchive": "bc8f8d1be58e8c8383e683a06e1e1e57893fff87"
}
},
"start": {
"cmd": "python main.py"
}
}
  • Building isn't able to get the ENV
#11 [stage-0 7/9] RUN --mount=type=cache,id=jg4s8og0swok00og8sckws4k-/root/cache/uv,target=/root/.cache/uv python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install uv== && uv sync --no-dev --frozen
#11 6.777
#11 6.777 [notice] A new release of pip is available: 24.2 -> 25.3
#11 6.777 [notice] To update, run: pip install --upgrade pip
#11 6.778 ERROR: Invalid requirement: 'uv==': Expected end or semicolon (after name and no valid version specifier)
#11 6.778     uv==
#11 6.778       ^
#11 ERROR: process "/bin/bash -ol pipefail -c python -m venv --copies /opt/venv && . /opt/venv/bin/activate && pip install uv==$NIXPACKS_UV_VERSION && uv sync --no-dev --frozen" did not complete successfully: exit code: 1

Full logs if you're interested https://upload.woodburn.au/inline/brv/nix_python_uv.log

Nathanwoodburn avatar Nov 08 '25 04:11 Nathanwoodburn

any updates on this?

m1guer avatar Nov 09 '25 13:11 m1guer

this actually solved my problem, could be a work around for now.

[phases.setup]
nixPkgs = ["python3", "postgresql_16.dev", "gcc"]
nixLibs = ["zlib", "stdenv.cc.cc.lib"]
aptPkgs = ["curl", "wget"]

[phases.install]
dependsOn = ["setup"]
cmds = [
  "python -m venv --copies /opt/venv",
  ". /opt/venv/bin/activate && pip install uv==0.5.11",
  ". /opt/venv/bin/activate && uv sync --no-dev --frozen"
]
paths = ["/opt/venv/bin"]

[phases.build]
....

[start]
....

[variables]
PYTHONUNBUFFERED = "1"
PYTHONDONTWRITEBYTECODE = "1"
PYTHONFAULTHANDLER = "1"
PYTHONHASHSEED = "random"
PIP_NO_CACHE_DIR = "1"
PIP_DISABLE_PIP_VERSION_CHECK = "1"
PIP_DEFAULT_TIMEOUT = "100"
UV_PROJECT_ENVIRONMENT = "/opt/venv"

m1guer avatar Nov 11 '25 22:11 m1guer

Could anyone provide a reproducable example repo?

Cinzya avatar Nov 11 '25 22:11 Cinzya

Could anyone provide a reproducable example repo?

I'm out of time to do that actually, but there is nothing especial in my repo, only different thing that I have rn is a Procfile.

m1guer avatar Nov 11 '25 23:11 m1guer

Here is a simple example repo: https://github.com/yaserahmady/coolify-uv-bug-repo

It used to work exactly like this (I followed this article the first time) but now randomly stopped deploying. I haven't upgraded Coolify since I first started using it, it's still v4.0.0-beta.442 in Docker.

The quickest and simplest workaround right now is to use requirements.txt (uv pip compile pyproject.toml -o requirements.txt).

failed-deployment.log

yaserahmady avatar Nov 12 '25 08:11 yaserahmady

I'm also hitting this bug all of a sudden without changing anything in my repo

RayBB avatar Nov 13 '25 03:11 RayBB

me too

iamashwin99 avatar Nov 18 '25 06:11 iamashwin99

Here is a simple example repo: https://github.com/yaserahmady/coolify-uv-bug-repo

It used to work exactly like this (I followed this article the first time) but now randomly stopped deploying. I haven't upgraded Coolify since I first started using it, it's still v4.0.0-beta.442 in Docker.

The quickest and simplest workaround right now is to use requirements.txt (uv pip compile pyproject.toml -o requirements.txt).

failed-deployment.log

Im using setup from the same blog and am getting the same error. Interestingly, when I try to manually set the env variable, it won't let me specify the env var as available at build time (the check box goes away)

scott-williams-2002 avatar Nov 21 '25 03:11 scott-williams-2002

Also hitting this

StromFLIX avatar Nov 23 '25 16:11 StromFLIX

I'm having this same problem. Repos that used to build with no problems now face this when trying to redeploy. I've had to uv pip freeze > requirements.txt and do without uv in the Coolify server. Which is less than ideal... Any fixes/workarounds?

Dijkie85 avatar Nov 23 '25 17:11 Dijkie85

Hi! Any updates on this?

Dijkie85 avatar Dec 05 '25 13:12 Dijkie85

nixpacks build args are fixed in latest version (they are no longer empty), so this should be resolved in v452

djsisson avatar Dec 05 '25 14:12 djsisson

nixpacks build args are fixed in latest version (they are no longer empty), so this should be resolved in v452

confirmed this fixed my deployment issues with UV. i did have to update from the base installer script after removing my docker coolify processes, was failing via UI updates.

basedchris avatar Dec 16 '25 01:12 basedchris