How do I access the devShell outPath from inside flake.nix (to bundle+cache it)


How do I cache a devShell from within the flake.nix itself? I’ve asked this but it seems more difficult than it looks at first glance.

If devShell uses mkShell, then there are two problems:

  • the mkShell derivation refuses to be built:
    error: --- Error ------------------------------------------------------------------------------------------------------- nix
    builder for '/nix/store/ydg6ban9vkp3f00g7rcrzd7wmzcjyhrb-nixcfg-devshell.drv' failed with exit code 1; last 4 log lines:
      This derivation is not meant to be built, aborting
  • if I try to use it with linkFarmFromDrvs it complains about being missing

If devShell uses stdenv.mkDerivation, then:

error: --- Error ------------------------------------------------------------------------------------------------------- nix
builder for '/nix/store/ljwqzcg51xl50zp93f8v15m0bnfar5qn-nixcfg-devshell.drv' failed with exit code 1; last 2 log lines:
  unpacking sources
  variable $src or $srcs should point to the source

I also looked at nix-direnv, but it seems like it uses nix print-dev-env with --profile to capture the closure of the development environment. I don’t really know how to emulate this with Nix inside the flake.nix.

Any suggestions? I’m hoping for something “nicer” than manually tracking the nativeBuildInputs/buildInputs to feed to devShell and my own expression later.

Could you try how to push binary with nix build and nix develop · Issue #340 · cachix/cachix · GitHub

Hey thanks for the link, but it looks like the other technique I’d mentioned. I’m specifically very interested in avoiding having to write another script to call nix develop --profile, ensure the nix version, etc. I already have a flake output attribute that is a bundle of everything else.

Somehow, mkShell/nix-shell/etc feel like something I’ve never quite been able to fully understand in my head properly. And now, with this, I’m left confused and a bit disappointed. To me, it feels like “It’s just Nix”. I’m declaring the devenv in Nix, it feels like it should be more trivial to write Nix to access the devshell-env usefully.

Well, @ryantm made my day by pointing me to And thank you to all of the folks in that thread that brought this to life, just in time for me to come looking for it. :slight_smile: .