Specifying shell-only inputs for a derivation?

Hello all,

I have a flake which provides multiple packages. The intended workflow is for the users of the flake (the development team) to use eg nix develop .#pkg1 to work on pkg1.

I’d like to make a set of standard development tools (like gdb) available in all of the provided packages, and I can easily do so by adding gdb to the buildInputs of each package. However, the problem with this is that I am now getting frequent cache invalidations, because this list of development tools is somewhat long and prone to change, and any change in this list requires pkg1 to be re-built.

I’m looking for a solution and speculating whether any of the following are possible:

  • A mkDerivation argument I’ve missed that allows you to pass packages that are used only in the shell, and don’t form part of the build dependency graph
  • A neat way to have the package-specific shell stack on top of a more general development shell with the developments tools available in it
  • … or some other solution?

Thanks for any help!

If it is enough to get binaries in PATH from the packages, then something like this might work (simplified flake output schema):

devShells.pkg1 = pkgs.mkShell {
  inputsFrom = [self.packages.pkg1];
  packages = [gdb and other common stuff];
};

Alternatively, something like the following is imaginable:

devShells = let
  shellFor = pkg: pkgs.mkShell {
    packages = [gdb and other common stuff] ++ (pkg.buildInputs or []) ++ (pkg.nativeBuildInputs or []);
  };
in pkg1 = shellFor self.packages.pkg1;

Neither is optimal, and probably requires tweaking, but there is nothing that would give you a “full” out of the box experience.

Thanks - actually, that approach seems to work fine - if there are any downsides I’ve yet to bump into them.