2022-01-08 01:54:04 +01:00
|
|
|
{ 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.
|
2022-01-08 01:54:04 +01:00
|
|
|
{ name ? "nix-shell"
|
|
|
|
, # a list of packages to add to the shell environment
|
2021-05-13 19:17:29 +02:00
|
|
|
packages ? [ ]
|
|
|
|
, # propagate all the inputs from the given derivations
|
|
|
|
inputsFrom ? [ ]
|
|
|
|
, buildInputs ? [ ]
|
|
|
|
, nativeBuildInputs ? [ ]
|
|
|
|
, propagatedBuildInputs ? [ ]
|
|
|
|
, propagatedNativeBuildInputs ? [ ]
|
|
|
|
, ...
|
2017-12-21 00:42:07 +01:00
|
|
|
}@attrs:
|
|
|
|
let
|
2021-09-08 13:53:09 +02:00
|
|
|
mergeInputs = name:
|
2022-01-08 01:54:04 +01:00
|
|
|
(attrs.${name} or [ ]) ++
|
2021-09-08 16:54:24 +02:00
|
|
|
(lib.subtractLists inputsFrom (lib.flatten (lib.catAttrs name inputsFrom)));
|
2017-12-21 00:42:07 +01:00
|
|
|
|
|
|
|
rest = builtins.removeAttrs attrs [
|
2022-01-08 01:54:04 +01:00
|
|
|
"name"
|
2021-05-13 19:17:29 +02:00
|
|
|
"packages"
|
2017-12-21 00:42:07 +01:00
|
|
|
"inputsFrom"
|
|
|
|
"buildInputs"
|
|
|
|
"nativeBuildInputs"
|
|
|
|
"propagatedBuildInputs"
|
|
|
|
"propagatedNativeBuildInputs"
|
2019-06-23 21:11:49 +02:00
|
|
|
"shellHook"
|
2017-12-21 00:42:07 +01:00
|
|
|
];
|
|
|
|
in
|
|
|
|
|
|
|
|
stdenv.mkDerivation ({
|
2022-01-08 01:54:04 +01:00
|
|
|
inherit name;
|
2017-12-21 00:42:07 +01:00
|
|
|
|
|
|
|
buildInputs = mergeInputs "buildInputs";
|
2021-05-13 19:17:29 +02:00
|
|
|
nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs");
|
2017-12-21 00:42:07 +01:00
|
|
|
propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
|
|
|
|
propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
|
|
|
|
|
2019-06-23 21:11:49 +02:00
|
|
|
shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook"
|
2021-05-13 19:17:29 +02:00
|
|
|
(lib.reverseList inputsFrom ++ [ attrs ]));
|
2019-06-23 21:11:49 +02:00
|
|
|
|
2022-01-08 01:54:04 +01:00
|
|
|
phases = [ "buildPhase" ];
|
|
|
|
|
|
|
|
buildPhase = ''
|
2022-12-05 09:16:12 +01: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"
|
2017-12-21 00:42:07 +01:00
|
|
|
'';
|
2023-02-22 11:53:51 +01:00
|
|
|
|
|
|
|
preferLocalBuild = true;
|
2017-12-21 00:42:07 +01:00
|
|
|
} // rest)
|