Skip to content

Commit

Permalink
stdenv: Fix handling of dependencies and hooks
Browse files Browse the repository at this point in the history
4 far-reaching changes: Smaller PATH, New vars, different propagation
logic, and different hook logic

Smaller PATH
------------

`buildInputs` no longer go on the PATH at build time, as they cannot be
run when cross compiling and we don't want to special case. Simply make
a `nativeBuildInput` too if one needs them on the PATH. Fixes NixOS#21191.

Many new depedendency variables
-------------------------------

See the stdenv chapter of the nixpkgs manual. I pulled out the existing
documentation of dependency specification into a new section, and added
language for these two (and their propagated equivalents) along side
the others'.

More complex propagation logic
------------------------------

Before a propagated*XXX*Input always acted as if it was specified
directly as a *XXX*Input downstream. That's simple enough, but violates
the intended roles of each sort of dep, which has functional and not
just stylistic consequences.

The new algorithm is detailed in the manual, and ensures everything
ends up in the right place. I tried to give both an informal and formal
description, but I suspect in practice it will not make much sense
until one tries cross compiling, after which it will immediately make
sense as the only sane option.

Simplified hook logic
---------------------

Rather than `envHook` and `crossEnvHook`, whose behavior differs
depending on whether we are cross compiling or not, there is now one
hook per sort (or rather non-propagated and propagated pair of sorts)
of dependency. These new hooks have the same meaning regardless of
cross compilation. See the setup hook section of stdenv chapter of the
Nixpkgs manual for more details.
  • Loading branch information
Ericson2314 authored and bgamari committed Nov 5, 2017
1 parent 164dd43 commit 90512bc
Show file tree
Hide file tree
Showing 2 changed files with 276 additions and 102 deletions.
71 changes: 55 additions & 16 deletions pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ rec {
mkDerivation =
{ name ? ""

, nativeBuildInputs ? []
, buildInputs ? []
# TODO(@Ericson2314): Stop using legacy dep attribute names
# host offset -> target offset
, depsBuildBuild ? [] # -1 -> -1
, depsBuildBuildPropagated ? [] # -1 -> -1
, nativeBuildInputs ? [] # -1 -> 0 N.B. Legacy name
, propagatedNativeBuildInputs ? [] # -1 -> 0 N.B. Legacy name
, __depsBuildTarget ? [] # -1 -> 1
, __depsBuildTargetPropagated ? [] # -1 -> 1

, propagatedNativeBuildInputs ? []
, propagatedBuildInputs ? []
, __depsHostHost ? [] # 0 -> 0
, __depsHostHostPropagated ? [] # 0 -> 0
, buildInputs ? [] # 0 -> 1 N.B. Legacy name
, propagatedBuildInputs ? [] # 0 -> 1 N.B. Legacy name

, __depsTargetTarget ? [] # 1 -> 1
, __depsTargetTargetPropagated ? [] # 1 -> 1

, configureFlags ? []
, # Target is not included by default because most programs don't care.
Expand Down Expand Up @@ -56,15 +67,35 @@ rec {
inherit erroneousHardeningFlags hardeningDisable hardeningEnable supportedHardeningFlags;
})
else let
dependencies = map lib.chooseDevOutputs [
(map (drv: drv.nativeDrv or drv) nativeBuildInputs
++ lib.optional separateDebugInfo ../../build-support/setup-hooks/separate-debug-info.sh
++ lib.optional stdenv.hostPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh)
(map (drv: drv.crossDrv or drv) buildInputs)
dependencies = map (map lib.chooseDevOutputs) [
[
(map (drv: drv.__spliced.buildBuild or drv) depsBuildBuild)
(map (drv: drv.nativeDrv or drv) nativeBuildInputs
++ lib.optional separateDebugInfo ../../build-support/setup-hooks/separate-debug-info.sh
++ lib.optional stdenv.hostPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh)
(map (drv: drv.__spliced.__buildTarget or drv) __depsBuildTarget)
]
[
(map (drv: drv.__spliced.__hostHost or drv) __depsHostHost)
(map (drv: drv.crossDrv or drv) buildInputs)
]
[
(map (drv: drv.__spliced.__targetTarget or drv) __depsTargetTarget)
]
];
propagatedDependencies = map lib.chooseDevOutputs [
(map (drv: drv.nativeDrv or drv) propagatedNativeBuildInputs)
(map (drv: drv.crossDrv or drv) propagatedBuildInputs)
propagatedDependencies = map (map lib.chooseDevOutputs) [
[
(map (drv: drv.__spliced.buildBuild or drv) depsBuildBuildPropagated)
(map (drv: drv.nativeDrv or drv) propagatedNativeBuildInputs)
(map (drv: drv.__spliced.__buildTarget or drv) __depsBuildTargetPropagated)
]
[
(map (drv: drv.__spliced.__hostHost or drv) __depsHostHostPropagated)
(map (drv: drv.crossDrv or drv) propagatedBuildInputs)
]
[
(map (drv: drv.__spliced.__targetTarget or drv) __depsTargetTargetPropagated)
]
];

outputs' =
Expand Down Expand Up @@ -105,11 +136,19 @@ rec {
userHook = config.stdenv.userHook or null;
__ignoreNulls = true;

nativeBuildInputs = lib.elemAt dependencies 0;
buildInputs = lib.elemAt dependencies 1;
depsBuildBuild = lib.elemAt (lib.elemAt dependencies 0) 0;
nativeBuildInputs = lib.elemAt (lib.elemAt dependencies 0) 1;
__depsBuildTarget = lib.elemAt (lib.elemAt dependencies 0) 2;
__depsHostBuild = lib.elemAt (lib.elemAt dependencies 1) 0;
buildInputs = lib.elemAt (lib.elemAt dependencies 1) 1;
__depsTargetTarget = lib.elemAt (lib.elemAt dependencies 2) 0;

propagatedNativeBuildInputs = lib.elemAt propagatedDependencies 0;
propagatedBuildInputs = lib.elemAt propagatedDependencies 1;
depsBuildBuildPropagated = lib.elemAt (lib.elemAt propagatedDependencies 0) 0;
propagatedNativeBuildInputs = lib.elemAt (lib.elemAt propagatedDependencies 0) 1;
__depsBuildTargetPropagated = lib.elemAt (lib.elemAt propagatedDependencies 0) 2;
__depsHostBuildPropagated = lib.elemAt (lib.elemAt propagatedDependencies 1) 0;
propagatedBuildInputs = lib.elemAt (lib.elemAt propagatedDependencies 1) 1;
__depsTargetTargetPropagated = lib.elemAt (lib.elemAt propagatedDependencies 2) 0;

# This parameter is sometimes a string, sometimes null, and sometimes a list, yuck
configureFlags = let inherit (lib) optional elem; in
Expand Down
Loading

0 comments on commit 90512bc

Please sign in to comment.