cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.47k stars 252 forks source link

Use devShell environment in package derivation #1132

Open shishkin opened 2 weeks ago

shishkin commented 2 weeks ago

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.

domenkozar commented 2 weeks ago

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

shishkin commented 2 weeks ago

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 commented 2 weeks ago

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

shishkin commented 2 weeks ago

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 commented 2 weeks ago

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.