Build the backend with uv2nix from the upstream uv.lock #12

Open
opened 2026-11-09 20:50:35 +00:00 by martin · 0 comments
Owner

Summary

Replace the hand-maintained Python dependency pins in pkgs/backend/default.nix with a virtual
environment generated by uv2nix from upstream's committed backend/uv.lock. This should remove most
of the packaging code and keep the packaged application's behaviour unchanged.

Context

  • pkgs/backend/default.nix is 232 lines; roughly lines 12–161 hand-build nine packages with source
    hashes: extruct 0.17.0, flask-basicauth 0.2.0, flask-apscheduler 1.13.1, sqlite-icu 1.0,
    mlextend 0.23.1, dbscan1d 0.2.4, uwsgi (git commit 6cbb2177), uwsgi-tools 1.1.1 and
    sqlalchemy 2.1.8, plus patches for sqlalchemy (test exclusions, Cython sed) and
    ingredient-parser-nlp (disable NLTK download on import).
  • Upstream v0.8.1 ships backend/pyproject.toml (PEP 621, requires-python = ">=3.14") and
    backend/uv.lock (673 KB), and builds its Docker image with uv sync --no-dev from that lock. The
    Nix package is the only consumer not reading the authoritative resolution.
  • Alternatives considered: poetry2nix is unmaintained and would need a poetry.lock that does not
    exist; pip2nix, pynixify and pypi2nix are abandoned and have no lockfile; python2nix is discontinued.
    uv2nix with pyproject.nix and pyproject-build-systems matches the existing lock input and is
    maintained.
  • The NixOS module consumes pythonPath, python3Packages.python, python3Packages.gunicorn and
    nltkData from the backend derivation, so this changes services/default.nix as well as the package.

Proposed approach

  • Add flake inputs pyproject-nix, uv2nix and pyproject-build-systems (all following nixpkgs).
  • Load the workspace from ${src}/backend, build with sourcePreference = "wheel" plus
    pyproject-build-systems.overlays.wheel, and select the interpreter from the lock's
    requires-python (pkgs.python314).
  • Produce the runtime environment with mkVirtualEnv and keep the existing application source copy at
    $out/opt/kitchenowl and the nltkData passthru.
  • Keep only overrides uv.lock cannot express: sqlite-icu (pkg-config, icu, sqlite), uwsgi
    (libxcrypt plus a setuptools-scm build system) and the ingredient-parser-nlp patch.
  • Decide how gunicorn is supplied, since it is not in upstream's lock: add it from nixpkgs to the
    virtualenv, or align the module with upstream's uwsgi entrypoint.

Risks to validate

  • Virtualenv execution replaces the current PYTHONPATH wiring for migrations, the default-item
    upgrade and gunicorn; tests.nix covers postgres, sqlite, open registration and NLTK nodes.
  • The local project declares no [build-system]; confirm uv2nix can build it or exclude it from the
    dependency spec.
  • Lock-derived packages are not in the nixpkgs binary cache, so the first build is much more expensive
    than today's mostly-substituted set.
  • The lock replaces the current deliberate deviations (sqlalchemy 2.1.8, uwsgi git commit); verify
    application behaviour and tests with the locked versions.
  • Binary wheels in litellm's dependency tree are patched automatically, but may still need extra
    system libraries.

Scope

  • pkgs/backend/default.nix, services/default.nix execution wiring, flake.nix inputs, and the
    build documentation in AGENTS.md where commands or caveats change.
  • The Flutter frontend packaging is out of scope.

Acceptance criteria

  • pkgs/backend/default.nix no longer pins package versions or hashes; runtime dependencies come
    from upstream's backend/uv.lock.
  • nix build .#kitchenowl-backend succeeds and the environment contains the lock's default
    dependency set without the dev group.
  • The module runs migrations, the default-item upgrade and the WSGI server from the generated
    environment without relying on PYTHONPATH.
  • nix flake check passes, including all four VM test nodes and the formatting check.
  • just update-version needs no backend-specific edits, and AGENTS.md documents the new
    workflow and any remaining overrides.
  • Overrides that are no longer needed (sqlalchemy, extruct, dbscan1d, mlxtend, ...) are
    gone, and any that remain are explained.

Dependencies

  • No blocking prerequisites. #11 moves this repository to Personal; this issue transfers with it and
    can be labelled there (type/refactor proposed) once the organization labels are inherited.
