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
2016-12-18 07:51:18 +00:00
|
|
|
# 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.
|
2017-01-15 23:03:59 +00:00
|
|
|
#
|
|
|
|
# For performance reasons, rather than uniformally splice in all cases, we only
|
|
|
|
# do so when `pkgs` and `buildPackages` are distinct. The `actuallySplice`
|
|
|
|
# parameter there the boolean value of that equality check.
|
|
|
|
lib: pkgs: actuallySplice:
|
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
2016-12-18 07:51:18 +00:00
|
|
|
|
|
|
|
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
|
2017-09-19 19:46:43 +01:00
|
|
|
getOutputs = value: lib.genAttrs
|
|
|
|
(value.outputs or (lib.optional (value ? out) "out"))
|
|
|
|
(output: value.${output});
|
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
2016-12-18 07:51:18 +00:00
|
|
|
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));
|
|
|
|
|
2017-01-15 23:03:59 +00:00
|
|
|
splicedPackages =
|
|
|
|
if actuallySplice
|
2017-02-06 23:13:02 +00:00
|
|
|
then splicer defaultBuildScope defaultRunScope // {
|
|
|
|
# These should never be spliced under any circumstances
|
2017-10-31 14:50:08 +00:00
|
|
|
inherit (pkgs) pkgs buildPackages targetPackages
|
2017-02-06 23:13:02 +00:00
|
|
|
buildPlatform targetPlatform hostPlatform;
|
|
|
|
}
|
2017-01-15 23:03:59 +00:00
|
|
|
else pkgs // pkgs.xorg;
|
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
2016-12-18 07:51:18 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
# 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);
|
|
|
|
}
|