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>
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 (guix 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-4.4-patches/bash44-~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-4.4
61 ;; This is the current patches series for 4.4, generated using
62 ;; 'download-patches' below.
64 (1 "03vzy7qwjdd5qvl3ydg99naazas2qmyd0yhnrflgjbbm64axja1y")
65 (2 "0lrwq6vyqism3yqv9s7kzaf3dsl4q5w9r5svcqz279qp7qca083h")
66 (3 "1chqww2rj6g42b8s60q5zlzy0jzp684jkpsbrbfy1vzxja8mmpsi")
67 (4 "1cy8abf96hkrjhw921ndr0shlcnc52bg45rn6xri4v5clhq0l25d")
68 (5 "0a8515kyk4zsgmvlqvlganjfr7pq0j6kzpr4d6xx02kpbdr4n7i2")
69 (6 "1f24wgqngmj2mrj9yibwvc2zvlmn5xi53mnw777g3l40c4m2x3ka")
70 (7 "1bzdsnqaf05gdbqpsixhan8vygjxpcxlz1dd8d9f5jdznw3wq76y") ;CVE-2017-5932
71 (8 "1firw915mjm03hbbw9a70ch3cpgrgnvqjpllgdnn6csr8q04f546")
72 (9 "0g1l56kvw61rpw7dqa9fcl9llkl693h73g631hrhxlm030ddssqb")
73 (10 "01lfhrkdsdkdz8ypzapr614ras23x7ckjnr60aa5bzkaqprccrc4")
74 (11 "038p7mhnq9m65g505hi3827jkf9f35nd1cy00w8mwafpyxp44mnx")
75 (12 "0gh6lbb1rwpk44pvbamm6vzdfi50xnwkqd9v7s8cjwk3pz973hps")
76 (13 "1djkx0w9v62q78gz3jsvamj1jq53i6hbfrfhhsw86ihwpjnfy98v")
77 (14 "0z5ikcq9zyxw79d0z36r5p0mspnb5piavbv03jmlan1wnknmrxx7")
78 (15 "09n307fi1j257abhm295k6ksmnzw47ka2zhnr0i5lbdnpvn04xnk")
79 (16 "1cgi1y6mifm8hsgv4avj5ih76535js3qba1sqwbfvp7si76927sh")
80 (17 "0w6jpj2giakji1ir83rpkx1y7n7xqppah3j748m6dm38hywr0gvp")
81 (18 "1k58h4wxbsg7r4rwhrvzx5hfbapba2nxjysbhh6qp6ki5ys99i2v")
82 (19 "07n1i5610lbs672x1s8g82qn3qfj06s0ip3z80sri0g8vxp0s5r7")))
84 (define (download-patches store count)
85 "Download COUNT Bash patches into store. Return a list of
86 number/base32-hash tuples, directly usable in the 'patch-series' form."
87 (unfold (cut > <> count)
89 (let* ((patch (download-to-store store (patch-url number)))
90 (sig (download-to-store store
91 (string-append (patch-url number)
93 (unless (gnupg-verify* sig patch)
94 (error "failed to verify signature" patch))
97 (bytevector->nix-base32-string
98 (call-with-input-file patch port-sha256)))))
103 (let* ((cppflags (string-join '("-DDEFAULT_PATH_VALUE='\"/no-such-path\"'"
104 "-DSTANDARD_UTILS_PATH='\"/no-such-path\"'"
105 "-DNON_INTERACTIVE_LOGIN_SHELLS"
106 "-DSSH_SOURCE_BASHRC")
109 ``("--with-installed-readline"
110 ,,(string-append "CPPFLAGS=" cppflags)
112 "LDFLAGS=-Wl,-rpath -Wl,"
113 (assoc-ref %build-inputs "readline")
116 (assoc-ref %build-inputs "ncurses")
124 "mirror://gnu/bash/bash-" version ".tar.gz"))
127 "1jyz6snd63xjn6skk7za6psgidsd53k05cr3lksqybi0q6936syq"))
128 (patch-flags '("-p0"))
129 (patches %patch-series-4.4)))
130 (version (string-append version "."
131 (number->string (length %patch-series-4.4))))
132 (build-system gnu-build-system)
135 "doc" ;1.7 MiB of HTML and extra files
136 "include")) ;headers used by extensions
137 (inputs `(("readline" ,readline)
138 ("ncurses" ,ncurses))) ;TODO: add texinfo
140 `(;; When cross-compiling, `configure' incorrectly guesses that job
141 ;; control is missing.
142 #:configure-flags ,(if (%current-target-system)
143 `(cons* "bash_cv_job_control_missing=no"
147 ;; Bash is reportedly not parallel-safe. See, for instance,
148 ;; <http://patches.openembedded.org/patch/32745/> and
149 ;; <http://git.buildroot.net/buildroot/commit/?h=79e2d802a>.
153 ;; XXX: The tests have a lot of hard-coded paths, so disable them
157 #:modules ((srfi srfi-26)
159 (guix build gnu-build-system))
162 (modify-phases %standard-phases
163 (add-after 'install 'install-sh-symlink
164 (lambda* (#:key outputs #:allow-other-keys)
165 ;; Add a `sh' -> `bash' link.
166 (let ((out (assoc-ref outputs "out")))
167 (with-directory-excursion (string-append out "/bin")
168 (symlink "bash" "sh")
171 (add-after 'install 'move-development-files
172 (lambda* (#:key outputs #:allow-other-keys)
173 ;; Move 'Makefile.inc' and 'bash.pc' to "include" to avoid
174 ;; circular references among the outputs.
175 (let ((out (assoc-ref outputs "out"))
176 (include (assoc-ref outputs "include"))
177 (lib (cut string-append <> "/lib/bash")))
178 (mkdir-p (lib include))
179 (rename-file (string-append (lib out)
181 (string-append (lib include)
183 (rename-file (string-append out "/lib/pkgconfig")
184 (string-append include
187 ;; Don't capture the absolute file name of 'install' to avoid
188 ;; retaining a dependency on Coreutils.
189 (substitute* (string-append (lib include)
192 "INSTALL = install -c\n"))
196 (list (search-path-specification ;new in 4.4
197 (variable "BASH_LOADABLES_PATH")
198 (files '("lib/bash")))))
200 (synopsis "The GNU Bourne-Again SHell")
202 "Bash is the shell, or command-line interpreter, of the GNU system. It
203 is compatible with the Bourne Shell, but it also integrates useful features
204 from the Korn Shell and the C Shell and new improvements of its own. It
205 allows command-line editing, unlimited command history, shell functions and
206 aliases, and job control while still allowing most sh scripts to be run
207 without modification.")
209 (home-page "https://www.gnu.org/software/bash/"))))
211 (define-public bash-minimal
212 ;; A stripped-down Bash for non-interactive use.
213 (package (inherit bash)
214 (name "bash-minimal")
215 (inputs '()) ; no readline, no curses
217 ;; No "include" output because there's no support for loadable modules.
218 (outputs (delete "include" (package-outputs bash)))
221 (substitute-keyword-arguments (package-arguments bash)
223 '((guix build gnu-build-system)
227 ((#:configure-flags flags '())
228 `(list "--without-bash-malloc"
231 "--disable-help-builtin"
233 "--disable-net-redirections"
236 ;; Pretend 'dlopen' is missing so we don't build loadable
237 ;; modules and related code.
238 "ac_cv_func_dlopen=no"
240 ,@(if (%current-target-system)
241 '("bash_cv_job_control_missing=no"
242 "bash_cv_getcwd_malloc=yes")
245 `(modify-phases ,phases
246 ;; No loadable modules.
247 (delete 'move-development-files)))))))
249 (define-public static-bash
250 ;; Statically-linked Bash that contains nothing but the 'bash' binary and
251 ;; 'sh' symlink, without any reference.
252 (let ((bash (static-package bash-minimal)))
257 (substitute-keyword-arguments
258 `(#:allowed-references ("out") ,@(package-arguments bash))
260 `(modify-phases ,phases
261 (add-after 'strip 'remove-everything-but-the-binary
262 (lambda* (#:key outputs #:allow-other-keys)
263 (let* ((out (assoc-ref outputs "out"))
264 (bin (string-append out "/bin")))
265 (remove-store-references (string-append bin "/bash"))
266 (delete-file (string-append bin "/bashbug"))
267 (delete-file-recursively (string-append out "/share"))
270 (define-public bash-completion
272 (name "bash-completion")
277 "https://github.com/scop/" name "/releases/download/"
278 version "/" name "-" version ".tar.xz"))
281 "0kgmflrr1ga9wfk770vmakna3nj46ylb5ky9ipd0v2k9ymq5a7y0"))
283 (search-patches "bash-completion-directories.patch"))))
284 (build-system gnu-build-system)
285 (native-inputs `(("util-linux" ,util-linux)))
287 `(#:phases (modify-phases %standard-phases
289 'install 'remove-redundant-completions
290 (lambda* (#:key inputs outputs #:allow-other-keys)
291 ;; Util-linux comes with a bunch of completion files for
292 ;; its own commands which are more sophisticated and
293 ;; up-to-date than those of bash-completion. Remove those
294 ;; from bash-completion.
295 (let* ((out (assoc-ref outputs "out"))
296 (util-linux (assoc-ref inputs "util-linux"))
297 (completions (string-append out
298 "/share/bash-completion"
303 "/etc/bash_completion.d"))))
304 (with-directory-excursion completions
305 (for-each (lambda (file)
306 (when (file-exists? file)
308 (map basename already)))
310 (synopsis "Bash completions for common commands")
312 "This package provides extensions that allow Bash to provide adapted
313 completion for many common commands.")
314 (home-page "https://github.com/scop/bash-completion")
317 (define-public bash-tap
323 (uri (string-append "https://github.com/illusori/bash-tap/"
324 "archive/" version ".tar.gz"))
325 (file-name (string-append name "-" version ".tar.gz"))
328 "0qs1qi38bl3ns4mpagcawv618dsk2q1lgrbddgvs0wl3ia12cyz5"))))
329 ;; There is no compilation process to use this package, however, the bash
330 ;; scripts installed by this package start with "#!/bin/bash". To fix
331 ;; these lines, we use the patch-shebangs of the GNU build system. The
332 ;; project does not use a Makefile.
333 (build-system gnu-build-system)
335 `(#:tests? #f ; There is no test suite.
337 (modify-phases %standard-phases
338 ;; Because there are no configure scripts or Makefile, we can
339 ;; remove these phases.
342 ;; The installation involves manually copying the files to a location.
343 ;; To make them easily accessible by setting PATH, we add the scripts
344 ;; to the "bin" folder.
346 (lambda* (#:key outputs #:allow-other-keys)
347 (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
348 (install-file "bash-tap" bin)
349 (install-file "bash-tap-bootstrap" bin)
350 (install-file "bash-tap-mock" bin)))))))
351 (home-page "http://www.illusori.co.uk/projects/bash-tap/")
352 (synopsis "Bash port of a Test::More/Test::Builder-style TAP-compliant
354 (description "Bash TAP is a TAP-compliant Test::More-style testing library
355 for Bash shell scripts and functions. Along with the Test::More-style testing
356 helpers it provides helper functions for mocking commands and in-process output