What does mkShell's "mergeInputs" actually do?

I’ve been diving into source code to understand how mkShell handles each dependency type. I’ve stumbled upon mergeInputs and it stunned me a little. If I understand it correctly it returns a list of all the dependencies of that specified type (i.e. buildInputs , nativeBuildInputs) that aren’t listed in inputsFrom.

From what I see, apart from mergeInputs, inputsFrom wasn’t called anywhere else. Question: Does this mean that any dependency that I specified in inputsFrom wouldn’t get called if it is a dependency of another dependency in inputsFrom

For example
in shell.nix

let 
  pkgs = import <nixpkgs> {};
  b = pkgs.stdenv.mkDerivation {
    pname = "b";
    version = "0.0.0";
    src = /some-code/that-needs/a/in-it;
    buildInputs = [ a ];
  };
in
pkgs.mkShell {
  inputsFrom = [ a b ];
}

when I run nix-shell and call a, it wouldn’t be there ?
what if I have another package c in inputsFrom that has runtime dependency on a, How do I manage to create a shell that can do that?
or if I understand anything wrong, PLEASE, feel free to correct me. :sweat_smile:
Cheers!!

1 Like

The expression for c should already include a, so you don’t need to do anything extra beyond correct packaging.

Because a is not part of the shell env. Put it in packages instead.

1 Like

Oh your right, I didn’t think of that. Thanks for pointing it out!

so basically if you want the dependency put it in packages, but if you want the dependencies of a dependency put it in inputsFrom am I getting this right?

Yeah.​​​​​​​​​​​​​​​​​

Put it in either nativeBuildInputs or buildInputs depending on what kind of dependency it is. packages just puts everything in nativeBuildInputs which is not ideal but was sadly introduced in c6b62f23

1 Like

packages is fine. Usually people incorrectly put everything in buildInputs and then wonder why hooks don’t work. It’s not like a devshell is meant to be a pure env anyway.

NB this does not apply to actual packaging, of course. In that case deps should be specified correctly.

1 Like