mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-03-08 01:24:09 +01:00
mkShell: use extendMkDerivation
This commit is contained in:
parent
44088fa169
commit
fe2315d728
1 changed files with 48 additions and 57 deletions
|
|
@ -1,73 +1,64 @@
|
|||
{
|
||||
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 [ ])
|
||||
++
|
||||
# 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)));
|
||||
lib.extendMkDerivation {
|
||||
constructDrv = stdenv.mkDerivation;
|
||||
|
||||
rest = removeAttrs attrs [
|
||||
"name"
|
||||
excludeDrvArgNames = [
|
||||
"packages"
|
||||
"inputsFrom"
|
||||
"buildInputs"
|
||||
"nativeBuildInputs"
|
||||
"propagatedBuildInputs"
|
||||
"propagatedNativeBuildInputs"
|
||||
"shellHook"
|
||||
];
|
||||
in
|
||||
|
||||
stdenv.mkDerivation (
|
||||
{
|
||||
inherit name;
|
||||
extendDrvArgs =
|
||||
_finalAttrs:
|
||||
{
|
||||
name ? "nix-shell",
|
||||
# a list of packages to add to the shell environment
|
||||
packages ? [ ],
|
||||
# propagate all the inputs from the given derivations
|
||||
inputsFrom ? [ ],
|
||||
...
|
||||
}@attrs:
|
||||
let
|
||||
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)));
|
||||
in
|
||||
{
|
||||
inherit name;
|
||||
|
||||
buildInputs = mergeInputs "buildInputs";
|
||||
nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs");
|
||||
propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
|
||||
propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
|
||||
buildInputs = mergeInputs "buildInputs";
|
||||
nativeBuildInputs = packages ++ (mergeInputs "nativeBuildInputs");
|
||||
propagatedBuildInputs = mergeInputs "propagatedBuildInputs";
|
||||
propagatedNativeBuildInputs = mergeInputs "propagatedNativeBuildInputs";
|
||||
|
||||
shellHook = lib.concatStringsSep "\n" (
|
||||
lib.catAttrs "shellHook" (lib.reverseList inputsFrom ++ [ attrs ])
|
||||
);
|
||||
shellHook = lib.concatStringsSep "\n" (
|
||||
lib.catAttrs "shellHook" (lib.reverseList inputsFrom ++ [ attrs ])
|
||||
);
|
||||
|
||||
phases = [ "buildPhase" ];
|
||||
phases = attrs.phases or [ "buildPhase" ];
|
||||
|
||||
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"
|
||||
'';
|
||||
buildPhase =
|
||||
attrs.buildPhase or ''
|
||||
{ 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"
|
||||
'';
|
||||
|
||||
preferLocalBuild = true;
|
||||
}
|
||||
// rest
|
||||
)
|
||||
preferLocalBuild = attrs.preferLocalBuild or true;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue