Basic flake: run existing (python, bash) script

There was recently a thread with someone else discussing the same woes Why is it so hard to use a Python package?

Both with create the virtualenv (only if it doesn’t seem to exist and have a bin/python that exists) and install dependencies in pypiDeps .

For “I want to use the venv in the current directory”, I wonder if direnv / Python would be more suitable. Home · direnv/direnv Wiki · GitHub

Rather, I think having a nix run application make use of the current directory, and installing runtime dependencies with pip in order to do so, isn’t very idiomatic/‘clean’.

e.g. I updated my gist with your runner example, and

nix run git+https://gist.github.com/rgoulter/35daa2c1152ac0b4381fd38c4ddb4069#runner

for me runs

/nix/store/nznji0b6g1r2gl97bb6m27irqvppzn03-python3-3.10.4-env/bin/python3.10
v0.1.4

The Nix for the runner being:


      runner = pkgs.writeShellApplication
        {
          name = "runme";
          checkPhase = ":";
          runtimeInputs = [pythonWithSimplenet];
          text = ''
            "${pythonWithSimplenet}/bin/python" ${./foo.py}
          '';
        };

and pythonWithSimplenet being:

    simplenet = ps: ps.callPackage ./simplenet.nix { };
    pythonWithSimplenet = pkgs.python3.withPackages (ps: [ (simplenet ps) ]);

and the Nix description of simplenet as a Python package is in the flake. (With caveats that I skipped including dependencies for running the tests; and the numpy in nixpkgs that the flake points to is older than your simplenet required).