Skip to content

Commit 94b72f4

Browse files
authored
Rollup merge of #89426 - davidtwco:bootstrap-nix-toolchain-env-var, r=Mark-Simulacrum
bootstrap: add config option for nix patching On NixOS systems, bootstrap will patch rustc used in bootstrapping after checking `/etc/os-release` (to confirm the current distribution is NixOS). However, when using Nix on a non-NixOS system, it can be desirable for bootstrap to patch rustc. In this commit, a `patch-binaries-for-nix` option is added to `config.toml`, which allows for user opt-in to bootstrap's Nix patching. r? ``@Mark-Simulacrum``
2 parents 87f782e + e552c0d commit 94b72f4

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

config.toml.example

+6
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ changelog-seen = 2
313313
# this setting's very existence, are all subject to change.)
314314
#print-step-rusage = false
315315

316+
# Always patch binaries for usage with Nix toolchains. If `true` then binaries
317+
# will be patched unconditionally. If `false` or unset, binaries will be patched
318+
# only if the current distribution is NixOS. This option is useful when using
319+
# a Nix toolchain on non-NixOS distributions.
320+
#patch-binaries-for-nix = false
321+
316322
# =============================================================================
317323
# General install configuration options
318324
# =============================================================================

src/bootstrap/bootstrap.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -594,19 +594,23 @@ def fix_bin_or_dylib(self, fname):
594594
if ostype != "Linux":
595595
return
596596

597-
# Use `/etc/os-release` instead of `/etc/NIXOS`.
598-
# The latter one does not exist on NixOS when using tmpfs as root.
599-
try:
600-
with open("/etc/os-release", "r") as f:
601-
if not any(line.strip() == "ID=nixos" for line in f):
602-
return
603-
except FileNotFoundError:
604-
return
605-
if os.path.exists("/lib"):
606-
return
597+
# If the user has asked binaries to be patched for Nix, then
598+
# don't check for NixOS or `/lib`, just continue to the patching.
599+
if self.get_toml('patch-binaries-for-nix', 'build') != 'true':
600+
# Use `/etc/os-release` instead of `/etc/NIXOS`.
601+
# The latter one does not exist on NixOS when using tmpfs as root.
602+
try:
603+
with open("/etc/os-release", "r") as f:
604+
if not any(line.strip() == "ID=nixos" for line in f):
605+
return
606+
except FileNotFoundError:
607+
return
608+
if os.path.exists("/lib"):
609+
return
607610

608-
# At this point we're pretty sure the user is running NixOS
609-
nix_os_msg = "info: you seem to be running NixOS. Attempting to patch"
611+
# At this point we're pretty sure the user is running NixOS or
612+
# using Nix
613+
nix_os_msg = "info: you seem to be using Nix. Attempting to patch"
610614
print(nix_os_msg, fname)
611615

612616
# Only build `.nix-deps` once.

src/bootstrap/config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ struct Build {
397397
install_stage: Option<u32>,
398398
dist_stage: Option<u32>,
399399
bench_stage: Option<u32>,
400+
patch_binaries_for_nix: Option<bool>,
400401
}
401402

402403
/// TOML representation of various global install decisions.

0 commit comments

Comments
 (0)