Skip to content

Commit 0e070aa

Browse files
committed
Always use os-release rather than /lib to detect NixOS
[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`.
1 parent 32aa405 commit 0e070aa

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

src/bootstrap/bootstrap.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -644,22 +644,17 @@ def get_answer():
644644
return False
645645

646646
# If the user has asked binaries to be patched for Nix, then
647-
# don't check for NixOS or `/lib`.
647+
# don't check for NixOS.
648648
if self.get_toml("patch-binaries-for-nix", "build") == "true":
649649
return True
650650

651651
# Use `/etc/os-release` instead of `/etc/NIXOS`.
652652
# The latter one does not exist on NixOS when using tmpfs as root.
653653
try:
654654
with open("/etc/os-release", "r") as f:
655-
if not any(ln.strip() in ("ID=nixos", "ID='nixos'", 'ID="nixos"') for ln in f):
656-
return False
655+
return any(ln.strip() in ("ID=nixos", "ID='nixos'", 'ID="nixos"') for ln in f)
657656
except FileNotFoundError:
658657
return False
659-
if os.path.exists("/lib"):
660-
return False
661-
662-
return True
663658

664659
answer = self._should_fix_bins_and_dylibs = get_answer()
665660
if answer:

src/bootstrap/download.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl Config {
105105
matches!(l.trim(), "ID=nixos" | "ID='nixos'" | "ID=\"nixos\"")
106106
}),
107107
};
108-
is_nixos && !Path::new("/lib").exists()
108+
is_nixos
109109
});
110110
if val {
111111
eprintln!("info: You seem to be using Nix.");

0 commit comments

Comments
 (0)