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

darwin.stdenv: allow patchShebangs during the bootstrap #242519

Merged
merged 1 commit into from
Jul 10, 2023
Merged
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
38 changes: 26 additions & 12 deletions pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ let
stdenvNoCC = prevStage.ccWrapperStdenv;
};

bash = prevStage.bash or bootstrapTools;

thisStdenv = import ../generic {
name = "${name}-stdenv-darwin";

Expand All @@ -159,18 +161,19 @@ let

extraBuildInputs = [ prevStage.darwin.CF ];

preHook = ''
preHook = lib.optionalString (!isBuiltByNixpkgsCompiler bash) ''
# Don't patch #!/interpreter because it leads to retained
# dependencies on the bootstrapTools in the final stdenv.
dontPatchShebangs=1
'' + ''
${commonPreHook prevStage}
${extraPreHook}
'' + lib.optionalString (prevStage.darwin ? locale) ''
export PATH_LOCALE=${prevStage.darwin.locale}/share/locale
'';

shell = "${bootstrapTools}/bin/bash";
initialPath = [ bootstrapTools ];
shell = bash + "/bin/bash";
initialPath = [ bash bootstrapTools ];

fetchurlBoot = import ../../build-support/fetchurl {
inherit lib;
Expand Down Expand Up @@ -242,6 +245,8 @@ in
# stage should only access the stage that came before it.
ccWrapperStdenv = self.stdenv;

bash = bootstrapTools;

coreutils = bootstrapTools;
gnugrep = bootstrapTools;

Expand Down Expand Up @@ -445,7 +450,7 @@ in
# making sure both packages are present on x86_64-darwin and aarch64-darwin.
(prevStage:
# previous stage0 stdenv:
assert lib.all isFromBootstrapFiles (with prevStage; [ coreutils cpio gnugrep pbzx ]);
assert lib.all isFromBootstrapFiles (with prevStage; [ bash coreutils cpio gnugrep pbzx ]);

assert lib.all isFromBootstrapFiles (with prevStage.darwin; [
binutils-unwrapped cctools print-reexports rewrite-tbd sigtool system_cmds
Expand Down Expand Up @@ -727,7 +732,8 @@ in
'';
})

# This stage rebuilds Libsystem.
# This stage rebuilds Libsystem. It also rebuilds bash, which will be needed in later stages
# to use in patched shebangs (e.g., to make sure `icu-config` uses bash from nixpkgs).
(prevStage:
# previous stage-xclang stdenv:
assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage; [
Expand Down Expand Up @@ -764,13 +770,19 @@ in

overrides = self: super: {
inherit (prevStage) ccWrapperStdenv
autoconf automake bash binutils-unwrapped bison brotli cmake cmakeMinimal coreutils
autoconf automake binutils-unwrapped bison brotli cmake cmakeMinimal coreutils
cpio curl cyrus_sasl db ed expat flex gettext gmp gnugrep groff icu libedit libffi
libiconv libidn2 libkrb5 libssh2 libtool libunistring libxml2 m4 ncurses nghttp2
ninja openbsm openldap openpam openssh openssl patchutils pbzx perl pkg-config
python3 python3Minimal scons serf sqlite subversion sysctl texinfo unzip which xz
zlib zstd;

# Bash must be linked against the system CoreFoundation instead of the open-source one.
# Otherwise, there will be a dependency cycle: bash -> CF -> icu -> bash (for icu^dev).
bash = super.bash.overrideAttrs (super: {
buildInputs = super.buildInputs ++ [ self.darwin.apple_sdk.frameworks.CoreFoundation ];
});

darwin = super.darwin.overrideScope (selfDarwin: superDarwin: {
inherit (prevStage.darwin)
CF binutils-unwrapped cctools configd darwin-stubs launchd libobjc libtapi locale
Expand Down Expand Up @@ -822,13 +834,15 @@ in
(prevStage:
# previous stage2-Libsystem stdenv:
assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage; [
autoconf automake bash binutils-unwrapped bison brotli cmake cmakeMinimal coreutils
autoconf automake binutils-unwrapped bison brotli cmake cmakeMinimal coreutils
cpio curl cyrus_sasl db ed expat flex gettext gmp gnugrep groff icu libedit libidn2
libkrb5 libssh2 libtool libunistring m4 nghttp2 ninja openbsm openldap openpam openssh
openssl patchutils pbzx perl pkg-config.pkg-config python3 python3Minimal scons serf
sqlite subversion sysctl.provider texinfo unzip which xz zstd
]);

assert lib.all isBuiltByNixpkgsCompiler (with prevStage; [ bash ]);

assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage; [
libffi libiconv libxml2 ncurses zlib zstd
]);
Expand Down Expand Up @@ -946,14 +960,14 @@ in
(prevStage:
# previous stage2-CF stdenv:
assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage; [
autoconf automake bash bison brotli cmake cmakeMinimal coreutils cpio curl cyrus_sasl
autoconf automake bison brotli cmake cmakeMinimal coreutils cpio curl cyrus_sasl
db ed expat flex gettext gmp gnugrep groff libedit libidn2 libkrb5 libssh2 libtool
libunistring m4 ncurses nghttp2 ninja openbsm openldap openpam openssh openssl
patchutils pbzx perl pkg-config.pkg-config python3 python3Minimal scons serf sqlite
subversion sysctl.provider texinfo unzip which xz zstd
]);
assert lib.all isBuiltByNixpkgsCompiler (with prevStage; [
binutils-unwrapped icu libffi libiconv libxml2 zlib
bash binutils-unwrapped icu libffi libiconv libxml2 zlib
]);

assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [
Expand Down Expand Up @@ -1025,15 +1039,15 @@ in
(prevStage:
# previous stage3 stdenv:
assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage; [
autoconf automake bash bison brotli cmake cmakeMinimal coreutils cpio curl cyrus_sasl
autoconf automake bison brotli cmake cmakeMinimal coreutils cpio curl cyrus_sasl
db ed expat flex gettext gmp gnugrep groff libedit libidn2 libkrb5 libssh2 libtool
libunistring m4 nghttp2 ninja openbsm openldap openpam openssh openssl patchutils pbzx
perl pkg-config.pkg-config python3 python3Minimal scons serf sqlite subversion
sysctl.provider texinfo unzip which xz zstd
]);

assert lib.all isBuiltByNixpkgsCompiler (with prevStage; [
binutils-unwrapped icu libffi libiconv libxml2 zlib
bash binutils-unwrapped icu libffi libiconv libxml2 zlib
]);

assert lib.all isBuiltByBootstrapFilesCompiler (with prevStage.darwin; [
Expand All @@ -1060,7 +1074,7 @@ in

overrides = self: super: {
inherit (prevStage) ccWrapperStdenv
autoconf automake bison cmake cmakeMinimal cpio cyrus_sasl db expat flex groff
autoconf automake bash bison cmake cmakeMinimal cpio cyrus_sasl db expat flex groff
libedit libtool m4 ninja openldap openssh patchutils pbzx perl pkg-config python3
python3Minimal scons serf sqlite subversion sysctl texinfo unzip which

Expand Down