From 2587d88ee89b4b29870703d94090f37c97d9f3af Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Fri, 2 Aug 2024 17:16:29 -0700 Subject: [PATCH] freshBootstrapTools.bootstrapTools: extract as a sort of package --- pkgs/stdenv/linux/bootstrap-tools/default.nix | 35 +++++++++++++++++++ pkgs/stdenv/linux/default.nix | 13 +++---- pkgs/stdenv/linux/make-bootstrap-tools.nix | 25 +++---------- 3 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 pkgs/stdenv/linux/bootstrap-tools/default.nix diff --git a/pkgs/stdenv/linux/bootstrap-tools/default.nix b/pkgs/stdenv/linux/bootstrap-tools/default.nix new file mode 100644 index 000000000000..2314fe84d9d0 --- /dev/null +++ b/pkgs/stdenv/linux/bootstrap-tools/default.nix @@ -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 diff --git a/pkgs/stdenv/linux/default.nix b/pkgs/stdenv/linux/default.nix index 7b6718ae2d80..1f1c4771d167 100644 --- a/pkgs/stdenv/linux/default.nix +++ b/pkgs/stdenv/linux/default.nix @@ -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}; diff --git a/pkgs/stdenv/linux/make-bootstrap-tools.nix b/pkgs/stdenv/linux/make-bootstrap-tools.nix index 5796154b6b53..31e16ab6ad7e 100644 --- a/pkgs/stdenv/linux/make-bootstrap-tools.nix +++ b/pkgs/stdenv/linux/make-bootstrap-tools.nix @@ -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;