Hi,
I’m trying to make an editable python environment using a nix flake. I want to install my project in editable mode, and its dependencies.
My understanding is that the poetry2nix.mkPoetryEnv
helper was created for this purpose, however I have had trouble getting it to work as I hoped.
I have the following flake, that does what I need, but has some shortfalls:
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, poetry2nix }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
_poetry2nix = poetry2nix.lib.mkPoetry2Nix { inherit pkgs; };
myEnv = _poetry2nix.mkPoetryEnv {
projectDir = ./.;
editablePackageSources = {
myProject = "${builtins.getEnv "PWD"}/src";
};
};
in {
devShells.default = pkgs.mkShell {
inputsFrom = [ myEnv.env ];
packages = [ pkgs.poetry ];
};
});
}
It’s issues are:
- It relies on
$PWD
being the local root of the project. If I do./.
, it points to the nix store and doesn’t see the edits I make. - I need to use
--impure
when I runnix develop
, presumably because when I make edits these are propagated to the nix store?
I have three questions:
- Is a
shell.nix
file a better application for this? I’m not sure of best-practices around poetry2nix. - Is there a more elegant way of setting
editablePackageSources
, that doesn’t rely on$PWD
being the project root? - What is
myEnv
, and what ismyEnv.env
(python
is not found, if I just passmy_env
tomkShell.fromInputs
)?
Many thanks for any help!