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>
8 ;;; Copyright © 2020 Zhu Zihao <all_but_last@163.com>
10 ;;; This file is part of GNU Guix.
12 ;;; GNU Guix is free software; you can redistribute it and/or modify it
13 ;;; under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 3 of the License, or (at
15 ;;; your option) any later version.
17 ;;; GNU Guix is distributed in the hope that it will be useful, but
18 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;;; GNU General Public License for more details.
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
25 (define-module (gnu packages bash)
26 #:use-module ((guix licenses) #:prefix license:)
27 #:use-module (gnu packages)
28 #:use-module (gnu packages base)
29 #:use-module (gnu packages bootstrap)
30 #:use-module (gnu packages compression)
31 #:use-module (gnu packages elf)
32 #:use-module (gnu packages ncurses)
33 #:use-module (gnu packages readline)
34 #:use-module (gnu packages bison)
35 #:use-module (gnu packages linux)
36 #:use-module (gnu packages libffi)
37 #:use-module (gnu packages pkg-config)
38 #:use-module (gnu packages guile)
39 #:use-module (guix packages)
40 #:use-module (guix download)
41 #:use-module (guix git-download)
42 #:use-module (guix utils)
43 #:use-module (guix gexp)
44 #:use-module (guix monads)
45 #:use-module (guix store)
46 #:use-module (guix build-system gnu)
47 #:use-module (guix build-system trivial)
48 #:autoload (guix gnupg) (gnupg-verify*)
49 #:autoload (guix base32) (bytevector->nix-base32-string)
51 ;; See <https://bugs.gnu.org/41457> for why not #:autoload here.
52 #:use-module ((gcrypt hash) #:select (port-sha256))
54 #:use-module (srfi srfi-1)
55 #:use-module (srfi srfi-26)
56 #:use-module (ice-9 format))
58 (define (patch-url seqno)
59 "Return the URL of Bash patch number SEQNO."
60 (format #f "mirror://gnu/bash/bash-5.0-patches/bash50-~3,'0d" seqno))
62 (define (bash-patch seqno sha256-bv)
63 "Return the origin of Bash patch SEQNO, with expected hash SHA256-BV."
66 (uri (patch-url seqno))
69 (define-syntax-rule (patch-series (seqno hash) ...)
70 (list (bash-patch seqno (base32 hash))
73 (define %patch-series-5.0
74 ;; This is the current patches series for 5.0, generated using
75 ;; 'download-patches' below.
77 (1 "12bjfdy6bg8nhyw27bdgxn7h4paylx8d927skfmi9pxd1wgrxzpj")
78 (2 "01w7yrzmz10mw06ys0546vhl7isv2v402ziyvfd7k67588spvs47")
79 (3 "0ny81ridp5n0j69hb8ixrc7dmxybby54jbsz5hikly8kgg1wvssf")
80 (4 "021gqqvgydixkrmqss64b6srfdlkvnx88lyfzpxfrn5d6bc7li0l")
81 (5 "0xl2kyzm84nlyklrqzkn73ixabhzfhn9x91lzcmis89cppclvxav")
82 (6 "0844749ixk1z60437nkznzms1f0nzh9an62kj7sny6r0zyk2k1fn")
83 (7 "16xg37gp1b8zlj5969w8mcrparwqlcbj9695vn3qhgb7wdz1xd0p")
84 (8 "1qyp19krjh8zxvb0jgwmyjz40djslwcf4xi7kc1ab0iaca44bipf")
85 (9 "00yrjjqd95s81b21qq3ba1y7h879q8jaajlkjggc6grhcwbs4g7d")
86 (10 "04ca5bjv456v538mkspzvn4xb2zdphh31r4fpvfm9p5my0jw7yyn")
87 (11 "1sklyixvsv8993kxzs0jigacpdchjrq7jv5xpdx7kbqyp4rf6k9c")
88 (12 "0cz21qg2gbr40lfgza7g02bqi2qknwqgxnq459pjj640d0cywhr9")
89 (13 "16h9nwz3yzwj7fnxvlidjymdc4yr30h818433gh9j1x3in6igmzm")
90 (14 "12gm5bvv2pd3m72z2ilj26pa08c61az253dsgfl24vpf2ijywvjx")
91 (15 "0pm0px758w4i23s55wajcv6lqfiym7zgxvq0pxf6vclkv8nxy5x5")
92 (16 "0vdha332km2iwx8g2ld15jy7d24cbplzgr1531dpzylr9ajxglgz")))
94 (define (download-patches store count)
95 "Download COUNT Bash patches into store. Return a list of
96 number/base32-hash tuples, directly usable in the 'patch-series' form."
97 (unfold (cut > <> count)
99 (let* ((patch (download-to-store store (patch-url number)))
100 (sig (download-to-store store
101 (string-append (patch-url number)
103 (unless (eq? 'valid-signature (gnupg-verify* sig patch))
104 (error "failed to verify signature" patch))
107 (bytevector->nix-base32-string
108 (call-with-input-file patch port-sha256)))))
113 (let* ((cppflags (string-join '("-DDEFAULT_PATH_VALUE='\"/no-such-path\"'"
114 "-DSTANDARD_UTILS_PATH='\"/no-such-path\"'"
115 "-DNON_INTERACTIVE_LOGIN_SHELLS"
116 "-DSSH_SOURCE_BASHRC")
119 ``("--with-installed-readline"
120 ,,(string-append "CPPFLAGS=" cppflags)
122 "LDFLAGS=-Wl,-rpath -Wl,"
123 (assoc-ref %build-inputs "readline")
126 (assoc-ref %build-inputs "ncurses")
134 "mirror://gnu/bash/bash-" version ".tar.gz"))
137 "0kgvfwqdcd90waczf4gx39xnrxzijhjrzyzv7s8v4w31qqm0za5l"))
138 (patch-flags '("-p0"))
139 (patches (cons (search-patch "bash-linux-pgrp-pipe.patch")
140 %patch-series-5.0))))
141 (version (string-append version "." (number->string (length %patch-series-5.0))))
142 (build-system gnu-build-system)
145 "doc" ;1.7 MiB of HTML and extra files
146 "include")) ;headers used by extensions
147 (inputs `(("readline" ,readline)
148 ("ncurses" ,ncurses))) ;TODO: add texinfo
150 `(;; When cross-compiling, `configure' incorrectly guesses that job
151 ;; control is missing.
152 #:configure-flags ,(if (%current-target-system)
153 `(cons* "bash_cv_job_control_missing=no"
157 ;; Bash is reportedly not parallel-safe. See, for instance,
158 ;; <http://patches.openembedded.org/patch/32745/> and
159 ;; <http://git.buildroot.net/buildroot/commit/?h=79e2d802a>.
163 ;; XXX: The tests have a lot of hard-coded paths, so disable them
167 #:modules ((srfi srfi-26)
169 (guix build gnu-build-system))
172 (modify-phases %standard-phases
173 (add-after 'install 'install-sh-symlink
174 (lambda* (#:key outputs #:allow-other-keys)
175 ;; Add a `sh' -> `bash' link.
176 (let ((out (assoc-ref outputs "out")))
177 (with-directory-excursion (string-append out "/bin")
178 (symlink "bash" "sh")
181 (add-after 'install 'move-development-files
182 (lambda* (#:key outputs #:allow-other-keys)
183 ;; Move 'Makefile.inc' and 'bash.pc' to "include" to avoid
184 ;; circular references among the outputs.
185 (let ((out (assoc-ref outputs "out"))
186 (include (assoc-ref outputs "include"))
187 (lib (cut string-append <> "/lib/bash")))
188 (mkdir-p (lib include))
189 (rename-file (string-append (lib out)
191 (string-append (lib include)
193 (rename-file (string-append out "/lib/pkgconfig")
194 (string-append include
197 ;; Don't capture the absolute file name of 'install' to avoid
198 ;; retaining a dependency on Coreutils.
199 (substitute* (string-append (lib include)
202 "INSTALL = install -c\n"))
206 (list (search-path-specification ;new in 4.4
207 (variable "BASH_LOADABLES_PATH")
208 (files '("lib/bash")))))
210 (synopsis "The GNU Bourne-Again SHell")
212 "Bash is the shell, or command-line interpreter, of the GNU system. It
213 is compatible with the Bourne Shell, but it also integrates useful features
214 from the Korn Shell and the C Shell and new improvements of its own. It
215 allows command-line editing, unlimited command history, shell functions and
216 aliases, and job control while still allowing most sh scripts to be run
217 without modification.")
218 (license license:gpl3+)
219 (home-page "https://www.gnu.org/software/bash/"))))
221 (define-public bash-minimal
222 ;; A stripped-down Bash for non-interactive use.
223 (package (inherit bash)
224 (name "bash-minimal")
225 (inputs '()) ; no readline, no curses
227 ;; No "include" output because there's no support for loadable modules.
228 (outputs (delete "include" (package-outputs bash)))
231 (substitute-keyword-arguments (package-arguments bash)
233 '((guix build gnu-build-system)
237 ((#:configure-flags flags '())
238 `(list "--without-bash-malloc"
241 "--disable-help-builtin"
243 "--disable-net-redirections"
246 ;; Pretend 'dlopen' is missing so we don't build loadable
247 ;; modules and related code.
248 "ac_cv_func_dlopen=no"
250 ,@(if (%current-target-system)
251 '("bash_cv_job_control_missing=no"
252 "bash_cv_getcwd_malloc=yes")
255 `(modify-phases ,phases
256 ;; No loadable modules.
257 (delete 'move-development-files)))))))
259 (define-public static-bash
260 ;; Statically-linked Bash that contains nothing but the 'bash' binary and
261 ;; 'sh' symlink, without any reference.
262 (let ((bash (static-package bash-minimal)))
267 (substitute-keyword-arguments
268 `(#:allowed-references ("out") ,@(package-arguments bash))
270 `(modify-phases ,phases
271 (add-after 'strip 'remove-everything-but-the-binary
272 (lambda* (#:key outputs #:allow-other-keys)
273 (let* ((out (assoc-ref outputs "out"))
274 (bin (string-append out "/bin")))
275 (remove-store-references (string-append bin "/bash"))
276 (delete-file (string-append bin "/bashbug"))
277 (delete-file-recursively (string-append out "/share"))
280 (define-public bash-completion
282 (name "bash-completion")
287 "https://github.com/scop/" name "/releases/download/"
288 version "/" name "-" version ".tar.xz"))
291 "0kgmflrr1ga9wfk770vmakna3nj46ylb5ky9ipd0v2k9ymq5a7y0"))
293 (search-patches "bash-completion-directories.patch"))))
294 (build-system gnu-build-system)
295 (native-inputs `(("util-linux" ,util-linux)))
297 `(#:phases (modify-phases %standard-phases
299 'install 'remove-redundant-completions
302 outputs #:allow-other-keys)
303 ;; Util-linux comes with a bunch of completion files for
304 ;; its own commands which are more sophisticated and
305 ;; up-to-date than those of bash-completion. Remove those
306 ;; from bash-completion.
307 (let* ((out (assoc-ref outputs "out"))
308 (util-linux (assoc-ref (or native-inputs inputs)
310 (completions (string-append out
311 "/share/bash-completion"
316 "/etc/bash_completion.d"))))
317 (with-directory-excursion completions
318 (for-each (lambda (file)
319 (when (file-exists? file)
321 (map basename already)))
323 (synopsis "Bash completions for common commands")
325 "This package provides extensions that allow Bash to provide adapted
326 completion for many common commands.")
327 (home-page "https://github.com/scop/bash-completion")
328 (license license:gpl2+)))
330 (define-public bash-tap
338 (url "https://github.com/illusori/bash-tap")
340 (file-name (git-file-name name version))
342 (base32 "13zz9h6bhhnk3hiwhlpafrnf2isws249h3fz785dcgymk02arz9c"))))
343 ;; There is no compilation process to use this package, however, the bash
344 ;; scripts installed by this package start with "#!/bin/bash". To fix
345 ;; these lines, we use the patch-shebangs of the GNU build system. The
346 ;; project does not use a Makefile.
347 (build-system gnu-build-system)
349 `(#:tests? #f ; There is no test suite.
351 (modify-phases %standard-phases
352 ;; Because there are no configure scripts or Makefile, we can
353 ;; remove these phases.
356 ;; The installation involves manually copying the files to a location.
357 ;; To make them easily accessible by setting PATH, we add the scripts
358 ;; to the "bin" folder.
360 (lambda* (#:key outputs #:allow-other-keys)
361 (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
362 (install-file "bash-tap" bin)
363 (install-file "bash-tap-bootstrap" bin)
364 (install-file "bash-tap-mock" bin)))))))
365 (home-page "https://www.illusori.co.uk/projects/bash-tap/")
366 (synopsis "Bash port of a Test::More/Test::Builder-style TAP-compliant
368 (description "Bash TAP is a TAP-compliant Test::More-style testing library
369 for Bash shell scripts and functions. Along with the Test::More-style testing
370 helpers it provides helper functions for mocking commands and in-process output
372 (license license:expat)))
381 (url "https://github.com/bats-core/bats-core")
382 (commit (string-append "v" version))))
383 (file-name (git-file-name name version))
386 "0f59zh4d4pa1a7ybs5zl6h0csbqqv11lbnq0jl1dgwm1s6p49bsq"))))
389 ("coreutils" ,coreutils)
390 ("guile" ,guile-3.0) ;for wrap-script
393 `(#:modules ((guix build utils))
396 (use-modules (guix build utils))
397 (copy-recursively (assoc-ref %build-inputs "source") ".")
399 (string-append (assoc-ref %build-inputs "bash") "/bin"
400 ":" (assoc-ref %build-inputs "coreutils") "/bin"
401 ":" (assoc-ref %build-inputs "grep") "/bin"
402 ":" (assoc-ref %build-inputs "guile") "/bin"
403 ":" (getenv "PATH")))
404 (for-each (lambda (file) (patch-shebang file)) (find-files "."))
405 (substitute* "bin/bats"
406 (("export BATS_ROOT" line)
407 (string-append "BATS_ROOT=\"${BATS_ROOT:-" %output "/libexec/bats-core}\"\n"
410 (invoke "./install.sh" %output)
411 (wrap-script (string-append %output "/bin/bats")
412 (list "PATH" 'prefix (string-split (getenv "PATH")
414 (build-system trivial-build-system)
415 (home-page "https://github.com/bats-core/bats-core/")
416 (synopsis "Bash Automated Testing System")
418 "Bats is a @acronym{TAP, Test Anything Protocol}-compliant testing
419 framework for Bash. It provides a simple way to verify that the UNIX programs
420 you write behave as expected. Bats is most useful when testing software written
421 in Bash, but you can use it to test any UNIX program.")
422 (license license:expat)))
424 (define-public bash-ctypes
431 (uri (string-append "https://github.com/taviso/ctypes.sh/releases/download/v"
432 version "/ctypes-sh-" version ".tar.gz"))
434 (base32 "0s1sifqzqmr0dnciv06yqrpzgj11d7n0gy5zaxh6b3x8bx7k75l8"))))
435 (build-system gnu-build-system)
437 `(("elfutils" ,elfutils)
441 ;; Require a bash with C plugin support to build.
444 `(("pkg-config" ,pkg-config)))
445 (home-page "https://github.com/taviso/ctypes.sh")
446 (synopsis "Foreign function interface for Bash")
447 (description "Bash-ctypes is a Bash plugin that provides a foreign
448 function interface (FFI) directly in your shell. In other words, it allows
449 you to call routines in shared libraries from within Bash.")
450 (license license:expat)))