5 , updateAutotoolsGnuConfigScriptsHook
9 # patch for cygwin requires readline support
10 , interactive ? stdenv.isCygwin
20 upstreamPatches = import ./bash-5.2-patches.nix (nr: sha256: fetchurl {
21 url = "mirror://gnu/bash/bash-5.2-patches/bash52-${nr}";
25 stdenv.mkDerivation rec {
26 pname = "bash${lib.optionalString interactive "-interactive"}";
27 version = "5.2${patch_suffix}";
28 patch_suffix = "p${toString (builtins.length upstreamPatches)}";
31 url = "mirror://gnu/bash/bash-${lib.removeSuffix patch_suffix version}.tar.gz";
32 sha256 = "sha256-oTnBZt9/9EccXgczBRZC7lVWwcyKSnjxRVg8XIGrMvs=";
35 hardeningDisable = [ "format" ]
36 # bionic libc is super weird and has issues with fortify outside of its own libc, check this comment:
37 # https://github.com/NixOS/nixpkgs/pull/192630#discussion_r978985593
38 # or you can check libc/include/sys/cdefs.h in bionic source code
39 ++ lib.optional (stdenv.hostPlatform.libc == "bionic") "fortify";
41 outputs = [ "out" "dev" "man" "doc" "info" ];
43 separateDebugInfo = true;
45 env.NIX_CFLAGS_COMPILE = ''
46 -DSYS_BASHRC="/etc/bashrc"
47 -DSYS_BASH_LOGOUT="/etc/bash_logout"
48 '' + lib.optionalString (!forFHSEnv) ''
49 -DDEFAULT_PATH_VALUE="/no-such-path"
50 -DSTANDARD_UTILS_PATH="/no-such-path"
52 -DNON_INTERACTIVE_LOGIN_SHELLS
56 patchFlags = [ "-p0" ];
58 patches = upstreamPatches ++ [
61 name = "fix-static.patch";
62 url = "https://cgit.freebsd.org/ports/plain/shells/bash/files/patch-configure?id=3e147a1f594751a68fea00a28090d0792bee0b51";
63 sha256 = "XHFMQ6eXTReNoywdETyrfQEv1rKF8+XFbQZP4YoVKFk=";
65 # Apply parallel build fix pending upstream inclusion:
66 # https://savannah.gnu.org/patch/index.php?10373
67 # Had to fetch manually to workaround -p0 default.
72 # At least on Linux bash memory allocator has pathological performance
73 # in scenarios involving use of larger memory:
74 # https://lists.gnu.org/archive/html/bug-bash/2023-08/msg00052.html
75 # Various distributions default to system allocator. Let's nixpkgs
77 "--without-bash-malloc"
78 (if interactive then "--with-installed-readline" else "--disable-readline")
79 ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
80 "bash_cv_job_control_missing=nomissing"
81 "bash_cv_sys_named_pipes=nomissing"
82 "bash_cv_getcwd_malloc=yes"
83 # This check cannot be performed when cross compiling. The "yes"
84 # default is fine for static linking on Linux (weak symbols?) but
85 # not with OpenBSD, when it does clash with the regular `getenv`.
86 "bash_cv_getenv_redef=${if !(with stdenv.hostPlatform; isStatic && isOpenBSD) then "yes" else "no"}"
87 ] ++ lib.optionals stdenv.hostPlatform.isCygwin [
88 "--without-libintl-prefix"
89 "--without-libiconv-prefix"
90 "--with-installed-readline"
91 "bash_cv_dev_stdin=present"
92 "bash_cv_dev_fd=standard"
93 "bash_cv_termcap_lib=libncurses"
94 ] ++ lib.optionals (stdenv.hostPlatform.libc == "musl") [
96 ] ++ lib.optionals stdenv.hostPlatform.isFreeBSD [
97 # /dev/fd is optional on FreeBSD. we need it to work when built on a system
98 # with it and transferred to a system without it! This includes linux cross.
99 "bash_cv_dev_fd=absent"
103 # Note: Bison is needed because the patches above modify parse.y.
104 depsBuildBuild = [ buildPackages.stdenv.cc ];
105 nativeBuildInputs = [ updateAutotoolsGnuConfigScriptsHook bison ]
106 ++ lib.optional withDocs texinfo
107 ++ lib.optional stdenv.hostPlatform.isDarwin stdenv.cc.bintools;
109 buildInputs = lib.optional interactive readline;
111 enableParallelBuilding = true;
113 makeFlags = lib.optionals stdenv.hostPlatform.isCygwin [
114 "LOCAL_LDFLAGS=-Wl,--export-all,--out-implib,libbash.dll.a"
118 nativeCheckInputs = [ util-linux ];
119 doCheck = false; # dependency cycle, needs to be interactive
122 ln -s bash "$out/bin/sh"
123 rm -f $out/lib/bash/Makefile.inc
129 substituteInPlace "$out/bin/bashbug" \
130 --replace '#!/bin/sh' "#!$out/bin/bash"
132 # most space is taken by locale data
134 rm -rf "$out/share" "$out/bin/bashbug"
138 shellPath = "/bin/bash";
139 tests.static = pkgsStatic.bash;
143 homepage = "https://www.gnu.org/software/bash/";
144 description = "GNU Bourne-Again Shell, the de facto standard shell on Linux" + lib.optionalString interactive " (for interactive use)";
146 Bash is the shell, or command language interpreter, that will
147 appear in the GNU operating system. Bash is an sh-compatible
148 shell that incorporates useful features from the Korn shell
149 (ksh) and C shell (csh). It is intended to conform to the IEEE
150 POSIX P1003.2/ISO 9945.2 Shell and Tools standard. It offers
151 functional improvements over sh for both programming and
152 interactive use. In addition, most sh scripts can be run by
153 Bash without modification.
155 license = licenses.gpl3Plus;
156 platforms = platforms.all;
157 maintainers = with maintainers; [ ];
158 mainProgram = "bash";