cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
4.04k stars 303 forks source link

Python package binaries from imported devenv not available #1400

Open mrfelton opened 3 weeks ago

mrfelton commented 3 weeks ago

Describe the bug

I have a composable devenv like so:

devenv.yaml
devenv.nix
├── devenv
│   └── mkdocs
│       ├── devenv.yaml
│       ├── devenv.nix
│       └── pyproject.toml

In the top level devenv.yaml I have something like this:

inputs:
  nixpkgs:
    url: github:cachix/devenv-nixpkgs/rolling
imports:
  - ./devenv/mkdocs

In the ./devenv/mkdocs/devenv.nix I set up a python env:

{ pkgs, ... }:

{
  languages.python.enable = true;
  languages.python.venv.enable = true;
  languages.python.poetry.enable = true;
  languages.python.poetry.activate.enable = true;
  languages.python.poetry.install.enable = true;
}

with ./devenv/mkdocs/pyproject.toml like so (truncated for brevity):

[tool.poetry.dependencies]
python = ">=3.10,<3.12"
mkdocs = "^1.6.0"

From directly within the devenv/mkdocs devenv I can use python and I can use the packages installed by poetry, eg mkdocs.

❯ which python
/Users/tom/workspace/devenv/mkdocs/.venv/bin/python

❯ which mkdocs
/Users/tom/workspace/devenv/mkdocs/.venv/bin/mkdocs

Problem: From the top level devenv (which imports the mkdocs one) I can use the python binary, but not the ones installed by poetry such as mkdocs.

❯ which python
/Users/tom/workspace/.devenv/state/venv/bin/python

❯ which mkdocs
mkdocs not found

Expectation: I expect to be be able to use the things installed from the imported devenvs poetry venv

Version

❯ devenv version
devenv 1.0.8 (aarch64-darwin)
sandydoo commented 3 weeks ago

It should also warn you that pyproject.toml is missing, which is a sign that we're working from the top-level directory.

The module is designed to work from the top-level directory. Composing devenvs like this is tricky, because Nix doesn't have a reliable way of letting us know where an option is defined, e.g. mkdocs/devenv.nix. If we add an option to specify the working directory for the python project, then only one of the devenv's will work, which brings us back full circle.

mrfelton commented 3 weeks ago

Best I came up with so far is adding an alias to the binaries that I want to share into the top level devenv:

e.g.

# scripts.mkdocs.exec = lib.mkForce "$DEVENV_ROOT/devenv/mkdocs/.venv/bin/mkdocs $@";

Kinda janky, but sorta works.