-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poetry Installs packages when running container instead of during build #657
Comments
This requires a bit of fiddling, but it can be fixed. |
I am experiencing something similar using python and venv. Here's a small { ... }:
{
languages.python = {
enable = true;
version = "3.12";
venv = {
enable = true;
requirements = ''
tqdm
'';
};
};
containers.test.name = "python-rebuilds-deps";
processes.test.exec = ''
python -c 'from tqdm import tqdm; import time; [time.sleep(0.2) for i in tqdm(range(10))]'
'';
} This makes it very unappealing to use |
I tried using only { pkgs, config, ... }:
{
packages = with pkgs; [
python312
python312Packages.tqdm
];
containers.processes.copyToRoot = null;
containers.test = {
name = "works-as-expected";
startupCommand = config.processes.test.exec;
};
processes.test.exec = ''
${pkgs.python312}/bin/python -c 'from tqdm import tqdm; import time; [time.sleep(0.2) for i in tqdm(range(10))]'
'';
} |
My messy attempt:
simplified devenv.nix
There might be lines that aren't really necessary. { pkgs, config, inputs, self, ... }:
{
languages.python.enable = true;
languages.python.package = pkgs.python310;
languages.python.poetry.enable = true;
languages.python.poetry.activate.enable = true;
languages.python.poetry.install.enable = !config.container.isBuilding;
containers.main.name = "main";
containers.main.startupCommand = "--help";
containers.main.entrypoint = let
cfg = config.languages.python;
bash = "${pkgs.bash}/bin/bash";
entrypoint = pkgs.writeScript "entrypoint" ''
#!${bash}
# Installing the root app during build resulted in a path like
# /build/ to be written to .pth
${cfg.poetry.package}/bin/poetry -C /app install --only-root
${cfg.poetry.package}/bin/poetry -C /app run mycli "''${@}"
'';
in [ entrypoint ];
containers.main.copyToRoot =
let
cfg = config.languages.python;
homeDir = "/app";
nix2container = inputs.nix2container.packages.${pkgs.stdenv.system};
app = pkgs.stdenv.mkDerivation {
name = "build-poetry-deps";
src = self;
buildPhase = ''
export XDG_CONFIG_HOME=$TMPDIR/.config
${cfg.poetry.package}/bin/poetry config virtualenvs.in-project true --local
${cfg.poetry.package}/bin/poetry config virtualenvs.create true --local
${cfg.poetry.package}/bin/poetry config cache-dir $TMPDIR/.cache --local
${cfg.poetry.package}/bin/poetry install --only main --no-root --no-directory --no-interaction --compile
'';
installPhase = ''
mkdir -p $out/tmp
mkdir -p $out${homeDir}
cp -R ./. $out${homeDir}/
'';
};
in (nix2container.nix2container.buildLayer {
copyToRoot = app;
}); |
Describe the bug
When creating a python poetry based container using the
devenv container
command, the poetry dependencies are installed when the container is ran and not when building the container. Additionally when running the container I'm getting this message:/nix/store/mnjksxz8alkwf6pa74a9j04h93p3y2sy-coreutils-9.3/bin/ln: failed to create symbolic link '/root/poetry_test/.venv': No such file or directory Creating virtualenv poetry-test in /.venv Using virtualenv: /.venv
To reproduce
I have created an example repo here that reproduces the issue.
devenv_poetry_container_test
Version
0.6.2
The text was updated successfully, but these errors were encountered: