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 Efraim Flashner <efraim@flashner.co.il>
7 ;;; This file is part of GNU Guix.
9 ;;; GNU Guix is free software; you can redistribute it and/or modify it
10 ;;; under the terms of the GNU General Public License as published by
11 ;;; the Free Software Foundation; either version 3 of the License, or (at
12 ;;; your option) any later version.
14 ;;; GNU Guix is distributed in the hope that it will be useful, but
15 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
19 ;;; You should have received a copy of the GNU General Public License
20 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22 (define-module (gnu packages bash)
23 #:use-module (guix licenses)
24 #:use-module (gnu packages)
25 #:use-module (gnu packages bootstrap)
26 #:use-module (gnu packages ncurses)
27 #:use-module (gnu packages readline)
28 #:use-module (gnu packages bison)
29 #:use-module (gnu packages linux)
30 #:use-module (guix packages)
31 #:use-module (guix download)
32 #:use-module (guix utils)
33 #:use-module (guix gexp)
34 #:use-module (guix monads)
35 #:use-module (guix store)
36 #:use-module (guix build-system gnu)
37 #:autoload (guix gnupg) (gnupg-verify*)
38 #:autoload (guix hash) (port-sha256)
39 #:autoload (guix base32) (bytevector->nix-base32-string)
40 #:use-module (srfi srfi-1)
41 #:use-module (srfi srfi-26)
42 #:use-module (ice-9 format))
44 (define (patch-url seqno)
45 "Return the URL of Bash patch number SEQNO."
46 (format #f "mirror://gnu/bash/bash-4.4-patches/bash44-~3,'0d" seqno))
48 (define (bash-patch seqno sha256)
49 "Return the origin of Bash patch SEQNO, with expected hash SHA256"
52 (uri (patch-url seqno))
55 (define-syntax-rule (patch-series (seqno hash) ...)
56 (list (bash-patch seqno (base32 hash))
59 (define %patch-series-4.4
60 ;; This is the current patches series for 4.4, generated using
61 ;; 'download-patches' below.
63 (1 "03vzy7qwjdd5qvl3ydg99naazas2qmyd0yhnrflgjbbm64axja1y")
64 (2 "0lrwq6vyqism3yqv9s7kzaf3dsl4q5w9r5svcqz279qp7qca083h")
65 (3 "1chqww2rj6g42b8s60q5zlzy0jzp684jkpsbrbfy1vzxja8mmpsi")
66 (4 "1cy8abf96hkrjhw921ndr0shlcnc52bg45rn6xri4v5clhq0l25d")
67 (5 "0a8515kyk4zsgmvlqvlganjfr7pq0j6kzpr4d6xx02kpbdr4n7i2")
68 (6 "1f24wgqngmj2mrj9yibwvc2zvlmn5xi53mnw777g3l40c4m2x3ka")
69 (7 "1bzdsnqaf05gdbqpsixhan8vygjxpcxlz1dd8d9f5jdznw3wq76y") ;CVE-2017-5932
70 (8 "1firw915mjm03hbbw9a70ch3cpgrgnvqjpllgdnn6csr8q04f546")
71 (9 "0g1l56kvw61rpw7dqa9fcl9llkl693h73g631hrhxlm030ddssqb")
72 (10 "01lfhrkdsdkdz8ypzapr614ras23x7ckjnr60aa5bzkaqprccrc4")
73 (11 "038p7mhnq9m65g505hi3827jkf9f35nd1cy00w8mwafpyxp44mnx")
74 (12 "0gh6lbb1rwpk44pvbamm6vzdfi50xnwkqd9v7s8cjwk3pz973hps")
75 (13 "1djkx0w9v62q78gz3jsvamj1jq53i6hbfrfhhsw86ihwpjnfy98v")
76 (14 "0z5ikcq9zyxw79d0z36r5p0mspnb5piavbv03jmlan1wnknmrxx7")
77 (15 "09n307fi1j257abhm295k6ksmnzw47ka2zhnr0i5lbdnpvn04xnk")
78 (16 "1cgi1y6mifm8hsgv4avj5ih76535js3qba1sqwbfvp7si76927sh")
79 (17 "0w6jpj2giakji1ir83rpkx1y7n7xqppah3j748m6dm38hywr0gvp")
80 (18 "1k58h4wxbsg7r4rwhrvzx5hfbapba2nxjysbhh6qp6ki5ys99i2v")
81 (19 "07n1i5610lbs672x1s8g82qn3qfj06s0ip3z80sri0g8vxp0s5r7")))
83 (define (download-patches store count)
84 "Download COUNT Bash patches into store. Return a list of
85 number/base32-hash tuples, directly usable in the 'patch-series' form."
86 (unfold (cut > <> count)
88 (let* ((patch (download-to-store store (patch-url number)))
89 (sig (download-to-store store
90 (string-append (patch-url number)
92 (unless (gnupg-verify* sig patch)
93 (error "failed to verify signature" patch))
96 (bytevector->nix-base32-string
97 (call-with-input-file patch port-sha256)))))
102 (let* ((cppflags (string-join '("-DDEFAULT_PATH_VALUE='\"/no-such-path\"'"
103 "-DSTANDARD_UTILS_PATH='\"/no-such-path\"'"
104 "-DNON_INTERACTIVE_LOGIN_SHELLS"
105 "-DSSH_SOURCE_BASHRC")
108 ``("--with-installed-readline"
109 ,,(string-append "CPPFLAGS=" cppflags)
111 "LDFLAGS=-Wl,-rpath -Wl,"
112 (assoc-ref %build-inputs "readline")
115 (assoc-ref %build-inputs "ncurses")
123 "mirror://gnu/bash/bash-" version ".tar.gz"))
126 "1jyz6snd63xjn6skk7za6psgidsd53k05cr3lksqybi0q6936syq"))
127 (patch-flags '("-p0"))
128 (patches %patch-series-4.4)))
129 (version (string-append version "."
130 (number->string (length %patch-series-4.4))))
131 (build-system gnu-build-system)
134 "doc" ;1.7 MiB of HTML and extra files
135 "include")) ;headers used by extensions
136 (inputs `(("readline" ,readline)
137 ("ncurses" ,ncurses))) ;TODO: add texinfo
139 `(;; When cross-compiling, `configure' incorrectly guesses that job
140 ;; control is missing.
141 #:configure-flags ,(if (%current-target-system)
142 `(cons* "bash_cv_job_control_missing=no"
146 ;; Bash is reportedly not parallel-safe. See, for instance,
147 ;; <http://patches.openembedded.org/patch/32745/> and
148 ;; <http://git.buildroot.net/buildroot/commit/?h=79e2d802a>.
152 ;; XXX: The tests have a lot of hard-coded paths, so disable them
156 #:modules ((srfi srfi-26)
158 (guix build gnu-build-system))
161 (modify-phases %standard-phases
162 (add-after 'install 'install-sh-symlink
163 (lambda* (#:key outputs #:allow-other-keys)
164 ;; Add a `sh' -> `bash' link.
165 (let ((out (assoc-ref outputs "out")))
166 (with-directory-excursion (string-append out "/bin")
167 (symlink "bash" "sh")
170 (add-after 'install 'move-development-files
171 (lambda* (#:key outputs #:allow-other-keys)
172 ;; Move 'Makefile.inc' and 'bash.pc' to "include" to avoid
173 ;; circular references among the outputs.
174 (let ((out (assoc-ref outputs "out"))
175 (include (assoc-ref outputs "include"))
176 (lib (cut string-append <> "/lib/bash")))
177 (mkdir-p (lib include))
178 (rename-file (string-append (lib out)
180 (string-append (lib include)
182 (rename-file (string-append out "/lib/pkgconfig")
183 (string-append include
186 ;; Don't capture the absolute file name of 'install' to avoid
187 ;; retaining a dependency on Coreutils.
188 (substitute* (string-append (lib include)
191 "INSTALL = install -c\n"))
195 (list (search-path-specification ;new in 4.4
196 (variable "BASH_LOADABLES_PATH")
197 (files '("lib/bash")))))
199 (synopsis "The GNU Bourne-Again SHell")
201 "Bash is the shell, or command-line interpreter, of the GNU system. It
202 is compatible with the Bourne Shell, but it also integrates useful features
203 from the Korn Shell and the C Shell and new improvements of its own. It
204 allows command-line editing, unlimited command history, shell functions and
205 aliases, and job control while still allowing most sh scripts to be run
206 without modification.")
208 (home-page "https://www.gnu.org/software/bash/"))))
210 (define-public bash-minimal
211 ;; A stripped-down Bash for non-interactive use.
212 (package (inherit bash)
213 (name "bash-minimal")
214 (inputs '()) ; no readline, no curses
216 ;; No "include" output because there's no support for loadable modules.
217 (outputs (delete "include" (package-outputs bash)))
220 (substitute-keyword-arguments (package-arguments bash)
222 '((guix build gnu-build-system)
226 ((#:configure-flags flags '())
227 `(list "--without-bash-malloc"
230 "--disable-help-builtin"
232 "--disable-net-redirections"
235 ;; Pretend 'dlopen' is missing so we don't build loadable
236 ;; modules and related code.
237 "ac_cv_func_dlopen=no"
239 ,@(if (%current-target-system)
240 '("bash_cv_job_control_missing=no"
241 "bash_cv_getcwd_malloc=yes")
244 `(modify-phases ,phases
245 ;; No loadable modules.
246 (delete 'move-development-files)))))))
248 (define-public static-bash
249 ;; Statically-linked Bash that contains nothing but the 'bash' binary and
250 ;; 'sh' symlink, without any reference.
251 (let ((bash (static-package bash-minimal)))
256 (substitute-keyword-arguments
257 `(#:allowed-references ("out") ,@(package-arguments bash))
259 `(modify-phases ,phases
260 (add-after 'strip 'remove-everything-but-the-binary
261 (lambda* (#:key outputs #:allow-other-keys)
262 (let* ((out (assoc-ref outputs "out"))
263 (bin (string-append out "/bin")))
264 (remove-store-references (string-append bin "/bash"))
265 (delete-file (string-append bin "/bashbug"))
266 (delete-file-recursively (string-append out "/share"))
269 (define-public bash-completion
271 (name "bash-completion")
276 "https://github.com/scop/" name "/releases/download/"
277 version "/" name "-" version ".tar.xz"))
280 "07j484vb3k90f4989xh1g1x99g01akrp69p3dml4lza27wnqkfj1"))
282 (search-patches "bash-completion-directories.patch"))))
283 (build-system gnu-build-system)
284 (native-inputs `(("util-linux" ,util-linux)))
286 `(#:phases (modify-phases %standard-phases
288 'install 'remove-redundant-completions
289 (lambda* (#:key inputs outputs #:allow-other-keys)
290 ;; Util-linux comes with a bunch of completion files for
291 ;; its own commands which are more sophisticated and
292 ;; up-to-date than those of bash-completion. Remove those
293 ;; from bash-completion.
294 (let* ((out (assoc-ref outputs "out"))
295 (util-linux (assoc-ref inputs "util-linux"))
296 (completions (string-append out
297 "/share/bash-completion"
302 "/etc/bash_completion.d"))))
303 (with-directory-excursion completions
304 (for-each (lambda (file)
305 (when (file-exists? file)
307 (map basename already)))
309 (synopsis "Bash completions for common commands")
311 "This package provides extensions that allow Bash to provide adapted
312 completion for many common commands.")
313 (home-page "https://github.com/scop/bash-completion")
316 (define-public bash-tap
322 (uri (string-append "https://github.com/illusori/bash-tap/"
323 "archive/" version ".tar.gz"))
324 (file-name (string-append name "-" version ".tar.gz"))
327 "0qs1qi38bl3ns4mpagcawv618dsk2q1lgrbddgvs0wl3ia12cyz5"))))
328 ;; There is no compilation process to use this package, however, the bash
329 ;; scripts installed by this package start with "#!/bin/bash". To fix
330 ;; these lines, we use the patch-shebangs of the GNU build system. The
331 ;; project does not use a Makefile.
332 (build-system gnu-build-system)
334 `(#:tests? #f ; There is no test suite.
336 (modify-phases %standard-phases
337 ;; Because there are no configure scripts or Makefile, we can
338 ;; remove these phases.
341 ;; The installation involves manually copying the files to a location.
342 ;; To make them easily accessible by setting PATH, we add the scripts
343 ;; to the "bin" folder.
345 (lambda* (#:key outputs #:allow-other-keys)
346 (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
347 (install-file "bash-tap" bin)
348 (install-file "bash-tap-bootstrap" bin)
349 (install-file "bash-tap-mock" bin)))))))
350 (home-page "http://www.illusori.co.uk/projects/bash-tap/")
351 (synopsis "Bash port of a Test::More/Test::Builder-style TAP-compliant
353 (description "Bash TAP is a TAP-compliant Test::More-style testing library
354 for Bash shell scripts and functions. Along with the Test::More-style testing
355 helpers it provides helper functions for mocking commands and in-process output