nixpkgs/pkgs/build-support/mkshell/default.nix

56 lines
1.6 KiB
Nix
Raw Normal View History

{ lib, stdenv, buildEnv }:
2017-12-21 00:42:07 +01:00
# A special kind of derivation that is only meant to be consumed by the
# nix-shell.
{ name ? "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 ? [ ]
, ...
2017-12-21 00:42:07 +01:00
}@attrs:
let
mergeInputs = name:
(attrs.${name} or [ ]) ++
(lib.subtractLists inputsFrom (lib.flatten (lib.catAttrs name inputsFrom)));
2017-12-21 00:42:07 +01:00
rest = builtins.removeAttrs attrs [
"name"
"packages"
2017-12-21 00:42:07 +01:00
"inputsFrom"
"buildInputs"
"nativeBuildInputs"
"propagatedBuildInputs"
"propagatedNativeBuildInputs"
"shellHook"
2017-12-21 00:42:07 +01:00
];
in
stdenv.mkDerivation ({
inherit name;
2017-12-21 00:42:07 +01:00
buildInputs = mergeInputs "buildInputs";
nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs");
2017-12-21 00:42:07 +01:00
propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook"
(lib.reverseList inputsFrom ++ [ attrs ]));
phases = [ "buildPhase" ];
buildPhase = ''
echo "------------------------------------------------------------" >>$out
echo " WARNING: the existence of this path is not guaranteed." >>$out
echo " It is an internal implementation detail for pkgs.mkShell." >>$out
echo "------------------------------------------------------------" >>$out
echo >> $out
# Record all build inputs as runtime dependencies
export >> $out
2017-12-21 00:42:07 +01:00
'';
} // rest)