Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdenv: inline and remove actuallySplice (no effect on eval) #263278

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions pkgs/stdenv/booter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,22 @@ stageFuns: let
thisStage =
if args.__raw or false
then args'
else allPackages ((builtins.removeAttrs args' ["selfBuild"]) // {
adjacentPackages = if args.selfBuild or true then null else rec {
pkgsBuildBuild = prevStage.buildPackages;
pkgsBuildHost = prevStage;
pkgsBuildTarget =
if args.stdenv.targetPlatform == args.stdenv.hostPlatform
then pkgsBuildHost
else assert args.stdenv.hostPlatform == args.stdenv.buildPlatform; thisStage;
pkgsHostHost =
if args.stdenv.hostPlatform == args.stdenv.targetPlatform
then thisStage
else assert args.stdenv.buildPlatform == args.stdenv.hostPlatform; pkgsBuildHost;
pkgsTargetTarget = nextStage;
};
else allPackages (args' // {
adjacentPackages =
let
# search backwards from `stage` for the most recent stage containing packages which execute on `on` and target `for`
seek = stage: { on, for }@args:
if on == stage.stdenv.hostPlatform &&
for == stage.stdenv.targetPlatform
then stage
else seek stage.stdenv.__bootPackages or (throw "nixpkgs internal error: Bootstrapping stage with requested host and target platform not found.") args;
in rec {
pkgsBuildBuild = seek thisStage { on = thisStage.stdenv.buildPlatform; for = thisStage.stdenv.buildPlatform; };
pkgsBuildHost = seek thisStage { on = thisStage.stdenv.buildPlatform; for = thisStage.stdenv.hostPlatform; };
pkgsBuildTarget = seek thisStage { on = thisStage.stdenv.buildPlatform; for = thisStage.stdenv.targetPlatform; };
pkgsHostHost = seek thisStage { on = thisStage.stdenv.hostPlatform; for = thisStage.stdenv.hostPlatform; };
pkgsTargetTarget = nextStage;
};
});
in thisStage;

Expand Down
23 changes: 21 additions & 2 deletions pkgs/stdenv/cross/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ in lib.init bootStages ++ [
# Build tool Packages
(vanillaPackages: {
inherit config overlays;
selfBuild = false;
stdenv =
assert vanillaPackages.stdenv.buildPlatform == localSystem;
assert vanillaPackages.stdenv.hostPlatform == localSystem;
Expand All @@ -34,6 +33,27 @@ in lib.init bootStages ++ [
allowCustomOverrides = true;
})

# Prevent (some) unwanted assumptions about the number of stages
# from creeping in. Previously, nixpkgs contained code which
# assumed that `pkgs.stdenv.__bootPackages == pkgs.stdenv.pkgsBuildHost`.
#
# We add this no-op stage here, between pkgsBuildHost and
# pkgsHostHost, in order to deliberately break any code which
# makes that assumption -- such code will likely fail since
# `pkgs.stdenv.__bootPackages.hostPlatform !=
# pkgs.stdenv.pkgsBuildHost.hostPlatform`, and will end up trying
# to run `hostPlatform` binaries during the build.
#
# We previously had two additional no-op stages: one before
# `pkgsBuildHost`, and one after `pkgsHostHost`. However these
# appeared to increase eval-time CPU usage by 1%, which was deemed
# undesirable. See https://github.com/NixOS/nixpkgs/pull/251299
#
(prevStage: {
inherit config overlays;
inherit (prevStage) stdenv;
})

# Run Packages
(buildPackages: let
adaptStdenv =
Expand All @@ -43,7 +63,6 @@ in lib.init bootStages ++ [
in {
inherit config;
overlays = overlays ++ crossOverlays;
selfBuild = false;
stdenv = adaptStdenv (buildPackages.stdenv.override (old: rec {
buildPlatform = localSystem;
hostPlatform = crossSystem;
Expand Down
6 changes: 4 additions & 2 deletions pkgs/top-level/splice.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# 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:
lib: pkgs:

let

Expand Down Expand Up @@ -102,7 +102,9 @@ let
, pkgsHostTarget
, pkgsTargetTarget
} @ args:
if actuallySplice then spliceReal args else pkgsHostTarget;
if pkgs.stdenv.buildPlatform == pkgs.stdenv.targetPlatform
then pkgsHostTarget
else spliceReal args;

splicedPackages = splicePackages
{
Expand Down
65 changes: 35 additions & 30 deletions pkgs/top-level/stage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -115,37 +115,42 @@ let
inherit (self.pkgsBuildHost.xorg) lndir;
};

stdenvBootstappingAndPlatforms = self: super: let
withFallback = thisPkgs:
(if adjacentPackages == null then self else thisPkgs)
// { recurseForDerivations = false; };
in {
# Here are package sets of from related stages. They are all in the form
# `pkgs{theirHost}{theirTarget}`. For example, `pkgsBuildHost` means their
# host platform is our build platform, and their target platform is our host
# platform. We only care about their host/target platforms, not their build
# platform, because the the former two alone affect the interface of the
# final package; the build platform is just an implementation detail that
# should not leak.
pkgsBuildBuild = withFallback adjacentPackages.pkgsBuildBuild;
pkgsBuildHost = withFallback adjacentPackages.pkgsBuildHost;
pkgsBuildTarget = withFallback adjacentPackages.pkgsBuildTarget;
pkgsHostHost = withFallback adjacentPackages.pkgsHostHost;
pkgsHostTarget = self // { recurseForDerivations = false; }; # always `self`
pkgsTargetTarget = withFallback adjacentPackages.pkgsTargetTarget;

# Older names for package sets. Use these when only the host platform of the
# package set matter (i.e. use `buildPackages` where any of `pkgsBuild*`
# would do, and `targetPackages` when any of `pkgsTarget*` would do (if we
# had more than just `pkgsTargetTarget`).)
buildPackages = self.pkgsBuildHost;
pkgs = self.pkgsHostTarget;
targetPackages = self.pkgsTargetTarget;

inherit stdenv;
};
stdenvBootstappingAndPlatforms = self: super:
(lib.pipe {
# Here are package sets of from related stages. They are all in the form
# `pkgs{theirHost}{theirTarget}`. For example, `pkgsBuildHost` means their
# host platform is our build platform, and their target platform is our host
# platform. We only care about their host/target platforms, not their build
# platform, because the the former two alone affect the interface of the
# final package; the build platform is just an implementation detail that
# should not leak.
inherit (adjacentPackages)
pkgsBuildBuild pkgsBuildHost pkgsBuildTarget pkgsHostHost pkgsTargetTarget;
pkgsHostTarget = self; # always `self`
} [

# I'm pretty sure the following step can be removed, but it
# will cause a mass-rebuild due to a quirk in xgcc if we
# aren't splicing, replace all the packagesets with "self"
(builtins.mapAttrs (name: pkgset:
if /*name=="pkgsTargetTarget" &&*/ stdenv.buildPlatform == stdenv.targetPlatform
then self else pkgset))

# set recurseForDerivations=false on all packagesets (why?)
(builtins.mapAttrs (_: pkgset: pkgset // { recurseForDerivations = false; }))
]
) // {
# Older names for package sets. Use these when only the host platform of the
# package set matter (i.e. use `buildPackages` where any of `pkgsBuild*`
# would do, and `targetPackages` when any of `pkgsTarget*` would do (if we
# had more than just `pkgsTargetTarget`).)
buildPackages = self.pkgsBuildHost;
pkgs = self.pkgsHostTarget;
targetPackages = self.pkgsTargetTarget;
inherit stdenv;
};

splice = self: super: import ./splice.nix lib self (adjacentPackages != null);
splice = self: super: import ./splice.nix lib self;

allPackages = self: super:
let res = import ./all-packages.nix
Expand Down