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.
50 lines
1.2 KiB
Nix
50 lines
1.2 KiB
Nix
{ lib, stdenv }:
|
|
|
|
# A special kind of derivation that is only meant to be consumed by the
|
|
# nix-shell.
|
|
{
|
|
# a list of packages to add to the shell environment
|
|
packages ? [ ]
|
|
, # propagate all the inputs from the given derivations
|
|
inputsFrom ? [ ]
|
|
, buildInputs ? [ ]
|
|
, nativeBuildInputs ? [ ]
|
|
, propagatedBuildInputs ? [ ]
|
|
, propagatedNativeBuildInputs ? [ ]
|
|
, ...
|
|
}@attrs:
|
|
let
|
|
mergeInputs = name: lib.concatLists (lib.catAttrs name
|
|
([ attrs ] ++ inputsFrom));
|
|
|
|
rest = builtins.removeAttrs attrs [
|
|
"packages"
|
|
"inputsFrom"
|
|
"buildInputs"
|
|
"nativeBuildInputs"
|
|
"propagatedBuildInputs"
|
|
"propagatedNativeBuildInputs"
|
|
"shellHook"
|
|
];
|
|
in
|
|
|
|
stdenv.mkDerivation ({
|
|
name = "nix-shell";
|
|
phases = [ "nobuildPhase" ];
|
|
|
|
buildInputs = mergeInputs "buildInputs";
|
|
nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs");
|
|
propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
|
|
propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
|
|
|
|
shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook"
|
|
(lib.reverseList inputsFrom ++ [ attrs ]));
|
|
|
|
nobuildPhase = ''
|
|
echo
|
|
echo "This derivation is not meant to be built, aborting";
|
|
echo
|
|
exit 1
|
|
'';
|
|
} // rest)
|