## Summary Replace the hand-maintained Python dependency pins in `pkgs/backend/default.nix` with a virtual environment generated by uv2nix from upstream's committed `backend/uv.lock`. This should remove most of the packaging code and keep the packaged application's behaviour unchanged. ## Context - `pkgs/backend/default.nix` is 232 lines; roughly lines 12–161 hand-build nine packages with source hashes: `extruct` 0.17.0, `flask-basicauth` 0.2.0, `flask-apscheduler` 1.13.1, `sqlite-icu` 1.0, `mlextend` 0.23.1, `dbscan1d` 0.2.4, `uwsgi` (git commit `6cbb2177`), `uwsgi-tools` 1.1.1 and `sqlalchemy` 2.1.8, plus patches for `sqlalchemy` (test exclusions, Cython sed) and `ingredient-parser-nlp` (disable NLTK download on import). - Upstream v0.8.1 ships `backend/pyproject.toml` (PEP 621, `requires-python = ">=3.14"`) and `backend/uv.lock` (673 KB), and builds its Docker image with `uv sync --no-dev` from that lock. The Nix package is the only consumer not reading the authoritative resolution. - Alternatives considered: poetry2nix is unmaintained and would need a `poetry.lock` that does not exist; pip2nix, pynixify and pypi2nix are abandoned and have no lockfile; python2nix is discontinued. uv2nix with `pyproject.nix` and `pyproject-build-systems` matches the existing lock input and is maintained. - The NixOS module consumes `pythonPath`, `python3Packages.python`, `python3Packages.gunicorn` and `nltkData` from the backend derivation, so this changes `services/default.nix` as well as the package. ## Proposed approach - Add flake inputs `pyproject-nix`, `uv2nix` and `pyproject-build-systems` (all following `nixpkgs`). - Load the workspace from `${src}/backend`, build with `sourcePreference = "wheel"` plus `pyproject-build-systems.overlays.wheel`, and select the interpreter from the lock's `requires-python` (`pkgs.python314`). - Produce the runtime environment with `mkVirtualEnv` and keep the existing application source copy at `$out/opt/kitchenowl` and the `nltkData` passthru. - Keep only overrides `uv.lock` cannot express: `sqlite-icu` (pkg-config, icu, sqlite), `uwsgi` (libxcrypt plus a `setuptools-scm` build system) and the `ingredient-parser-nlp` patch. - Decide how gunicorn is supplied, since it is not in upstream's lock: add it from nixpkgs to the virtualenv, or align the module with upstream's uwsgi entrypoint. ## Risks to validate - Virtualenv execution replaces the current `PYTHONPATH` wiring for migrations, the default-item upgrade and gunicorn; `tests.nix` covers postgres, sqlite, open registration and NLTK nodes. - The local project declares no `[build-system]`; confirm uv2nix can build it or exclude it from the dependency spec. - Lock-derived packages are not in the nixpkgs binary cache, so the first build is much more expensive than today's mostly-substituted set. - The lock replaces the current deliberate deviations (`sqlalchemy` 2.1.8, `uwsgi` git commit); verify application behaviour and tests with the locked versions. - Binary wheels in `litellm`'s dependency tree are patched automatically, but may still need extra system libraries. ## Scope - `pkgs/backend/default.nix`, `services/default.nix` execution wiring, `flake.nix` inputs, and the build documentation in `AGENTS.md` where commands or caveats change. - The Flutter frontend packaging is out of scope. ## Acceptance criteria - [ ] `pkgs/backend/default.nix` no longer pins package versions or hashes; runtime dependencies come from upstream's `backend/uv.lock`. - [ ] `nix build .#kitchenowl-backend` succeeds and the environment contains the lock's default dependency set without the `dev` group. - [ ] The module runs migrations, the default-item upgrade and the WSGI server from the generated environment without relying on `PYTHONPATH`. - [ ] `nix flake check` passes, including all four VM test nodes and the formatting check. - [ ] `just update-version` needs no backend-specific edits, and `AGENTS.md` documents the new workflow and any remaining overrides. - [ ] Overrides that are no longer needed (`sqlalchemy`, `extruct`, `dbscan1d`, `mlxtend`, ...) are gone, and any that remain are explained. ## Dependencies - No blocking prerequisites. #11 moves this repository to `Personal`; this issue transfers with it and can be labelled there (`type/refactor` proposed) once the organization labels are inherited.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Personal/kitchenowl-flake#12
No description provided.