nix-community / lorri

Your project’s nix-env [maintainer=@Profpatsch,@nyarly]
Apache License 2.0
638 stars 24 forks source link

Unable to use pythonPackages.venvShellHook #75

Open sephii opened 2 years ago

sephii commented 2 years ago

Describe the bug

Using lorri with pythonPackages.venvShellHook as mentioned in the nixpkgs docs results in an error.

To Reproduce

Create a shell.nix file with the following contents:

{ pkgs ? import (builtins.fetchGit {
    url = "https://github.com/NixOS/nixpkgs";
    ref = "nixos-21.11";
    rev = "77aa71f66fd05d9e7b7d1c084865d703a8008ab7";
  }) { } }:
let
  pythonPackages = pkgs.python38Packages;
in pkgs.mkShell {
  name = "impurePythonEnv";

  buildInputs = [
    pythonPackages.venvShellHook
    pythonPackages.wheel
  ];

  venvDir = "./.venv";

  postVenvCreation = ''
    unset SOURCE_DATE_EPOCH
    pip install -r ./requirements.txt
  '';

  postShellHook = ''
    # allow pip to install wheels
    unset SOURCE_DATE_EPOCH
  '';
}

Put something in requirements.txt like django, and then run lorri shell. You’ll get the following error:

❯ lorri shell
lorri: building environment.......... done
Jan 20 09:34:46.604 ERRO Build failed. No cached environment available.
Build error: Nix process returned exit code 1.
$ "nix-build" "--out-link" "/tmp/.tmpoM4Zgu/result" "--" "/tmp/.tmpzQiyBN/result"
this derivation will be built:
  /nix/store/3jdfxdmqzrg9f17nv384vyf8r5x3r18a-lorri-keep-env-hack-impurePythonEnv.drv
building '/nix/store/3jdfxdmqzrg9f17nv384vyf8r5x3r18a-lorri-keep-env-hack-impurePythonEnv.drv'...
Using venvShellHook
Executing venvHook
Creating new venv environment in path: './.venv'
WARNING: The directory '/homeless-shelter/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.
ERROR: Could not open requirements file: [Errno 2] No such file or directory: './requirements.txt'
error: builder for '/nix/store/3jdfxdmqzrg9f17nv384vyf8r5x3r18a-lorri-keep-env-hack-impurePythonEnv.drv' failed with exit code 1;
       last 5 log lines:
       > Using venvShellHook
       > Executing venvHook
       > Creating new venv environment in path: './.venv'
       > WARNING: The directory '/homeless-shelter/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.
       > ERROR: Could not open requirements file: [Errno 2] No such file or directory: './requirements.txt'
       For full logs, run 'nix log /nix/store/3jdfxdmqzrg9f17nv384vyf8r5x3r18a-lorri-keep-env-hack-impurePythonEnv.drv'.

Expected behavior The Python virtual environment is created and activated.

Metadata

❯ lorri info --shell-file shell.nix
lorri version: 1.5
❯ uname -a
Linux midgar 5.10.81 #1-NixOS SMP Sun Nov 21 12:46:37 UTC 2021 x86_64 GNU/Linux