diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2023-08-22 17:45:54 -0400 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2023-08-22 17:45:54 -0400 |
| commit | 3c6f4cc743316ff4b7f76a6492f78d6eb83dcf50 (patch) | |
| tree | b1a7e2c301f4109e59d4f5bdea9341db047596f1 /src/bootstrap/bootstrap.py | |
| parent | 4332e8417d15f304741208e82ab969768f0dc11d (diff) | |
| download | rust-3c6f4cc743316ff4b7f76a6492f78d6eb83dcf50.tar.gz rust-3c6f4cc743316ff4b7f76a6492f78d6eb83dcf50.zip | |
Better diagnostics for people using nix subshell on non-NixOS.
1. Turned patch-binaries-for-nix from a boolean into a ternary flag: true, false, and unset. 2. When patch-binaries-for-nix is unset, we continue with the existing NixOS detection heuristic (look for nixos in /etc/os-release, if present), but if we are not atop NixOS, then issue a note if we see the IN_NIX_SHELL environment variable telling the user to consider setting patch-binaries-for-nix explicitly.
Diffstat (limited to 'src/bootstrap/bootstrap.py')
| -rw-r--r-- | src/bootstrap/bootstrap.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index c71ecc0a139..588164e4a85 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -643,18 +643,33 @@ class RustBuild(object): if ostype != "Linux": return False - # If the user has asked binaries to be patched for Nix, then - # don't check for NixOS. + # If the user has explicitly indicated whether binaries should be + # patched for Nix, then don't check for NixOS. if self.get_toml("patch-binaries-for-nix", "build") == "true": return True + if self.get_toml("patch-binaries-for-nix", "build") == "false": + return False + + # Assume we should fix until we see evidence that it is not NixOS + should_fix_retval = 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: - return any(ln.strip() in ("ID=nixos", "ID='nixos'", 'ID="nixos"') for ln in f) + should_fix_retval = any(ln.strip() in ("ID=nixos", "ID='nixos'", 'ID="nixos"') for ln in f) except FileNotFoundError: - return False + should_fix_retval = False + + # If not on NixOS, then warn if user seems to be atop Nix shell + if not should_fix_retval: + in_nix_shell = os.getenv('IN_NIX_SHELL') + if in_nix_shell: + print("The IN_NIX_SHELL environment variable is set to `{}`;".format(in_nix_shell), + "you may need to set `patch-binaries-for-nix=true` in your config.toml", + file=sys.stderr) + + return should_fix_retval answer = self._should_fix_bins_and_dylibs = get_answer() if answer: |
