1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017 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 Tobias Geerinckx-Rice <me@tobias.gr>
8 ;;; This file is part of GNU Guix.
10 ;;; GNU Guix is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or (at
13 ;;; your option) any later version.
15 ;;; GNU Guix is distributed in the hope that it will be useful, but
16 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
23 (define-module (gnu packages bash)
24 #:use-module (guix licenses)
25 #:use-module (gnu packages)
26 #:use-module (gnu packages bootstrap)
27 #:use-module (gnu packages ncurses)
28 #:use-module (gnu packages readline)
29 #:use-module (gnu packages bison)
30 #:use-module (gnu packages linux)
31 #:use-module (guix packages)
32 #:use-module (guix download)
33 #:use-module (guix utils)
34 #:use-module (guix gexp)
35 #:use-module (guix monads)
36 #:use-module (guix store)
37 #:use-module (guix build-system gnu)
38 #:autoload (guix gnupg) (gnupg-verify*)
39 #:autoload (gcrypt hash) (port-sha256)
40 #:autoload (guix base32) (bytevector->nix-base32-string)
41 #:use-module (srfi srfi-1)
42 #:use-module (srfi srfi-26)
43 #:use-module (ice-9 format))
45 (define (patch-url seqno)
46 "Return the URL of Bash patch number SEQNO."
47 (format #f "mirror://gnu/bash/bash-5.0-patches/bash50-~3,'0d" seqno))
49 (define (bash-patch seqno sha256)
50 "Return the origin of Bash patch SEQNO, with expected hash SHA256"
53 (uri (patch-url seqno))
56 (define-syntax-rule (patch-series (seqno hash) ...)
57 (list (bash-patch seqno (base32 hash))
60 (define %patch-series-5.0
61 ;; This is the current patches series for 5.0, generated using
62 ;; 'download-patches' below.
66 (define (download-patches store count)
67 "Download COUNT Bash patches into store. Return a list of
68 number/base32-hash tuples, directly usable in the 'patch-series' form."
69 (unfold (cut > <> count)
71 (let* ((patch (download-to-store store (patch-url number)))
72 (sig (download-to-store store
73 (string-append (patch-url number)
75 (unless (gnupg-verify* sig patch)
76 (error "failed to verify signature" patch))
79 (bytevector->nix-base32-string
80 (call-with-input-file patch port-sha256)))))
85 (let* ((cppflags (string-join '("-DDEFAULT_PATH_VALUE='\"/no-such-path\"'"
86 "-DSTANDARD_UTILS_PATH='\"/no-such-path\"'"
87 "-DNON_INTERACTIVE_LOGIN_SHELLS"
88 "-DSSH_SOURCE_BASHRC")
91 ``("--with-installed-readline"
92 ,,(string-append "CPPFLAGS=" cppflags)
94 "LDFLAGS=-Wl,-rpath -Wl,"
95 (assoc-ref %build-inputs "readline")
98 (assoc-ref %build-inputs "ncurses")
106 "mirror://gnu/bash/bash-" version ".tar.gz"))
109 "0kgvfwqdcd90waczf4gx39xnrxzijhjrzyzv7s8v4w31qqm0za5l"))))
111 (build-system gnu-build-system)
114 "doc" ;1.7 MiB of HTML and extra files
115 "include")) ;headers used by extensions
116 (inputs `(("readline" ,readline)
117 ("ncurses" ,ncurses))) ;TODO: add texinfo
119 `(;; When cross-compiling, `configure' incorrectly guesses that job
120 ;; control is missing.
121 #:configure-flags ,(if (%current-target-system)
122 `(cons* "bash_cv_job_control_missing=no"
126 ;; Bash is reportedly not parallel-safe. See, for instance,
127 ;; <http://patches.openembedded.org/patch/32745/> and
128 ;; <http://git.buildroot.net/buildroot/commit/?h=79e2d802a>.
132 ;; XXX: The tests have a lot of hard-coded paths, so disable them
136 #:modules ((srfi srfi-26)
138 (guix build gnu-build-system))
141 (modify-phases %standard-phases
142 (add-after 'install 'install-sh-symlink
143 (lambda* (#:key outputs #:allow-other-keys)
144 ;; Add a `sh' -> `bash' link.
145 (let ((out (assoc-ref outputs "out")))
146 (with-directory-excursion (string-append out "/bin")
147 (symlink "bash" "sh")
150 (add-after 'install 'move-development-files
151 (lambda* (#:key outputs #:allow-other-keys)
152 ;; Move 'Makefile.inc' and 'bash.pc' to "include" to avoid
153 ;; circular references among the outputs.
154 (let ((out (assoc-ref outputs "out"))
155 (include (assoc-ref outputs "include"))
156 (lib (cut string-append <> "/lib/bash")))
157 (mkdir-p (lib include))
158 (rename-file (string-append (lib out)
160 (string-append (lib include)
162 (rename-file (string-append out "/lib/pkgconfig")
163 (string-append include
166 ;; Don't capture the absolute file name of 'install' to avoid
167 ;; retaining a dependency on Coreutils.
168 (substitute* (string-append (lib include)
171 "INSTALL = install -c\n"))
175 (list (search-path-specification ;new in 4.4
176 (variable "BASH_LOADABLES_PATH")
177 (files '("lib/bash")))))
179 (synopsis "The GNU Bourne-Again SHell")
181 "Bash is the shell, or command-line interpreter, of the GNU system. It
182 is compatible with the Bourne Shell, but it also integrates useful features
183 from the Korn Shell and the C Shell and new improvements of its own. It
184 allows command-line editing, unlimited command history, shell functions and
185 aliases, and job control while still allowing most sh scripts to be run
186 without modification.")
188 (home-page "https://www.gnu.org/software/bash/"))))
190 (define-public bash-minimal
191 ;; A stripped-down Bash for non-interactive use.
192 (package (inherit bash)
193 (name "bash-minimal")
194 (inputs '()) ; no readline, no curses
196 ;; No "include" output because there's no support for loadable modules.
197 (outputs (delete "include" (package-outputs bash)))
200 (substitute-keyword-arguments (package-arguments bash)
202 '((guix build gnu-build-system)
206 ((#:configure-flags flags '())
207 `(list "--without-bash-malloc"
210 "--disable-help-builtin"
212 "--disable-net-redirections"
215 ;; Pretend 'dlopen' is missing so we don't build loadable
216 ;; modules and related code.
217 "ac_cv_func_dlopen=no"
219 ,@(if (%current-target-system)
220 '("bash_cv_job_control_missing=no"
221 "bash_cv_getcwd_malloc=yes")
224 `(modify-phases ,phases
225 ;; No loadable modules.
226 (delete 'move-development-files)))))))
228 (define-public static-bash
229 ;; Statically-linked Bash that contains nothing but the 'bash' binary and
230 ;; 'sh' symlink, without any reference.
231 (let ((bash (static-package bash-minimal)))
236 (substitute-keyword-arguments
237 `(#:allowed-references ("out") ,@(package-arguments bash))
239 `(modify-phases ,phases
240 (add-after 'strip 'remove-everything-but-the-binary
241 (lambda* (#:key outputs #:allow-other-keys)
242 (let* ((out (assoc-ref outputs "out"))
243 (bin (string-append out "/bin")))
244 (remove-store-references (string-append bin "/bash"))
245 (delete-file (string-append bin "/bashbug"))
246 (delete-file-recursively (string-append out "/share"))
249 (define-public bash-completion
251 (name "bash-completion")
256 "https://github.com/scop/" name "/releases/download/"
257 version "/" name "-" version ".tar.xz"))
260 "0kgmflrr1ga9wfk770vmakna3nj46ylb5ky9ipd0v2k9ymq5a7y0"))
262 (search-patches "bash-completion-directories.patch"))))
263 (build-system gnu-build-system)
264 (native-inputs `(("util-linux" ,util-linux)))
266 `(#:phases (modify-phases %standard-phases
268 'install 'remove-redundant-completions
269 (lambda* (#:key inputs outputs #:allow-other-keys)
270 ;; Util-linux comes with a bunch of completion files for
271 ;; its own commands which are more sophisticated and
272 ;; up-to-date than those of bash-completion. Remove those
273 ;; from bash-completion.
274 (let* ((out (assoc-ref outputs "out"))
275 (util-linux (assoc-ref inputs "util-linux"))
276 (completions (string-append out
277 "/share/bash-completion"
282 "/etc/bash_completion.d"))))
283 (with-directory-excursion completions
284 (for-each (lambda (file)
285 (when (file-exists? file)
287 (map basename already)))
289 (synopsis "Bash completions for common commands")
291 "This package provides extensions that allow Bash to provide adapted
292 completion for many common commands.")
293 (home-page "https://github.com/scop/bash-completion")
296 (define-public bash-tap
302 (uri (string-append "https://github.com/illusori/bash-tap/"
303 "archive/" version ".tar.gz"))
304 (file-name (string-append name "-" version ".tar.gz"))
307 "0qs1qi38bl3ns4mpagcawv618dsk2q1lgrbddgvs0wl3ia12cyz5"))))
308 ;; There is no compilation process to use this package, however, the bash
309 ;; scripts installed by this package start with "#!/bin/bash". To fix
310 ;; these lines, we use the patch-shebangs of the GNU build system. The
311 ;; project does not use a Makefile.
312 (build-system gnu-build-system)
314 `(#:tests? #f ; There is no test suite.
316 (modify-phases %standard-phases
317 ;; Because there are no configure scripts or Makefile, we can
318 ;; remove these phases.
321 ;; The installation involves manually copying the files to a location.
322 ;; To make them easily accessible by setting PATH, we add the scripts
323 ;; to the "bin" folder.
325 (lambda* (#:key outputs #:allow-other-keys)
326 (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
327 (install-file "bash-tap" bin)
328 (install-file "bash-tap-bootstrap" bin)
329 (install-file "bash-tap-mock" bin)))))))
330 (home-page "http://www.illusori.co.uk/projects/bash-tap/")
331 (synopsis "Bash port of a Test::More/Test::Builder-style TAP-compliant
333 (description "Bash TAP is a TAP-compliant Test::More-style testing library
334 for Bash shell scripts and functions. Along with the Test::More-style testing
335 helpers it provides helper functions for mocking commands and in-process output