freshBootstrapTools.bootstrapTools: extract as a sort of package

This commit is contained in:
Philip Taron 2024-08-02 17:16:29 -07:00
parent 052ecdbfae
commit 2587d88ee8
No known key found for this signature in database
3 changed files with 45 additions and 28 deletions

View File

@ -0,0 +1,35 @@
{
lib,
libc,
config,
system,
bootstrapFiles,
isFromBootstrapFiles ? false,
}:
let
maybeDenoteProvenance = lib.optionalAttrs isFromBootstrapFiles {
passthru = {
inherit isFromBootstrapFiles;
};
};
maybeContentAddressed = lib.optionalAttrs config.contentAddressedByDefault {
__contentAddressed = true;
outputHashAlgo = "sha256";
outputHashMode = "recursive";
};
args = {
inherit system bootstrapFiles;
extraAttrs = maybeContentAddressed;
};
result =
if libc == "glibc" then
import ./glibc.nix args
else if libc == "musl" then
import ./musl.nix args
else
throw "unsupported libc";
in
result // maybeDenoteProvenance

View File

@ -139,14 +139,11 @@ let
# Download and unpack the bootstrap tools (coreutils, GCC, Glibc, ...).
bootstrapTools = (import (if localSystem.libc == "musl" then ./bootstrap-tools/musl.nix else ./bootstrap-tools/glibc.nix) {
inherit system bootstrapFiles;
extraAttrs = lib.optionalAttrs config.contentAddressedByDefault {
__contentAddressed = true;
outputHashAlgo = "sha256";
outputHashMode = "recursive";
};
}) // { passthru.isFromBootstrapFiles = true; };
bootstrapTools = import ./bootstrap-tools {
inherit (localSystem) libc system;
inherit lib bootstrapFiles config;
isFromBootstrapFiles = true;
};
getLibc = stage: stage.${localSystem.libc};

View File

@ -49,26 +49,11 @@ rec {
inherit (build) bootstrapFiles;
bootstrapTools =
let extraAttrs = lib.optionalAttrs
config.contentAddressedByDefault
{
__contentAddressed = true;
outputHashAlgo = "sha256";
outputHashMode = "recursive";
};
in
if (stdenv.hostPlatform.libc == "glibc") then
import ./bootstrap-tools/glibc.nix {
inherit (stdenv.buildPlatform) system; # Used to determine where to build
inherit bootstrapFiles extraAttrs;
}
else if (stdenv.hostPlatform.libc == "musl") then
import ./bootstrap-tools/musl.nix {
inherit (stdenv.buildPlatform) system; # Used to determine where to build
inherit bootstrapFiles extraAttrs;
}
else throw "unsupported libc";
bootstrapTools = import ./bootstrap-tools {
inherit (stdenv.buildPlatform) system; # Used to determine where to build
inherit (stdenv.hostPlatform) libc;
inherit lib bootstrapFiles config;
};
test = pkgs.callPackage ./test-bootstrap-tools.nix {
inherit bootstrapTools;