Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use devShell environment in package derivation #1132

Open
shishkin opened this issue Apr 15, 2024 · 5 comments
Open

Use devShell environment in package derivation #1132

shishkin opened this issue Apr 15, 2024 · 5 comments
Labels
question Further information is requested

Comments

@shishkin
Copy link

Is it possible to use shell environment in mkDerivation? I've setup a devenv shell environment and would like to reuse it for package building. I tried adding self.devShells.${system}.default to buildInputs of mkDerivation but that didn't get the required tools on the builder path.

The reason I'm doing this is that I have a python poertry environment that I wasn't able to get working on vanilla nix and was quite happy when it just worked in devenv.

@shishkin shishkin added the question Further information is requested label Apr 15, 2024
@domenkozar
Copy link
Member

@shishkin can you give a bit more explanation what you're trying to do?

@shishkin
Copy link
Author

I have a flake with devenv shell:

        devShells.default = devenv.lib.mkShell {
          inherit inputs pkgs;

            languages.python = {
              enable = true;
              package = pkgs.python3;
              poetry = {
                enable = true;
                activate.enable = true;
                install = {
                  enable = true;
                  installRootPackage = false;
                  quiet = false;
                };
              };
            };
          }];
        };

Now I want to be able to use this shell environment in a package derivation:

        packages.default = pkgs.stdenv.mkDerivation {
          inherit system;

          # can this work?
          nativeBuildInputs = [ self.devShells.${system}.default ];

          buildPhase = ''
            # python and poetry dependencies are not available :(
          '';
        };

Is it possible to reuse shell environment in a derivation?

@domenkozar
Copy link
Member

That's not possible since derivation expects no networking access, which is required by most package managers like poetry.

@shishkin
Copy link
Author

Hm.. I thought that's what devenv would be effectively sidestep. When I enter my shell, all the python packages are already in the venv directory.

@thenonameguy
Copy link
Contributor

That is because it's a venv install side-effect generated by the devenv activation script.

There are some blog posts on the internet that advocate disabling the sandboxing for cases like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants