1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014, 2015, 2018 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2015, 2017 Leo Famulari <leo@famulari.name>
5 ;;; Copyright © 2016, 2017, 2018, 2019 Efraim Flashner <efraim@flashner.co.il>
6 ;;; Copyright © 2018, 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
7 ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
9 ;;; This file is part of GNU Guix.
11 ;;; GNU Guix is free software; you can redistribute it and/or modify it
12 ;;; under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 3 of the License, or (at
14 ;;; your option) any later version.
16 ;;; GNU Guix is distributed in the hope that it will be useful, but
17 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;;; GNU General Public License for more details.
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24 (define-module (gnu packages bash)
25 #:use-module (guix licenses)
26 #:use-module (gnu packages)
27 #:use-module (gnu packages base)
28 #:use-module (gnu packages bootstrap)
29 #:use-module (gnu packages ncurses)
30 #:use-module (gnu packages readline)
31 #:use-module (gnu packages bison)
32 #:use-module (gnu packages linux)
33 #:use-module (gnu packages guile)
34 #:use-module (guix packages)
35 #:use-module (guix download)
36 #:use-module (guix git-download)
37 #:use-module (guix utils)
38 #:use-module (guix gexp)
39 #:use-module (guix monads)
40 #:use-module (guix store)
41 #:use-module (guix build-system gnu)
42 #:use-module (guix build-system trivial)
43 #:autoload (guix gnupg) (gnupg-verify*)
44 #:autoload (guix base32) (bytevector->nix-base32-string)
46 ;; See <https://bugs.gnu.org/41457> for why not #:autoload here.
47 #:use-module ((gcrypt hash) #:select (port-sha256))
49 #:use-module (srfi srfi-1)
50 #:use-module (srfi srfi-26)
51 #:use-module (ice-9 format))
53 (define (patch-url seqno)
54 "Return the URL of Bash patch number SEQNO."
55 (format #f "mirror://gnu/bash/bash-5.0-patches/bash50-~3,'0d" seqno))
57 (define (bash-patch seqno sha256-bv)
58 "Return the origin of Bash patch SEQNO, with expected hash SHA256-BV."
61 (uri (patch-url seqno))
64 (define-syntax-rule (patch-series (seqno hash) ...)
65 (list (bash-patch seqno (base32 hash))
68 (define %patch-series-5.0
69 ;; This is the current patches series for 5.0, generated using
70 ;; 'download-patches' below.
72 (1 "12bjfdy6bg8nhyw27bdgxn7h4paylx8d927skfmi9pxd1wgrxzpj")
73 (2 "01w7yrzmz10mw06ys0546vhl7isv2v402ziyvfd7k67588spvs47")
74 (3 "0ny81ridp5n0j69hb8ixrc7dmxybby54jbsz5hikly8kgg1wvssf")
75 (4 "021gqqvgydixkrmqss64b6srfdlkvnx88lyfzpxfrn5d6bc7li0l")
76 (5 "0xl2kyzm84nlyklrqzkn73ixabhzfhn9x91lzcmis89cppclvxav")
77 (6 "0844749ixk1z60437nkznzms1f0nzh9an62kj7sny6r0zyk2k1fn")
78 (7 "16xg37gp1b8zlj5969w8mcrparwqlcbj9695vn3qhgb7wdz1xd0p")
79 (8 "1qyp19krjh8zxvb0jgwmyjz40djslwcf4xi7kc1ab0iaca44bipf")
80 (9 "00yrjjqd95s81b21qq3ba1y7h879q8jaajlkjggc6grhcwbs4g7d")
81 (10 "04ca5bjv456v538mkspzvn4xb2zdphh31r4fpvfm9p5my0jw7yyn")
82 (11 "1sklyixvsv8993kxzs0jigacpdchjrq7jv5xpdx7kbqyp4rf6k9c")
83 (12 "0cz21qg2gbr40lfgza7g02bqi2qknwqgxnq459pjj640d0cywhr9")
84 (13 "16h9nwz3yzwj7fnxvlidjymdc4yr30h818433gh9j1x3in6igmzm")
85 (14 "12gm5bvv2pd3m72z2ilj26pa08c61az253dsgfl24vpf2ijywvjx")
86 (15 "0pm0px758w4i23s55wajcv6lqfiym7zgxvq0pxf6vclkv8nxy5x5")
87 (16 "0vdha332km2iwx8g2ld15jy7d24cbplzgr1531dpzylr9ajxglgz")))
89 (define (download-patches store count)
90 "Download COUNT Bash patches into store. Return a list of
91 number/base32-hash tuples, directly usable in the 'patch-series' form."
92 (unfold (cut > <> count)
94 (let* ((patch (download-to-store store (patch-url number)))
95 (sig (download-to-store store
96 (string-append (patch-url number)
98 (unless (eq? 'valid-signature (gnupg-verify* sig patch))
99 (error "failed to verify signature" patch))
102 (bytevector->nix-base32-string
103 (call-with-input-file patch port-sha256)))))
108 (let* ((cppflags (string-join '("-DDEFAULT_PATH_VALUE='\"/no-such-path\"'"
109 "-DSTANDARD_UTILS_PATH='\"/no-such-path\"'"
110 "-DNON_INTERACTIVE_LOGIN_SHELLS"
111 "-DSSH_SOURCE_BASHRC")
114 ``("--with-installed-readline"
115 ,,(string-append "CPPFLAGS=" cppflags)
117 "LDFLAGS=-Wl,-rpath -Wl,"
118 (assoc-ref %build-inputs "readline")
121 (assoc-ref %build-inputs "ncurses")
129 "mirror://gnu/bash/bash-" version ".tar.gz"))
132 "0kgvfwqdcd90waczf4gx39xnrxzijhjrzyzv7s8v4w31qqm0za5l"))
133 (patch-flags '("-p0"))
134 (patches (cons (search-patch "bash-linux-pgrp-pipe.patch")
135 %patch-series-5.0))))
136 (version (string-append version "." (number->string (length %patch-series-5.0))))
137 (build-system gnu-build-system)
140 "doc" ;1.7 MiB of HTML and extra files
141 "include")) ;headers used by extensions
142 (inputs `(("readline" ,readline)
143 ("ncurses" ,ncurses))) ;TODO: add texinfo
145 `(;; When cross-compiling, `configure' incorrectly guesses that job
146 ;; control is missing.
147 #:configure-flags ,(if (%current-target-system)
148 `(cons* "bash_cv_job_control_missing=no"
152 ;; Bash is reportedly not parallel-safe. See, for instance,
153 ;; <http://patches.openembedded.org/patch/32745/> and
154 ;; <http://git.buildroot.net/buildroot/commit/?h=79e2d802a>.
158 ;; XXX: The tests have a lot of hard-coded paths, so disable them
162 #:modules ((srfi srfi-26)
164 (guix build gnu-build-system))
167 (modify-phases %standard-phases
168 (add-after 'install 'install-sh-symlink
169 (lambda* (#:key outputs #:allow-other-keys)
170 ;; Add a `sh' -> `bash' link.
171 (let ((out (assoc-ref outputs "out")))
172 (with-directory-excursion (string-append out "/bin")
173 (symlink "bash" "sh")
176 (add-after 'install 'move-development-files
177 (lambda* (#:key outputs #:allow-other-keys)
178 ;; Move 'Makefile.inc' and 'bash.pc' to "include" to avoid
179 ;; circular references among the outputs.
180 (let ((out (assoc-ref outputs "out"))
181 (include (assoc-ref outputs "include"))
182 (lib (cut string-append <> "/lib/bash")))
183 (mkdir-p (lib include))
184 (rename-file (string-append (lib out)
186 (string-append (lib include)
188 (rename-file (string-append out "/lib/pkgconfig")
189 (string-append include
192 ;; Don't capture the absolute file name of 'install' to avoid
193 ;; retaining a dependency on Coreutils.
194 (substitute* (string-append (lib include)
197 "INSTALL = install -c\n"))
201 (list (search-path-specification ;new in 4.4
202 (variable "BASH_LOADABLES_PATH")
203 (files '("lib/bash")))))
205 (synopsis "The GNU Bourne-Again SHell")
207 "Bash is the shell, or command-line interpreter, of the GNU system. It
208 is compatible with the Bourne Shell, but it also integrates useful features
209 from the Korn Shell and the C Shell and new improvements of its own. It
210 allows command-line editing, unlimited command history, shell functions and
211 aliases, and job control while still allowing most sh scripts to be run
212 without modification.")
214 (home-page "https://www.gnu.org/software/bash/"))))
216 (define-public bash-minimal
217 ;; A stripped-down Bash for non-interactive use.
218 (package (inherit bash)
219 (name "bash-minimal")
220 (inputs '()) ; no readline, no curses
222 ;; No "include" output because there's no support for loadable modules.
223 (outputs (delete "include" (package-outputs bash)))
226 (substitute-keyword-arguments (package-arguments bash)
228 '((guix build gnu-build-system)
232 ((#:configure-flags flags '())
233 `(list "--without-bash-malloc"
236 "--disable-help-builtin"
238 "--disable-net-redirections"
241 ;; Pretend 'dlopen' is missing so we don't build loadable
242 ;; modules and related code.
243 "ac_cv_func_dlopen=no"
245 ,@(if (%current-target-system)
246 '("bash_cv_job_control_missing=no"
247 "bash_cv_getcwd_malloc=yes")
250 `(modify-phases ,phases
251 ;; No loadable modules.
252 (delete 'move-development-files)))))))
254 (define-public static-bash
255 ;; Statically-linked Bash that contains nothing but the 'bash' binary and
256 ;; 'sh' symlink, without any reference.
257 (let ((bash (static-package bash-minimal)))
262 (substitute-keyword-arguments
263 `(#:allowed-references ("out") ,@(package-arguments bash))
265 `(modify-phases ,phases
266 (add-after 'strip 'remove-everything-but-the-binary
267 (lambda* (#:key outputs #:allow-other-keys)
268 (let* ((out (assoc-ref outputs "out"))
269 (bin (string-append out "/bin")))
270 (remove-store-references (string-append bin "/bash"))
271 (delete-file (string-append bin "/bashbug"))
272 (delete-file-recursively (string-append out "/share"))
275 (define-public bash-completion
277 (name "bash-completion")
282 "https://github.com/scop/" name "/releases/download/"
283 version "/" name "-" version ".tar.xz"))
286 "0kgmflrr1ga9wfk770vmakna3nj46ylb5ky9ipd0v2k9ymq5a7y0"))
288 (search-patches "bash-completion-directories.patch"))))
289 (build-system gnu-build-system)
290 (native-inputs `(("util-linux" ,util-linux)))
292 `(#:phases (modify-phases %standard-phases
294 'install 'remove-redundant-completions
297 outputs #:allow-other-keys)
298 ;; Util-linux comes with a bunch of completion files for
299 ;; its own commands which are more sophisticated and
300 ;; up-to-date than those of bash-completion. Remove those
301 ;; from bash-completion.
302 (let* ((out (assoc-ref outputs "out"))
303 (util-linux (assoc-ref (or native-inputs inputs)
305 (completions (string-append out
306 "/share/bash-completion"
311 "/etc/bash_completion.d"))))
312 (with-directory-excursion completions
313 (for-each (lambda (file)
314 (when (file-exists? file)
316 (map basename already)))
318 (synopsis "Bash completions for common commands")
320 "This package provides extensions that allow Bash to provide adapted
321 completion for many common commands.")
322 (home-page "https://github.com/scop/bash-completion")
325 (define-public bash-tap
333 (url "https://github.com/illusori/bash-tap")
335 (file-name (git-file-name name version))
337 (base32 "13zz9h6bhhnk3hiwhlpafrnf2isws249h3fz785dcgymk02arz9c"))))
338 ;; There is no compilation process to use this package, however, the bash
339 ;; scripts installed by this package start with "#!/bin/bash". To fix
340 ;; these lines, we use the patch-shebangs of the GNU build system. The
341 ;; project does not use a Makefile.
342 (build-system gnu-build-system)
344 `(#:tests? #f ; There is no test suite.
346 (modify-phases %standard-phases
347 ;; Because there are no configure scripts or Makefile, we can
348 ;; remove these phases.
351 ;; The installation involves manually copying the files to a location.
352 ;; To make them easily accessible by setting PATH, we add the scripts
353 ;; to the "bin" folder.
355 (lambda* (#:key outputs #:allow-other-keys)
356 (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
357 (install-file "bash-tap" bin)
358 (install-file "bash-tap-bootstrap" bin)
359 (install-file "bash-tap-mock" bin)))))))
360 (home-page "https://www.illusori.co.uk/projects/bash-tap/")
361 (synopsis "Bash port of a Test::More/Test::Builder-style TAP-compliant
363 (description "Bash TAP is a TAP-compliant Test::More-style testing library
364 for Bash shell scripts and functions. Along with the Test::More-style testing
365 helpers it provides helper functions for mocking commands and in-process output
376 (url "https://github.com/bats-core/bats-core")
377 (commit (string-append "v" version))))
378 (file-name (git-file-name name version))
381 "0f59zh4d4pa1a7ybs5zl6h0csbqqv11lbnq0jl1dgwm1s6p49bsq"))))
384 ("coreutils" ,coreutils)
385 ("guile" ,guile-3.0) ;for wrap-script
388 `(#:modules ((guix build utils))
391 (use-modules (guix build utils))
392 (copy-recursively (assoc-ref %build-inputs "source") ".")
394 (string-append (assoc-ref %build-inputs "bash") "/bin"
395 ":" (assoc-ref %build-inputs "coreutils") "/bin"
396 ":" (assoc-ref %build-inputs "grep") "/bin"
397 ":" (assoc-ref %build-inputs "guile") "/bin"
398 ":" (getenv "PATH")))
399 (for-each (lambda (file) (patch-shebang file)) (find-files "."))
400 (substitute* "bin/bats"
401 (("export BATS_ROOT" line)
402 (string-append "BATS_ROOT=\"${BATS_ROOT:-" %output "/libexec/bats-core}\"\n"
405 (invoke "./install.sh" %output)
406 (wrap-script (string-append %output "/bin/bats")
407 (list "PATH" 'prefix (string-split (getenv "PATH")
409 (build-system trivial-build-system)
410 (home-page "https://github.com/bats-core/bats-core/")
411 (synopsis "Bash Automated Testing System")
413 "Bats is a @acronym{TAP, Test Anything Protocol}-compliant testing
414 framework for Bash. It provides a simple way to verify that the UNIX programs
415 you write behave as expected. Bats is most useful when testing software written
416 in Bash, but you can use it to test any UNIX program.")