Rollup merge of #115090 - eopb:dont-check-lib-bootstrap, r=ozkanonur

Always use `os-release` rather than `/lib` to detect `NixOS` (bootstrap)

[Two users over on zulip](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/Bootstrapping.20on.20NixOS) bumped into issues where NixOS wasn't being properly detected.

I believe this was caused by the presence of `/lib` on their machines. `/lib` is not standard on NixOS but can still be created by users or scripts.

We are already checking `/etc/os-release`. The presence of `ID=nixos` in it's output should be trustworthy and we shouldn't then go on to also check for `/lib`.
This commit is contained in:
Michael Goulet 2023-08-22 09:00:50 -07:00 committed by GitHub
commit 634ab606a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 8 deletions

View File

@ -644,7 +644,7 @@ class RustBuild(object):
return False return False
# If the user has asked binaries to be patched for Nix, then # If the user has asked binaries to be patched for Nix, then
# don't check for NixOS or `/lib`. # don't check for NixOS.
if self.get_toml("patch-binaries-for-nix", "build") == "true": if self.get_toml("patch-binaries-for-nix", "build") == "true":
return True return True
@ -652,14 +652,9 @@ class RustBuild(object):
# The latter one does not exist on NixOS when using tmpfs as root. # The latter one does not exist on NixOS when using tmpfs as root.
try: try:
with open("/etc/os-release", "r") as f: with open("/etc/os-release", "r") as f:
if not any(ln.strip() in ("ID=nixos", "ID='nixos'", 'ID="nixos"') for ln in f): return any(ln.strip() in ("ID=nixos", "ID='nixos'", 'ID="nixos"') for ln in f)
return False
except FileNotFoundError: except FileNotFoundError:
return False return False
if os.path.exists("/lib"):
return False
return True
answer = self._should_fix_bins_and_dylibs = get_answer() answer = self._should_fix_bins_and_dylibs = get_answer()
if answer: if answer:

View File

@ -105,7 +105,7 @@ impl Config {
matches!(l.trim(), "ID=nixos" | "ID='nixos'" | "ID=\"nixos\"") matches!(l.trim(), "ID=nixos" | "ID='nixos'" | "ID=\"nixos\"")
}), }),
}; };
is_nixos && !Path::new("/lib").exists() is_nixos
}); });
if val { if val {
eprintln!("info: You seem to be using Nix."); eprintln!("info: You seem to be using Nix.");