How can I install a package into a nix shell from source for debugging using flakes, equivalent to python setup.py develop

147 views Asked by At

Is there a way to include a package into a nix shell from source, ie the path linking not to a copy of the code in the nix store but to the actual source code, for debugging purposes?

I.e. I'm searching for a nix flake equivalent to running

python setup.py develop

in a conda environment instead of install.

The closest I found is using a flake.nix like

{
    inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    outputs = { self, nixpkgs }:
    let
        pkgs = import nixpkgs { system = "x86_64-linux"; };
        python_library = pkgs.python3Packages.buildPythonPackage {
            pname = "python_library";
            version = "0.1";
            src = /home/user_name/python_library;
            doCheck = false;
        };
    in {
      defaultPackage.x86_64-linux = pkgs.buildEnv {
        name = "test-env";
        paths = [
          (pkgs.python3.withPackages(ps: [
            ps.numpy
            ps.scipy
            ps.matplotlib
            python_library
          ]))
          pkgs.spyder
        ];
      };
    };
}

Where python_library contains new code I wish to debug, e.g.

class Hello:
  def __init__(self):
    print("Hello!!! Hello!")

which I test via

>>> from python_library.test import Hello
>>> a=Hello()
Hello!!! Hello!

For changes in the code to take effect, I need to run

nix build
nix shell

which rebuilds the nix environment with the updated code, as long as the flake is not inside a git repository. However this rebuilding process can get quite annoying in more complex cases if there are a lot of bugs to fix and when always having to switch folder between the nix flake and the code to execute, so I was wondering if there is a way to write the flake in such a way that the nix store directly links to the source code, instead of copying it over, as is possible with anaconda? None of the nix develop commands appeared to do anything like that for me.

0

There are 0 answers