Skip to content

Commit

Permalink
stdenv: native aarch64-darwin bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
stephank committed Jan 3, 2023
1 parent 283ca25 commit 7be022c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 105 deletions.
49 changes: 17 additions & 32 deletions pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,19 @@
, crossOverlays ? [ ]
, bootstrapLlvmVersion ? "11.1.0"
# Allow passing in bootstrap files directly so we can test the stdenv bootstrap process when changing the bootstrap tools
, bootstrapFiles ? if localSystem.isAarch64 then
let
fetch = { file, sha256, executable ? true }: import <nix/fetchurl.nix> {
url = "http://tarballs.nixos.org/stdenv-darwin/aarch64/20acd4c4f14040485f40e55c0a76c186aa8ca4f3/${file}";
inherit (localSystem) system;
inherit sha256 executable;
}; in
{
sh = fetch { file = "sh"; sha256 = "17m3xrlbl99j3vm7rzz3ghb47094dyddrbvs2a6jalczvmx7spnj"; };
bzip2 = fetch { file = "bzip2"; sha256 = "1khs8s5klf76plhlvlc1ma838r8pc1qigk9f5bdycwgbn0nx240q"; };
mkdir = fetch { file = "mkdir"; sha256 = "1m9nk90paazl93v43myv2ay68c1arz39pqr7lk5ddbgb177hgg8a"; };
cpio = fetch { file = "cpio"; sha256 = "17pxq61yjjvyd738fy9f392hc9cfzkl612sdr9rxr3v0dgvm8y09"; };
tarball = fetch { file = "bootstrap-tools.cpio.bz2"; sha256 = "1v2332k33akm6mrm4bj749rxnnmc2pkbgcslmd0bbkf76bz2ildy"; executable = false; };
}
else
let
fetch = { file, sha256, executable ? true }: import <nix/fetchurl.nix> {
url = "http://tarballs.nixos.org/stdenv-darwin/x86_64/c253216595572930316f2be737dc288a1da22558/${file}";
inherit (localSystem) system;
inherit sha256 executable;
}; in
{
sh = fetch { file = "sh"; sha256 = "sha256-igMAVEfumFv/LUNTGfNi2nSehgTNIP4Sg+f3L7u6SMA="; };
bzip2 = fetch { file = "bzip2"; sha256 = "sha256-K3rhkJZipudT1Jgh+l41Y/fNsMkrPtiAsNRDha/lpZI="; };
mkdir = fetch { file = "mkdir"; sha256 = "sha256-VddFELwLDJGNADKB1fWwWPBtIAlEUgJv2hXRmC4NEeM="; };
cpio = fetch { file = "cpio"; sha256 = "sha256-SWkwvLaFyV44kLKL2nx720SvcL4ej/p2V/bX3uqAGO0="; };
tarball = fetch { file = "bootstrap-tools.cpio.bz2"; sha256 = "sha256-kRC/bhCmlD4L7KAvJQgcukk7AinkMz4IwmG1rqlh5tA="; executable = false; };
}
, bootstrapFiles ? if localSystem.isAarch64 then {
tools = import <nix/fetchurl.nix> {
url = "https://stephank.nl/dump/aarch64-darwin-bootstrap-tools.nar.xz";
hash = "sha256-6UrovvsIkvzp8YS2/KuOiy45LoGDjPz3lM7V5RfQico=";
unpack = true;
};
} else {
tools = import <nix/fetchurl.nix> {
url = "https://stephank.nl/dump/x86_64-darwin-bootstrap-tools.nar.xz";
hash = "sha256-HuV3CEpb/CX9VUbc+rmgf9qwxb+yVhIwT5YadNx/EHE=";
unpack = true;
};
}
}:

assert crossSystem == localSystem;
Expand Down Expand Up @@ -69,10 +54,10 @@ rec {
inherit system;

name = "bootstrap-tools";
builder = bootstrapFiles.sh; # Not a filename! Attribute 'sh' on bootstrapFiles
args = if localSystem.isAarch64 then [ ./unpack-bootstrap-tools-aarch64.sh ] else [ ./unpack-bootstrap-tools.sh ];
builder = "${bootstrapFiles.tools}/bin/bash";
args = [ ./patch-bootstrap-tools.sh ];

inherit (bootstrapFiles) mkdir bzip2 cpio tarball;
inherit (bootstrapFiles) tools;

__impureHostDeps = commonImpureHostDeps;
} // lib.optionalAttrs config.contentAddressedByDefault {
Expand Down Expand Up @@ -231,7 +216,7 @@ rec {

cpio = self.runCommandLocal "bootstrap-stage0-cpio" { } ''
mkdir -p $out/bin
ln -s ${bootstrapFiles.cpio} $out/bin/cpio
ln -s ${bootstrapTools}/bin/cpio $out/bin/cpio
'';

darwin = super.darwin.overrideScope (selfDarwin: superDarwin: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
set -euo pipefail

# Unpack the bootstrap tools tarball.
echo Unpacking the bootstrap tools...
$mkdir $out
$bzip2 -d < $tarball | (cd $out && $cpio -i)
export PATH=$tools/bin

export PATH=$out/bin

# Fix codesign wrapper paths
sed -i \
-e "1c\
#!$out/bin/bash" \
-e "s|[^( ]*\bsigtool\b|$out/bin/sigtool|g" \
$out/bin/codesign
cp -R $tools $out
chmod -R u+w $out

updateInstallName() {
local path="$1"
Expand All @@ -23,11 +14,6 @@ updateInstallName() {
mv -f "$path.new" "$path"
}

find $out

ln -s bash $out/bin/sh
ln -s bzip2 $out/bin/bunzip2

find $out/lib -type f -name '*.dylib' -print0 | while IFS= read -r -d $'\0' lib; do
updateInstallName "$lib"
done
Expand Down
54 changes: 0 additions & 54 deletions pkgs/stdenv/darwin/unpack-bootstrap-tools.sh

This file was deleted.

3 changes: 1 addition & 2 deletions pkgs/top-level/release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ let
# Lightweight distribution and test
inherit (bootstrap) dist test;
# Test a full stdenv bootstrap from the bootstrap tools definition
# TODO: Re-enable once the new bootstrap-tools are in place.
#inherit (bootstrap.test-pkgs) stdenv;
inherit (bootstrap.test-pkgs) stdenv;
}
else
abort "No bootstrap implementation for system: ${system}"
Expand Down

0 comments on commit 7be022c

Please sign in to comment.