target / lorri

Your project's nix-env
Apache License 2.0
993 stars 69 forks source link

`shell.nix` file works with nix-shell, but lorri fails to build #468

Open samuela opened 4 years ago

samuela commented 4 years ago

Describe the bug I have a shell.nix file based on section 15.17.3.6 of https://nixos.org/nixpkgs/manual/. It works as expected with nix-shell, but lorri fails to build it.

To Reproduce

# requirements.txt
taichi>=0.6.16
matplotlib
numpy
opencv-python
scipy
# shell.nix
{ pkgs ? import <nixpkgs> {} }:

let
  venvDir = "./.venv";
in pkgs.mkShell {
  buildInputs = [
    pkgs.python3
  ];

  shellHook = ''
    if [ -d "${venvDir}" ]; then
      echo "Virtualenv '${venvDir}' already exists"
    else
      echo "Creating virtualenv '${venvDir}'"
      ${pkgs.python3Packages.python.interpreter} -m venv "${venvDir}"
    fi

    source "${venvDir}/bin/activate"

    pip install -r ./requirements.txt
  '';
}
❯ nix-shell shell.nix
Virtualenv './.venv' already exists
Requirement already satisfied: taichi>=0.6.16 in ./.venv/lib/python3.8/site-packages (from -r ./requirements.txt (line 1)) (0.6.24)
...
WARNING: You are using pip version 20.1.1; however, version 20.2.1 is available.
You should consider upgrading via the '/home/skainswo/dev/difftaichi/.venv/bin/python3.8 -m pip install --upgrade pip' command.
(.venv) 
[nix-shell:~/dev/difftaichi]$

But lorri fails because it says it can't find requirements.txt:

❯ journalctl --user -u lorri -f
Aug 08 18:32:39 skainswo-X58A-UD3R lorri[115591]: Aug 08 18:32:39.610 INFO build status, message: BuildEvent(Started { nix_file: NixFile("/home/skainswo/dev/difftaichi/shell.nix"), reason: FilesChanged(["/home/skainswo/dev/difftaichi/shell.nix"]) })
Aug 08 18:32:45 skainswo-X58A-UD3R lorri[115591]: Aug 08 18:32:45.081 INFO build status, message: BuildEvent(Failure { nix_file: NixFile("/home/skainswo/dev/difftaichi/shell.nix"), failure: Exit { cmd: "\"nix-build\" \"--out-link\" \"/tmp/.tmpeg7JLQ/result\" \"--\" \"/tmp/.tmpz021A0/result\"", status: Some(100), logs: [LogLine("these derivations will be built:"), LogLine("  /nix/store/695wbp7q9gh7lj04ybyi0vvl97sf9wbn-lorri-keep-env-hack-nix-shell.drv"), LogLine("building \'/nix/store/695wbp7q9gh7lj04ybyi0vvl97sf9wbn-lorri-keep-env-hack-nix-shell.drv\'..."), LogLine("Creating virtualenv \'./.venv\'"), LogLine("ERROR: Could not open requirements file: [Errno 2] No such file or directory: \'./requirements.txt\'"), LogLine("builder for \'/nix/store/695wbp7q9gh7lj04ybyi0vvl97sf9wbn-lorri-keep-env-hack-nix-shell.drv\' failed with exit code 1"), LogLine("error: build of \'/nix/store/695wbp7q9gh7lj04ybyi0vvl97sf9wbn-lorri-keep-env-hack-nix-shell.drv\' failed")] } })

Expected behavior Lorri to successfully build and activate the environment.

Metadata

$ lorri info
error: The following required arguments were not provided:
    --shell-file <nix_file>

USAGE:
    lorri info --shell-file <nix_file>

For more information try --help
$ uname -a
Linux skainswo-X58A-UD3R 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 GNU/Linux

Additional context

n/a

Ptival commented 3 years ago

I encountered the same problem, and thought I could solve it by just:

    pip install -r ${./requirements.txt}

so as to have the requirements.txt path be resolved w.r.t. where the file originally lives.

However, I am still encoutering lorri issues with this:

image

Ptival commented 3 years ago

Actually, it works with an empty requirements file.

What fails is when the derivation attempts to do impure things, like git clone-ing a repository, or reaching out to the Python package server. I'm not sure I understand how this is not a problem for the nix-shell invocation, and how it differs from what lorri attempts when building the derivation.