2024-06-30 08:16:52 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
stdenv,
|
|
|
|
buildEnv,
|
|
|
|
}:
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
# A special kind of derivation that is only meant to be consumed by the
|
|
|
|
# nix-shell.
|
2024-06-30 08:16:52 +00:00
|
|
|
{
|
|
|
|
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 ? [ ],
|
|
|
|
...
|
2024-05-02 00:46:19 +00:00
|
|
|
}@attrs:
|
|
|
|
let
|
2024-06-30 08:16:52 +00:00
|
|
|
mergeInputs =
|
|
|
|
name:
|
|
|
|
(attrs.${name} or [ ])
|
|
|
|
++
|
|
|
|
# 1. get all `{build,nativeBuild,...}Inputs` from the elements of `inputsFrom`
|
|
|
|
# 2. since that is a list of lists, `flatten` that into a regular list
|
|
|
|
# 3. filter out of the result everything that's in `inputsFrom` itself
|
|
|
|
# this leaves actual dependencies of the derivations in `inputsFrom`, but never the derivations themselves
|
|
|
|
(lib.subtractLists inputsFrom (lib.flatten (lib.catAttrs name inputsFrom)));
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
rest = builtins.removeAttrs attrs [
|
|
|
|
"name"
|
|
|
|
"packages"
|
|
|
|
"inputsFrom"
|
|
|
|
"buildInputs"
|
|
|
|
"nativeBuildInputs"
|
|
|
|
"propagatedBuildInputs"
|
|
|
|
"propagatedNativeBuildInputs"
|
|
|
|
"shellHook"
|
|
|
|
];
|
|
|
|
in
|
|
|
|
|
2024-06-30 08:16:52 +00:00
|
|
|
stdenv.mkDerivation (
|
|
|
|
{
|
|
|
|
inherit name;
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:16:52 +00:00
|
|
|
buildInputs = mergeInputs "buildInputs";
|
|
|
|
nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs");
|
|
|
|
propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
|
|
|
|
propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:16:52 +00:00
|
|
|
shellHook = lib.concatStringsSep "\n" (
|
|
|
|
lib.catAttrs "shellHook" (lib.reverseList inputsFrom ++ [ attrs ])
|
|
|
|
);
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:16:52 +00:00
|
|
|
phases = [ "buildPhase" ];
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:16:52 +00:00
|
|
|
buildPhase = ''
|
|
|
|
{ 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"
|
|
|
|
'';
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-06-30 08:16:52 +00:00
|
|
|
preferLocalBuild = true;
|
|
|
|
}
|
|
|
|
// rest
|
|
|
|
)
|