aboutsummaryrefslogtreecommitdiff
path: root/pkgs/top-level
diff options
context:
space:
mode:
authorJohn Ericson <Ericson2314@Yahoo.com>2016-12-17 23:51:18 -0800
committerJohn Ericson <Ericson2314@Yahoo.com>2017-01-24 11:37:56 -0500
commitbf17d6dacf2408436ffb5a2f8c87a31c88ec28e2 (patch)
tree810acd70cdbe14ffc816eea73e924d6c8703151a /pkgs/top-level
parent92b1e39e1c43a55a1460571782e3c7444556814b (diff)
top-level: Introduce `buildPackages` for resolving build-time deps
[N.B., this package also applies to the commits that follow it in the same PR.] In most cases, buildPackages = pkgs so things work just as before. For cross compiling, however, buildPackages is resolved as the previous bootstrapping stage. This allows us to avoid the mkDerivation hacks cross compiling currently uses today. To avoid a massive refactor, callPackage will splice together both package sets. Again to avoid churn, it uses the old `nativeDrv` vs `crossDrv` to do so. So now, whether cross compiling or not, packages with get a `nativeDrv` and `crossDrv`---in the non-cross-compiling case they are simply the same derivation. This is good because it reduces the divergence between the cross and non-cross dataflow. See `pkgs/top-level/splice.nix` for a comment along the lines of the preceding paragraph, and the code that does this splicing. Also, `forceNativeDrv` is replaced with `forceNativePackages`. The latter resolves `pkgs` unless the host platform is different from the build platform, in which case it resolves to `buildPackages`. Note that the target platform is not important here---it will not prevent `forcedNativePackages` from resolving to `pkgs`. -------- Temporarily, we make preserve some dubious decisions in the name of preserving hashes: Most importantly, we don't distinguish between "host" and "target" in the autoconf sense. This leads to the proliferation of *Cross derivations currently used. What we ought to is resolve native deps of the cross "build packages" (build = host != target) package set against the "vanilla packages" (build = host = target) package set. Instead, "build packages" uses itself, with (informally) target != build in all cases. This is wrong because it violates the "sliding window" principle of bootstrapping stages that shifting the platform triple of one stage to the left coincides with the next stage's platform triple. Only because we don't explicitly distinguish between "host" and "target" does it appear that the "sliding window" principle is preserved--indeed it is over the reductionary "platform double" of just "build" and "host/target". Additionally, we build libc, libgcc, etc in the same stage as the compilers themselves, which is wrong because they are used at runtime, not build time. Fixing this is somewhat subtle, and the solution and problem will be better explained in the commit that does fix it. Commits after this will solve both these issues, at the expense of breaking cross hashes. Native hashes won't be broken, thankfully. -------- Did the temporary ugliness pan out? Of the packages that currently build in `release-cross.nix`, the only ones that have their hash changed are `*.gcc.crossDrv` and `bootstrapTools.*.coreutilsMinimal`. In both cases I think it doesn't matter. 1. GCC when doing a `build = host = target = foreign` build (maximally cross), still defines environment variables like `CPATH`[1] with packages. This seems assuredly wrong because whether gcc dynamically links those, or the programs built by gcc dynamically link those---I have no idea which case is reality---they should be foreign. Therefore, in all likelihood, I just made the gcc less broken. 2. Coreutils (ab)used the old cross-compiling infrastructure to depend on a native version of itself. When coreutils was overwritten to be built with fewer features, the native version it used would also be overwritten because the binding was tight. Now it uses the much looser `BuildPackages.coreutils` which is just fine as a richer build dep doesn't cause any problems and avoids a rebuild. So, in conclusion I'd say the conservatism payed off. Onward to actually raking the muck in the next PR! [1]: https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html
Diffstat (limited to 'pkgs/top-level')
-rw-r--r--pkgs/top-level/all-packages.nix70
-rw-r--r--pkgs/top-level/release-cross.nix14
-rw-r--r--pkgs/top-level/release-lib.nix5
-rw-r--r--pkgs/top-level/splice.nix76
-rw-r--r--pkgs/top-level/stage.nix7
5 files changed, 123 insertions, 49 deletions
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 8d2b4cf52014..bafe502da385 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -10,26 +10,12 @@ self: pkgs:
with pkgs;
-let
- defaultScope = pkgs // pkgs.xorg;
-in
-
{
# Allow callPackage to fill in the pkgs argument
inherit pkgs;
- # We use `callPackage' to be able to omit function arguments that
- # can be obtained from `pkgs' or `pkgs.xorg' (i.e. `defaultScope').
- # Use `newScope' for sets of packages in `pkgs' (see e.g. `gnome'
- # below).
- callPackage = newScope {};
-
- callPackages = lib.callPackagesWith defaultScope;
-
- newScope = extra: lib.callPackageWith (defaultScope // extra);
-
# Override system. This is useful to build i686 packages on x86_64-linux.
forceSystem = system: kernel: nixpkgsFun {
inherit system;
@@ -39,15 +25,9 @@ in
# Used by wine, firefox with debugging version of Flash, ...
pkgsi686Linux = forceSystem "i686-linux" "i386";
- callPackage_i686 = lib.callPackageWith (pkgsi686Linux // pkgsi686Linux.xorg);
+ callPackage_i686 = pkgsi686Linux.callPackage;
- forceNativeDrv = drv:
- # Even when cross compiling, some packages come from the stdenv's
- # bootstrapping package set. Those packages are only built for the native
- # platform.
- if crossSystem != null && drv ? crossDrv
- then drv // { crossDrv = drv.nativeDrv; }
- else drv;
+ forcedNativePackages = if crossSystem == null then pkgs else buildPackages;
# A stdenv capable of building 32-bit binaries. On x86_64-linux,
# it uses GCC compiled with multilib support; on i686-linux, it's
@@ -4771,41 +4751,45 @@ in
gccApple = throw "gccApple is no longer supported";
- gccCrossStageStatic = let
+ gccCrossStageStatic = assert crossSystem != null; let
libcCross1 =
if stdenv.cross.libc == "msvcrt" then windows.mingw_w64_headers
else if stdenv.cross.libc == "libSystem" then darwin.xcode
else null;
in wrapGCCCross {
- gcc = forceNativeDrv (gcc.cc.override {
+ gcc = forcedNativePackages.gcc.cc.override {
cross = crossSystem;
crossStageStatic = true;
langCC = false;
libcCross = libcCross1;
enableShared = false;
- });
+ # Why is this needed?
+ inherit (forcedNativePackages) binutilsCross;
+ };
libc = libcCross1;
binutils = binutilsCross;
cross = crossSystem;
};
# Only needed for mingw builds
- gccCrossMingw2 = wrapGCCCross {
+ gccCrossMingw2 = assert crossSystem != null; wrapGCCCross {
gcc = gccCrossStageStatic.gcc;
libc = windows.mingw_headers2;
binutils = binutilsCross;
cross = assert crossSystem != null; crossSystem;
};
- gccCrossStageFinal = wrapGCCCross {
- gcc = forceNativeDrv (gcc.cc.override {
+ gccCrossStageFinal = assert crossSystem != null; wrapGCCCross {
+ gcc = forcedNativePackages.gcc.cc.override {
cross = crossSystem;
crossStageStatic = false;
# XXX: We have troubles cross-compiling libstdc++ on MinGW (see
# <http://hydra.nixos.org/build/4268232>), so don't even try.
langCC = crossSystem.config != "i686-pc-mingw32";
- });
+ # Why is this needed?
+ inherit (forcedNativePackages) binutilsCross;
+ };
libc = libcCross;
binutils = binutilsCross;
cross = crossSystem;
@@ -5499,12 +5483,12 @@ in
wrapGCCCross =
{gcc, libc, binutils, cross, shell ? "", name ? "gcc-cross-wrapper"}:
- forceNativeDrv (callPackage ../build-support/gcc-cross-wrapper {
+ forcedNativePackages.callPackage ../build-support/gcc-cross-wrapper {
nativeTools = false;
nativeLibc = false;
noLibc = (libc == null);
inherit gcc binutils libc shell name cross;
- });
+ };
# prolog
yap = callPackage ../development/compilers/yap { };
@@ -6084,12 +6068,12 @@ in
gold = false;
});
- binutilsCross = assert crossSystem != null; lowPrio (forceNativeDrv (
+ binutilsCross = assert crossSystem != null; lowPrio (
if crossSystem.libc == "libSystem" then darwin.cctools_cross
- else binutils.override {
+ else forcedNativePackages.binutils.override {
noSysDirs = true;
cross = crossSystem;
- }));
+ });
bison2 = callPackage ../development/tools/parsing/bison/2.x.nix { };
bison3 = callPackage ../development/tools/parsing/bison/3.x.nix { };
@@ -6558,9 +6542,9 @@ in
cross_renaming: we should make all programs use pkgconfig as
nativeBuildInput after the renaming.
*/
- pkgconfig = forceNativeDrv (callPackage ../development/tools/misc/pkgconfig {
+ pkgconfig = forcedNativePackages.callPackage ../development/tools/misc/pkgconfig {
fetchurl = fetchurlBoot;
- });
+ };
pkgconfigUpstream = lowPrio (pkgconfig.override { vanilla = true; });
postiats-utilities = callPackage ../development/tools/postiats-utilities {};
@@ -7336,10 +7320,10 @@ in
withGd = true;
};
- glibcCross = forceNativeDrv (glibc.override {
+ glibcCross = forcedNativePackages.glibc.override {
gccCross = gccCrossStageStatic;
linuxHeaders = linuxHeadersCross;
- });
+ };
# We can choose:
libcCrossChooser = name: if name == "glibc" then glibcCross
@@ -10910,7 +10894,7 @@ in
cmdline = callPackage ../os-specific/darwin/command-line-tools {};
apple-source-releases = callPackage ../os-specific/darwin/apple-source-releases { };
in apple-source-releases // rec {
- cctools_cross = callPackage (forceNativeDrv (callPackage ../os-specific/darwin/cctools/port.nix {}).cross) {
+ cctools_cross = callPackage (forcedNativePackages.callPackage ../os-specific/darwin/cctools/port.nix {}).cross {
cross = assert crossSystem != null; crossSystem;
inherit maloader;
xctoolchain = xcode.toolchain;
@@ -11148,13 +11132,13 @@ in
linuxHeaders = linuxHeaders_4_4;
- linuxHeaders24Cross = forceNativeDrv (callPackage ../os-specific/linux/kernel-headers/2.4.nix {
+ linuxHeaders24Cross = forcedNativePackages.callPackage ../os-specific/linux/kernel-headers/2.4.nix {
cross = assert crossSystem != null; crossSystem;
- });
+ };
- linuxHeaders26Cross = forceNativeDrv (callPackage ../os-specific/linux/kernel-headers/4.4.nix {
+ linuxHeaders26Cross = forcedNativePackages.callPackage ../os-specific/linux/kernel-headers/4.4.nix {
cross = assert crossSystem != null; crossSystem;
- });
+ };
linuxHeaders_3_18 = callPackage ../os-specific/linux/kernel-headers/3.18.nix { };
diff --git a/pkgs/top-level/release-cross.nix b/pkgs/top-level/release-cross.nix
index f582bcf3b323..48f183162cf8 100644
--- a/pkgs/top-level/release-cross.nix
+++ b/pkgs/top-level/release-cross.nix
@@ -32,8 +32,10 @@ let
in
{
- # These `nativeDrv`s should be identical to their vanilla ones --- cross
- # compiling should not affect the native derivation.
+ # These derivations from a cross package set's `buildPackages` should be
+ # identical to their vanilla equivalents --- none of these package should
+ # observe the target platform which is the only difference between those
+ # package sets.
ensureUnaffected = let
# Absurd values are fine here, as we are not building anything. In fact,
# there probably a good idea to try to be "more parametric" --- i.e. avoid
@@ -47,8 +49,12 @@ in
# good idea lest there be some irrelevant pass-through debug attrs that
# cause false negatives.
testEqualOne = path: system: let
- f = attrs: builtins.toString (lib.getAttrFromPath path (allPackages attrs));
- in assert f { inherit system; } == f { inherit system crossSystem; }; true;
+ f = path: attrs: builtins.toString (lib.getAttrFromPath path (allPackages attrs));
+ in assert
+ f path { inherit system; }
+ ==
+ f (["buildPackages"] ++ path) { inherit system crossSystem; };
+ true;
testEqual = path: systems: forAllSupportedSystems systems (testEqualOne path);
diff --git a/pkgs/top-level/release-lib.nix b/pkgs/top-level/release-lib.nix
index 5fe87711c016..04a57ef8063b 100644
--- a/pkgs/top-level/release-lib.nix
+++ b/pkgs/top-level/release-lib.nix
@@ -76,8 +76,9 @@ rec {
* parameter for allPackages, defining the target platform for cross builds,
* and triggering the build of the host derivation (cross built - crossDrv). */
mapTestOnCross = crossSystem: mapAttrsRecursive
- (path: systems: testOnCross crossSystem systems
- (pkgs: addMetaAttrs { maintainers = crossMaintainers; } (getAttrFromPath path pkgs)));
+ (path: systems: testOnCross crossSystem systems (pkgs: addMetaAttrs
+ { maintainers = crossMaintainers; }
+ (getAttrFromPath path pkgs.splicedPackages)));
/* Recursively map a (nested) set of derivations to an isomorphic
diff --git a/pkgs/top-level/splice.nix b/pkgs/top-level/splice.nix
new file mode 100644
index 000000000000..f57f42020c27
--- /dev/null
+++ b/pkgs/top-level/splice.nix
@@ -0,0 +1,76 @@
+# The `splicedPackages' package set, and its use by `callPackage`
+#
+# The `buildPackages` pkg set is a new concept, and the vast majority package
+# expression (the other *.nix files) are not designed with it in mind. This
+# presents us with a problem with how to get the right version (build-time vs
+# run-time) of a package to a consumer that isn't used to thinking so cleverly.
+#
+# The solution is to splice the package sets together as we do below, so every
+# `callPackage`d expression in fact gets both versions. Each# derivation (and
+# each derivation's outputs) consists of the run-time version, augmented with a
+# `nativeDrv` field for the build-time version, and `crossDrv` field for the
+# run-time version.
+#
+# We could have used any names we want for the disambiguated versions, but
+# `crossDrv` and `nativeDrv` were somewhat similarly used for the old
+# cross-compiling infrastructure. The names are mostly invisible as
+# `mkDerivation` knows how to pull out the right ones for `buildDepends` and
+# friends, but a few packages use them directly, so it seemed efficient (to
+# @Ericson2314) to reuse those names, at least initially, to minimize breakage.
+lib: pkgs:
+
+let
+ defaultBuildScope = pkgs.buildPackages // pkgs.buildPackages.xorg;
+ # TODO(@Ericson2314): we shouldn't preclude run-time fetching by removing
+ # these attributes. We should have a more general solution for selecting
+ # whether `nativeDrv` or `crossDrv` is the default in `defaultScope`.
+ pkgsWithoutFetchers = lib.filterAttrs (n: _: !lib.hasPrefix "fetch" n) pkgs;
+ defaultRunScope = pkgsWithoutFetchers // pkgs.xorg;
+
+ splicer = buildPkgs: runPkgs: let
+ mash = buildPkgs // runPkgs;
+ merge = name: {
+ inherit name;
+ value = let
+ defaultValue = mash.${name};
+ buildValue = buildPkgs.${name} or {};
+ runValue = runPkgs.${name} or {};
+ augmentedValue = defaultValue
+ // (lib.optionalAttrs (buildPkgs ? ${name}) { nativeDrv = buildValue; })
+ // (lib.optionalAttrs (runPkgs ? ${name}) { crossDrv = runValue; });
+ # Get the set of outputs of a derivation
+ getOutputs = value:
+ lib.genAttrs (value.outputs or []) (output: value.${output});
+ in
+ # Certain *Cross derivations will fail assertions, but we need their
+ # nativeDrv. We are assuming anything that fails to evaluate is an
+ # attrset (including derivation) and thus can be unioned.
+ if !(builtins.tryEval defaultValue).success then augmentedValue
+ # The derivation along with its outputs, which we recur
+ # on to splice them together.
+ else if lib.isDerivation defaultValue then augmentedValue
+ // splicer (getOutputs buildValue) (getOutputs runValue)
+ # Just recur on plain attrsets
+ else if lib.isAttrs defaultValue then splicer buildValue runValue
+ # Don't be fancy about non-derivations. But we could have used used
+ # `__functor__` for functions instead.
+ else defaultValue;
+ };
+ in lib.listToAttrs (map merge (lib.attrNames mash));
+
+ splicedPackages = splicer defaultBuildScope defaultRunScope;
+
+in
+
+{
+ splicedPackages = splicedPackages // { recurseForDerivations = false; };
+
+ # We use `callPackage' to be able to omit function arguments that can be
+ # obtained `pkgs` or `buildPackages` and their `xorg` package sets. Use
+ # `newScope' for sets of packages in `pkgs' (see e.g. `gnome' below).
+ callPackage = pkgs.newScope {};
+
+ callPackages = lib.callPackagesWith splicedPackages;
+
+ newScope = extra: lib.callPackageWith (splicedPackages // extra);
+}
diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix
index cbf65870eb7e..c100e21473cd 100644
--- a/pkgs/top-level/stage.nix
+++ b/pkgs/top-level/stage.nix
@@ -12,6 +12,9 @@
{ # The system (e.g., `i686-linux') for which to build the packages.
system
+, # the package set used at build-time
+ buildPackages
+
, # The standard environment to use for building packages.
stdenv
@@ -51,10 +54,13 @@ let
stdenvBootstappingAndPlatforms = self: super: {
stdenv = stdenv // { inherit platform; };
+ buildPackages = buildPackages // { recurseForDerivations = false; };
inherit
system platform crossSystem;
};
+ splice = self: super: import ./splice.nix lib self;
+
allPackages = self: super:
let res = import ./all-packages.nix
{ inherit lib nixpkgsFun noSysDirs config; }
@@ -85,6 +91,7 @@ let
stdenvBootstappingAndPlatforms
stdenvAdapters
trivialBuilders
+ splice
allPackages
aliases
stdenvOverrides