mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-23 14:13:35 +00:00
1e910209ae
When I designed `mkShell`, I didn't have a good idea of what the output should look like and so decided to make the build fail. In practice, this causes quite a bit of confusion and complications because now the shell cannot be part of a normal package set without failing the CI as well. This commit changes that build phase to record all the build inputs in a file. That way it becomes possible to build it, makes sure that all the build inputs get built as well, and also can be used as a GC root. (by applying the same trick as #95536). The documentation has also been improved to better describe what mkShell does and how to use it.
56 lines
1.6 KiB
Nix
56 lines
1.6 KiB
Nix
{ lib, stdenv, buildEnv }:
|
|
|
|
# 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 ? [ ]
|
|
, ...
|
|
}@attrs:
|
|
let
|
|
mergeInputs = name:
|
|
(attrs.${name} or [ ]) ++
|
|
(lib.subtractLists inputsFrom (lib.flatten (lib.catAttrs name inputsFrom)));
|
|
|
|
rest = builtins.removeAttrs attrs [
|
|
"name"
|
|
"packages"
|
|
"inputsFrom"
|
|
"buildInputs"
|
|
"nativeBuildInputs"
|
|
"propagatedBuildInputs"
|
|
"propagatedNativeBuildInputs"
|
|
"shellHook"
|
|
];
|
|
in
|
|
|
|
stdenv.mkDerivation ({
|
|
inherit name;
|
|
|
|
buildInputs = mergeInputs "buildInputs";
|
|
nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs");
|
|
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
|
|
'';
|
|
} // rest)
|