diff --git a/config.toml.example b/config.toml.example index aff4e8fa82ac1..d811b914d20a1 100644 --- a/config.toml.example +++ b/config.toml.example @@ -313,6 +313,12 @@ changelog-seen = 2 # this setting's very existence, are all subject to change.) #print-step-rusage = false +# Always patch binaries for usage with Nix toolchains. If `true` then binaries +# will be patched unconditionally. If `false` or unset, binaries will be patched +# only if the current distribution is NixOS. This option is useful when using +# a Nix toolchain on non-NixOS distributions. +#patch-binaries-for-nix = false + # ============================================================================= # General install configuration options # ============================================================================= diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 57ade88f73306..05d7b0f611f72 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -594,19 +594,23 @@ def fix_bin_or_dylib(self, fname): if ostype != "Linux": return - # Use `/etc/os-release` instead of `/etc/NIXOS`. - # The latter one does not exist on NixOS when using tmpfs as root. - try: - with open("/etc/os-release", "r") as f: - if not any(line.strip() == "ID=nixos" for line in f): - return - except FileNotFoundError: - return - if os.path.exists("/lib"): - return + # If the user has asked binaries to be patched for Nix, then + # don't check for NixOS or `/lib`, just continue to the patching. + if self.get_toml('patch-binaries-for-nix', 'build') != 'true': + # Use `/etc/os-release` instead of `/etc/NIXOS`. + # The latter one does not exist on NixOS when using tmpfs as root. + try: + with open("/etc/os-release", "r") as f: + if not any(line.strip() == "ID=nixos" for line in f): + return + except FileNotFoundError: + return + if os.path.exists("/lib"): + return - # At this point we're pretty sure the user is running NixOS - nix_os_msg = "info: you seem to be running NixOS. Attempting to patch" + # At this point we're pretty sure the user is running NixOS or + # using Nix + nix_os_msg = "info: you seem to be using Nix. Attempting to patch" print(nix_os_msg, fname) # Only build `.nix-deps` once. diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 5706b8f9e7cc6..062820040dc78 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -397,6 +397,7 @@ struct Build { install_stage: Option, dist_stage: Option, bench_stage: Option, + patch_binaries_for_nix: Option, } /// TOML representation of various global install decisions.