2022-01-13 20:06:32 +00:00
|
|
|
{ lib, stdenv, buildEnv }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# A special kind of derivation that is only meant to be consumed by the
|
|
|
|
# nix-shell.
|
2022-01-13 20:06:32 +00:00
|
|
|
{ name ? "nix-shell"
|
|
|
|
, # a list of packages to add to the shell environment
|
2021-05-20 23:08:51 +00:00
|
|
|
packages ? [ ]
|
|
|
|
, # propagate all the inputs from the given derivations
|
|
|
|
inputsFrom ? [ ]
|
|
|
|
, buildInputs ? [ ]
|
|
|
|
, nativeBuildInputs ? [ ]
|
|
|
|
, propagatedBuildInputs ? [ ]
|
|
|
|
, propagatedNativeBuildInputs ? [ ]
|
|
|
|
, ...
|
2020-04-24 23:36:52 +00:00
|
|
|
}@attrs:
|
|
|
|
let
|
2021-09-18 10:52:07 +00:00
|
|
|
mergeInputs = name:
|
2022-01-13 20:06:32 +00:00
|
|
|
(attrs.${name} or [ ]) ++
|
2021-09-18 10:52:07 +00:00
|
|
|
(lib.subtractLists inputsFrom (lib.flatten (lib.catAttrs name inputsFrom)));
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
rest = builtins.removeAttrs attrs [
|
2022-01-13 20:06:32 +00:00
|
|
|
"name"
|
2021-05-20 23:08:51 +00:00
|
|
|
"packages"
|
2020-04-24 23:36:52 +00:00
|
|
|
"inputsFrom"
|
|
|
|
"buildInputs"
|
|
|
|
"nativeBuildInputs"
|
|
|
|
"propagatedBuildInputs"
|
|
|
|
"propagatedNativeBuildInputs"
|
|
|
|
"shellHook"
|
|
|
|
];
|
|
|
|
in
|
|
|
|
|
|
|
|
stdenv.mkDerivation ({
|
2022-01-13 20:06:32 +00:00
|
|
|
inherit name;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
buildInputs = mergeInputs "buildInputs";
|
2021-05-20 23:08:51 +00:00
|
|
|
nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs");
|
2020-04-24 23:36:52 +00:00
|
|
|
propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
|
|
|
|
propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
|
|
|
|
|
|
|
|
shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook"
|
2021-05-20 23:08:51 +00:00
|
|
|
(lib.reverseList inputsFrom ++ [ attrs ]));
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-01-13 20:06:32 +00:00
|
|
|
phases = [ "buildPhase" ];
|
|
|
|
|
|
|
|
buildPhase = ''
|
2022-12-17 10:02:37 +00:00
|
|
|
{ echo "------------------------------------------------------------";
|
|
|
|
echo " WARNING: the existence of this path is not guaranteed.";
|
|
|
|
echo " It is an internal implementation detail for pkgs.mkShell.";
|
|
|
|
echo "------------------------------------------------------------";
|
|
|
|
echo;
|
|
|
|
# Record all build inputs as runtime dependencies
|
|
|
|
export;
|
|
|
|
} >> "$out"
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
} // rest)
|