Commit 0a800749 authored by Daniel Fullmer's avatar Daniel Fullmer Committed by Jonathan Ringer
Browse files

bash: use default PATH in FHS environments

If bash is executed within an environment where PATH is not set, it uses
the DEFAULT_PATH_VALUE compiled into bash to set PATH. In nixpkgs we set
this to /no-such-path by default. This makes sense in a nixpkgs/NixOS
environment since paths like /bin or /usr/bin should not be used.
However, when bash is used inside an FHS environment, this produces
results that differ from distributions which follow the FHS standard.

Before this change:
$ steam-run env -i /bin/bash -c 'echo $PATH'
/no-such-path

After this change:
$ steam-run env -i /bin/bash -c 'echo $PATH'
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:.
parent f4676c4c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ let
  basePkgs = with pkgs;
    [ glibcLocales
      (if isMultiBuild then glibc_multi else glibc)
      (toString gcc.cc.lib) bashInteractive coreutils less shadow su
      (toString gcc.cc.lib) bashInteractiveFHS coreutils less shadow su
      gawk diffutils findutils gnused gnugrep
      gnutar gzip bzip2 xz
    ];
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ let
  basePkgs = with pkgs;
    [ glibcLocales
      (if isMultiBuild then glibc_multi else glibc)
      (toString gcc.cc.lib) bashInteractive coreutils less shadow su
      (toString gcc.cc.lib) bashInteractiveFHS coreutils less shadow su
      gawk diffutils findutils gnused gnugrep
      gnutar gzip bzip2 xz
    ];
+3 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
, readline81 ? null
, withDocs ? false
, texinfo ? null
, forFHSEnv ? false
}:

with lib;
@@ -39,8 +40,10 @@ stdenv.mkDerivation rec {
  NIX_CFLAGS_COMPILE = ''
    -DSYS_BASHRC="/etc/bashrc"
    -DSYS_BASH_LOGOUT="/etc/bash_logout"
  '' + optionalString (!forFHSEnv) ''
    -DDEFAULT_PATH_VALUE="/no-such-path"
    -DSTANDARD_UTILS_PATH="/no-such-path"
  '' + ''
    -DNON_INTERACTIVE_LOGIN_SHELLS
    -DSSH_SOURCE_BASHRC
  '';
+6 −0
Original line number Diff line number Diff line
@@ -11550,6 +11550,12 @@ with pkgs;
    interactive = true;
    withDocs = true;
  };
  bashInteractiveFHS = callPackage ../shells/bash/5.1.nix {
    binutils = stdenv.cc.bintools;
    interactive = true;
    withDocs = true;
    forFHSEnv = true;
  };
  bash-completion = callPackage ../shells/bash/bash-completion { };