Commit Graph

7 Commits

Author SHA1 Message Date
Jonas Chevalier
1e910209ae
mkShell: make it buildable (#153194)
When I designed `mkShell`, I didn't have a good idea of what the output
should look like and so decided to make the build fail. In practice,
this causes quite a bit of confusion and complications because now the
shell cannot be part of a normal package set without failing the CI as
well.

This commit changes that build phase to record all the build inputs in a
file. That way it becomes possible to build it, makes sure that all the
build inputs get built as well, and also can be used as a GC root.
(by applying the same trick as #95536).

The documentation has also been improved to better describe what mkShell
does and how to use it.
2022-01-08 01:54:04 +01:00
Geoff Reedy
c524608dca
mkshell: small fix for #137005 (#137105)
I somehow accidentally left out the lib.flatten from mergeInputs. Without it, subtractLists won't ever remove anything from the inputs since the inputs will be a list of lists.
2021-09-08 16:54:24 +02:00
Geoff Reedy
087513bc11
mkShell: exclude inputsFrom from merged inputs (#137005)
The motivation for inputsFrom is to create a shell environment that is suitable for development of the packages listed in inputsFrom. This commit filters out any dependencies from one package in inputsFrom to another when computing the shell environment's inputs. This supports the use case where several closely related packages (perhaps even built from the same source tree) are being mutually developed. It is assumed that the user will configure their environment to resolve dependencies between these mutually developed packages.
2021-09-08 13:53:09 +02:00
Jonas Chevalier
c6b62f2381
mkShell: introduce packages argument (#122180)
The distinction between the inputs doesn't really make sense in the
mkShell context.  Technically speaking, we should be using the
nativeBuildInputs most of the time.

So in order to make this function more beginner-friendly, add "packages"
as an attribute, that maps to nativeBuildInputs.

This commit also updates all the uses in nixpkgs.
2021-05-13 19:17:29 +02:00
Bas van Dijk
cee35739ff mkshell: improve mergeInputs
mergeInputs is now simply defined in terms of `concatLists` and
`catAttrs` instead of a more complicated `foldr`.

Note that the order of PATH has also changed. For example running the
following with nix-shell:

  let
    pkgs = import <nixpkgs> {};

    shell1 = pkgs.mkShell {
      buildInputs = [ pkgs.htop ];
    };

    shell2 = pkgs.mkShell {
      buildInputs = [ pkgs.hello ];
    };

    shell3 = pkgs.mkShell {
      inputsFrom = [ shell1 shell2 ];
      buildInputs = [ pkgs.tree ];
    };

  in shell3

Results in the following PATH:

$ echo $PATH
...
/nix/store/yifq4bikf7m07160bpia7z48ciqddbfi-tree-1.8.0/bin:
/nix/store/vhxqk81234ivqw1a7j200a1c69k8mywi-htop-2.2.0/bin:
/nix/store/n9vm3m58y1n3rg3mlll17wanc9hln58k-hello-2.10/bin
...

Previously the order was:

/nix/store/n9vm3m58y1n3rg3mlll17wanc9hln58k-hello-2.10/bin
/nix/store/vhxqk81234ivqw1a7j200a1c69k8mywi-htop-2.2.0/bin:
/nix/store/yifq4bikf7m07160bpia7z48ciqddbfi-tree-1.8.0/bin:

I think the new order makes more sense because it allows to override
the PATH in the outermost mkShell.
2019-06-23 22:20:10 +02:00
Bas van Dijk
76ef802d3d mkShell: compose shellHooks
Running the following expression with nix-shell:

  let
    pkgs = import <nixpkgs> {};

    shell1 = pkgs.mkShell {
      shellHook = ''
        echo shell1
      '';
    };

    shell2 = pkgs.mkShell {
      shellHook = ''
        echo shell2
      '';
    };

    shell3 = pkgs.mkShell {
      inputsFrom = [ shell1 shell2 ];
      shellHook = ''
        echo shell3
      '';
    };
  in shell3

Will now results in:
shell2
shell1
shell3

Note that packages in the front of inputsFrom have precedence over
packages in the back. The outermost mkShell has precedence over all.
2019-06-23 22:13:57 +02:00
zimbatm
adc5c9b83d
mkShell: add builder (#30975) 2017-12-20 23:42:07 +00:00