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>
9 ;;; Copyright © 2021 Marius Bakke <marius@gnu.org>
11 ;;; This file is part of GNU Guix.
13 ;;; GNU Guix is free software; you can redistribute it and/or modify it
14 ;;; under the terms of the GNU General Public License as published by
15 ;;; the Free Software Foundation; either version 3 of the License, or (at
16 ;;; your option) any later version.
18 ;;; GNU Guix is distributed in the hope that it will be useful, but
19 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;;; GNU General Public License for more details.
23 ;;; You should have received a copy of the GNU General Public License
24 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
26 (define-module (gnu packages bash)
27 #:use-module ((guix licenses) #:prefix license:)
28 #:use-module (gnu packages)
29 #:use-module (gnu packages base)
30 #:use-module (gnu packages bootstrap)
31 #:use-module (gnu packages compression)
32 #:use-module (gnu packages elf)
33 #:use-module (gnu packages ncurses)
34 #:use-module (gnu packages readline)
35 #:use-module (gnu packages bison)
36 #:use-module (gnu packages linux)
37 #:use-module (gnu packages libffi)
38 #:use-module (gnu packages pkg-config)
39 #:use-module (gnu packages guile)
40 #:use-module (gnu packages version-control)
41 #:use-module (gnu packages less)
42 #:use-module (guix packages)
43 #:use-module (guix download)
44 #:use-module (guix git-download)
45 #:use-module (guix utils)
46 #:use-module (guix gexp)
47 #:use-module (guix monads)
48 #:use-module (guix store)
49 #:use-module (guix build-system gnu)
50 #:use-module (guix build-system trivial)
51 #:autoload (guix gnupg) (gnupg-verify*)
52 #:autoload (guix base32) (bytevector->nix-base32-string)
54 ;; See <https://bugs.gnu.org/41457> for why not #:autoload here.
55 #:use-module ((gcrypt hash) #:select (port-sha256))
57 #:use-module (srfi srfi-1)
58 #:use-module (srfi srfi-26)
59 #:use-module (ice-9 format))
61 (define (patch-url seqno)
62 "Return the URL of Bash patch number SEQNO."
63 (format #f "mirror://gnu/bash/bash-5.1-patches/bash51-~3,'0d" seqno))
65 (define (bash-patch seqno sha256-bv)
66 "Return the origin of Bash patch SEQNO, with expected hash SHA256-BV."
69 (uri (patch-url seqno))
72 (define-syntax-rule (patch-series (seqno hash) ...)
73 (list (bash-patch seqno (base32 hash))
76 (define %patch-series-5.1
77 ;; This is the current patches series for 5.0, generated using
78 ;; 'download-patches' below.
80 (1 "1ymm8ppss6gyh9ifznjwiabrb4k91npd09c10y7mk66xp8yppc7b")
81 (2 "1gjx9zqcm407am3n2sh44b8dxm48kgm15rzfiijqxr01m0hn3shm")
82 (3 "1cdnpbfc64yhvkjj4d12s9ywp11g195vzfl1cab24sq55wkcrwi2")
83 (4 "11iwhy6v562bv0kk7lwj7f5jj65ma9bblivy0v02h3ggcibbdbls")
84 (5 "19bdyigdr81824nxvqr6a7k0cax60wq7376j6b91afbnwvlvbjyc")
85 (6 "051x8wlwrqk0yr0zg378vh824iklfl5g9pkmcdf62qp8gn9pvqbm")
86 (7 "0fir80pp1gmlpadmqcgkrv4y119pc7xllchjzg05fd7px73viz5c")
87 (8 "1lfjgshk8i9vch92p5wgc9r90j3phw79aa7gbai89w183b2z6b7j")))
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 "1alv68wplnfdm6mh39hm57060xgssb9vqca4yr1cyva0c342n0fc"))
133 (patch-flags '("-p0"))
134 (patches (cons (search-patch "bash-linux-pgrp-pipe.patch")
135 %patch-series-5.1))))
136 (version (string-append version "." (number->string (length %patch-series-5.1))))
137 (build-system gnu-build-system)
140 "doc" ;1.7 MiB of HTML and extra files
141 "include")) ;headers used by extensions
142 (inputs (list readline ncurses)) ;TODO: add texinfo
144 `(;; When cross-compiling, `configure' incorrectly guesses that job
145 ;; control is missing.
146 #:configure-flags ,(if (%current-target-system)
147 `(cons* "bash_cv_job_control_missing=no"
151 ;; Bash is reportedly not parallel-safe. See, for instance,
152 ;; <http://patches.openembedded.org/patch/32745/> and
153 ;; <http://git.buildroot.net/buildroot/commit/?h=79e2d802a>.
157 ;; XXX: The tests have a lot of hard-coded paths, so disable them
161 #:modules ((srfi srfi-26)
163 (guix build gnu-build-system))
166 (modify-phases %standard-phases
167 (add-after 'install 'install-sh-symlink
168 (lambda* (#:key outputs #:allow-other-keys)
169 ;; Add a `sh' -> `bash' link.
170 (let ((out (assoc-ref outputs "out")))
171 (with-directory-excursion (string-append out "/bin")
172 (symlink "bash" "sh")
175 (add-after 'install 'move-development-files
176 (lambda* (#:key outputs #:allow-other-keys)
177 ;; Move 'Makefile.inc' and 'bash.pc' to "include" to avoid
178 ;; circular references among the outputs.
179 (let ((out (assoc-ref outputs "out"))
180 (include (assoc-ref outputs "include"))
181 (lib (cut string-append <> "/lib/bash")))
182 (mkdir-p (lib include))
183 (rename-file (string-append (lib out)
185 (string-append (lib include)
187 (rename-file (string-append out "/lib/pkgconfig")
188 (string-append include
191 ;; Don't capture the absolute file name of 'install' to avoid
192 ;; retaining a dependency on Coreutils.
193 (substitute* (string-append (lib include)
196 "INSTALL = install -c\n"))
200 (list (search-path-specification ;new in 4.4
201 (variable "BASH_LOADABLES_PATH")
202 (files '("lib/bash")))))
204 (synopsis "The GNU Bourne-Again SHell")
206 "Bash is the shell, or command-line interpreter, of the GNU system. It
207 is compatible with the Bourne Shell, but it also integrates useful features
208 from the Korn Shell and the C Shell and new improvements of its own. It
209 allows command-line editing, unlimited command history, shell functions and
210 aliases, and job control while still allowing most sh scripts to be run
211 without modification.")
212 (license license:gpl3+)
213 (home-page "https://www.gnu.org/software/bash/"))))
215 (define-public bash-minimal
216 ;; A stripped-down Bash for non-interactive use.
217 (package (inherit bash)
218 (name "bash-minimal")
219 (inputs '()) ; no readline, no curses
221 ;; No "include" output because there's no support for loadable modules.
222 (outputs (delete "include" (package-outputs bash)))
225 (substitute-keyword-arguments (package-arguments bash)
227 '((guix build gnu-build-system)
231 ((#:configure-flags flags '())
232 `(list "--without-bash-malloc"
235 "--disable-help-builtin"
237 "--disable-net-redirections"
240 ;; Pretend 'dlopen' is missing so we don't build loadable
241 ;; modules and related code.
242 "ac_cv_func_dlopen=no"
244 ,@(if (%current-target-system)
245 '("bash_cv_job_control_missing=no"
246 "bash_cv_getcwd_malloc=yes")
249 `(modify-phases ,phases
250 ;; No loadable modules.
251 (delete 'move-development-files)))))))
253 (define-public static-bash
254 ;; Statically-linked Bash that contains nothing but the 'bash' binary and
255 ;; 'sh' symlink, without any reference.
256 (let ((bash (static-package bash-minimal)))
261 (substitute-keyword-arguments
262 `(#:allowed-references ("out") ,@(package-arguments bash))
264 `(modify-phases ,phases
265 (add-after 'strip 'remove-everything-but-the-binary
266 (lambda* (#:key outputs #:allow-other-keys)
267 (let* ((out (assoc-ref outputs "out"))
268 (bin (string-append out "/bin")))
269 (remove-store-references (string-append bin "/bash"))
270 (delete-file (string-append bin "/bashbug"))
271 (delete-file-recursively (string-append out "/share"))
274 (define-public bash-with-syslog
277 (name "bash-with-syslog")
279 (substitute-keyword-arguments (package-arguments bash)
280 ((#:phases phases '%standard-phases)
281 `(modify-phases ,phases
282 (add-after 'unpack 'enable-syslogging
284 (substitute* "config-top.h"
285 (("/\\* #define SYSLOG_HISTORY \\*/")
286 "#define SYSLOG_HISTORY"))))))))
288 "Bash is the shell, or command-line interpreter, of the GNU system. This
289 variant logs the history to syslog.")))
291 (define-public bash-completion
293 (name "bash-completion")
298 "https://github.com/scop/" name "/releases/download/"
299 version "/" name "-" version ".tar.xz"))
302 "0kgmflrr1ga9wfk770vmakna3nj46ylb5ky9ipd0v2k9ymq5a7y0"))
304 (search-patches "bash-completion-directories.patch"))))
305 (build-system gnu-build-system)
306 (native-inputs (list util-linux))
308 `(#:phases (modify-phases %standard-phases
310 'install 'remove-redundant-completions
313 outputs #:allow-other-keys)
314 ;; Util-linux comes with a bunch of completion files for
315 ;; its own commands which are more sophisticated and
316 ;; up-to-date than those of bash-completion. Remove those
317 ;; from bash-completion.
318 (let* ((out (assoc-ref outputs "out"))
319 (util-linux (assoc-ref (or native-inputs inputs)
321 (completions (string-append out
322 "/share/bash-completion"
327 "/etc/bash_completion.d"))))
328 (with-directory-excursion completions
329 (for-each (lambda (file)
330 (when (file-exists? file)
332 (map basename already)))
334 (synopsis "Bash completions for common commands")
336 "This package provides extensions that allow Bash to provide adapted
337 completion for many common commands.")
338 (home-page "https://github.com/scop/bash-completion")
339 (license license:gpl2+)))
341 (define-public bash-tap
349 (url "https://github.com/illusori/bash-tap")
351 (file-name (git-file-name name version))
353 (base32 "13zz9h6bhhnk3hiwhlpafrnf2isws249h3fz785dcgymk02arz9c"))))
354 ;; There is no compilation process to use this package, however, the bash
355 ;; scripts installed by this package start with "#!/bin/bash". To fix
356 ;; these lines, we use the patch-shebangs of the GNU build system. The
357 ;; project does not use a Makefile.
358 (build-system gnu-build-system)
360 `(#:tests? #f ; There is no test suite.
362 (modify-phases %standard-phases
363 ;; Because there are no configure scripts or Makefile, we can
364 ;; remove these phases.
367 ;; The installation involves manually copying the files to a location.
368 ;; To make them easily accessible by setting PATH, we add the scripts
369 ;; to the "bin" folder.
371 (lambda* (#:key outputs #:allow-other-keys)
372 (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
373 (install-file "bash-tap" bin)
374 (install-file "bash-tap-bootstrap" bin)
375 (install-file "bash-tap-mock" bin)))))))
376 (home-page "https://www.illusori.co.uk/projects/bash-tap/")
377 (synopsis "Bash port of a Test::More/Test::Builder-style TAP-compliant
379 (description "Bash TAP is a TAP-compliant Test::More-style testing library
380 for Bash shell scripts and functions. Along with the Test::More-style testing
381 helpers it provides helper functions for mocking commands and in-process output
383 (license license:expat)))
392 (url "https://github.com/bats-core/bats-core")
393 (commit (string-append "v" version))))
394 (file-name (git-file-name name version))
397 "0f59zh4d4pa1a7ybs5zl6h0csbqqv11lbnq0jl1dgwm1s6p49bsq"))))
399 (list bash coreutils guile-3.0 ;for wrap-script
402 `(#:modules ((guix build utils))
405 (use-modules (guix build utils))
406 (copy-recursively (assoc-ref %build-inputs "source") ".")
408 (string-append (assoc-ref %build-inputs "bash") "/bin"
409 ":" (assoc-ref %build-inputs "coreutils") "/bin"
410 ":" (assoc-ref %build-inputs "grep") "/bin"
411 ":" (assoc-ref %build-inputs "guile") "/bin"
412 ":" (getenv "PATH")))
413 (for-each (lambda (file) (patch-shebang file)) (find-files "."))
414 (substitute* "bin/bats"
415 (("export BATS_ROOT" line)
416 (string-append "BATS_ROOT=\"${BATS_ROOT:-" %output "/libexec/bats-core}\"\n"
419 (invoke "./install.sh" %output)
420 (wrap-script (string-append %output "/bin/bats")
421 #:guile (search-input-file %build-inputs "bin/guile")
422 (list "PATH" 'prefix (string-split (getenv "PATH")
424 (build-system trivial-build-system)
425 (home-page "https://github.com/bats-core/bats-core/")
426 (synopsis "Bash Automated Testing System")
428 "Bats is a @acronym{TAP, Test Anything Protocol}-compliant testing
429 framework for Bash. It provides a simple way to verify that the UNIX programs
430 you write behave as expected. Bats is most useful when testing software written
431 in Bash, but you can use it to test any UNIX program.")
432 (license license:expat)))
434 (define-public bash-ctypes
441 (uri (string-append "https://github.com/taviso/ctypes.sh/releases/download/v"
442 version "/ctypes-sh-" version ".tar.gz"))
444 (base32 "0s1sifqzqmr0dnciv06yqrpzgj11d7n0gy5zaxh6b3x8bx7k75l8"))))
445 (build-system gnu-build-system)
451 ;; Require a bash with C plugin support to build.
455 (home-page "https://github.com/taviso/ctypes.sh")
456 (synopsis "Foreign function interface for Bash")
457 (description "Bash-ctypes is a Bash plugin that provides a foreign
458 function interface (FFI) directly in your shell. In other words, it allows
459 you to call routines in shared libraries from within Bash.")
460 (license license:expat)))
465 (version "0.4.0-devel2")
469 (url "https://github.com/akinomyoga/ble.sh")
470 (commit (string-append "v" version))))
471 (file-name (git-file-name name version))
474 "02fdjyh4x6wr5hg3i86nsxhz8ysgjrvvxdmk6pqr0lm8ngw9p3sh"))))
476 (list #:make-flags #~(list (string-append "PREFIX="
478 #:phases #~(modify-phases %standard-phases
479 (add-after 'unpack 'pretend-contrib-.git-exists
481 (mkdir-p "contrib/.git")))
482 (add-after 'unpack 'make-readlink-work
484 (substitute* "ble.pp"
485 (("PATH=/bin:/usr/bin readlink")
486 (search-input-file %build-inputs
488 (delete 'configure) ;no configure
489 (add-before 'check 'use-LANG-for-tests
493 (unsetenv "LC_ALL"))))))
494 (build-system gnu-build-system)
495 (native-inputs (list less))
496 (home-page "https://github.com/akinomyoga/ble.sh")
497 (synopsis "Bash Line Editor")
499 "Bash Line Editor (ble.sh) is a command line editor written in pure Bash
500 which replaces the default GNU Readline. It adds syntax highlighting, auto
501 suggestions, vim modes, and more to Bash interactive sessions.")
502 (license license:bsd-3)))