Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / gnu / packages / bash.scm
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>
7 ;;;
8 ;;; This file is part of GNU Guix.
9 ;;;
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.
14 ;;;
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.
19 ;;;
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/>.
22
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))
44
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))
48
49 (define (bash-patch seqno sha256)
50 "Return the origin of Bash patch SEQNO, with expected hash SHA256"
51 (origin
52 (method url-fetch)
53 (uri (patch-url seqno))
54 (sha256 sha256)))
55
56 (define-syntax-rule (patch-series (seqno hash) ...)
57 (list (bash-patch seqno (base32 hash))
58 ...))
59
60 (define %patch-series-4.4
61 ;; This is the current patches series for 4.4, generated using
62 ;; 'download-patches' below.
63 (patch-series
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")))
83
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)
88 (lambda (number)
89 (let* ((patch (download-to-store store (patch-url number)))
90 (sig (download-to-store store
91 (string-append (patch-url number)
92 ".sig"))))
93 (unless (gnupg-verify* sig patch)
94 (error "failed to verify signature" patch))
95
96 (list number
97 (bytevector->nix-base32-string
98 (call-with-input-file patch port-sha256)))))
99 1+
100 1))
101
102 (define-public bash
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")
107 " "))
108 (configure-flags
109 ``("--with-installed-readline"
110 ,,(string-append "CPPFLAGS=" cppflags)
111 ,(string-append
112 "LDFLAGS=-Wl,-rpath -Wl,"
113 (assoc-ref %build-inputs "readline")
114 "/lib"
115 " -Wl,-rpath -Wl,"
116 (assoc-ref %build-inputs "ncurses")
117 "/lib")))
118 (version "4.4"))
119 (package
120 (name "bash")
121 (source (origin
122 (method url-fetch)
123 (uri (string-append
124 "mirror://gnu/bash/bash-" version ".tar.gz"))
125 (sha256
126 (base32
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)
133
134 (outputs '("out"
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
139 (arguments
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"
144 ,configure-flags)
145 configure-flags)
146
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>.
150 #:parallel-build? #f
151 #:parallel-tests? #f
152
153 ;; XXX: The tests have a lot of hard-coded paths, so disable them
154 ;; for now.
155 #:tests? #f
156
157 #:modules ((srfi srfi-26)
158 (guix build utils)
159 (guix build gnu-build-system))
160
161 #:phases
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")
169 #t))))
170
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)
180 "/Makefile.inc")
181 (string-append (lib include)
182 "/Makefile.inc"))
183 (rename-file (string-append out "/lib/pkgconfig")
184 (string-append include
185 "/lib/pkgconfig"))
186
187 ;; Don't capture the absolute file name of 'install' to avoid
188 ;; retaining a dependency on Coreutils.
189 (substitute* (string-append (lib include)
190 "/Makefile.inc")
191 (("^INSTALL =.*")
192 "INSTALL = install -c\n"))
193 #t))))))
194
195 (native-search-paths
196 (list (search-path-specification ;new in 4.4
197 (variable "BASH_LOADABLES_PATH")
198 (files '("lib/bash")))))
199
200 (synopsis "The GNU Bourne-Again SHell")
201 (description
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.")
208 (license gpl3+)
209 (home-page "https://www.gnu.org/software/bash/"))))
210
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
216
217 ;; No "include" output because there's no support for loadable modules.
218 (outputs (delete "include" (package-outputs bash)))
219
220 (arguments
221 (substitute-keyword-arguments (package-arguments bash)
222 ((#:modules _ '())
223 '((guix build gnu-build-system)
224 (guix build utils)
225 (srfi srfi-1)
226 (srfi srfi-26)))
227 ((#:configure-flags flags '())
228 `(list "--without-bash-malloc"
229 "--disable-readline"
230 "--disable-history"
231 "--disable-help-builtin"
232 "--disable-progcomp"
233 "--disable-net-redirections"
234 "--disable-nls"
235
236 ;; Pretend 'dlopen' is missing so we don't build loadable
237 ;; modules and related code.
238 "ac_cv_func_dlopen=no"
239
240 ,@(if (%current-target-system)
241 '("bash_cv_job_control_missing=no"
242 "bash_cv_getcwd_malloc=yes")
243 '())))
244 ((#:phases phases)
245 `(modify-phases ,phases
246 ;; No loadable modules.
247 (delete 'move-development-files)))))))
248
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)))
253 (package
254 (inherit bash)
255 (name "bash-static")
256 (arguments
257 (substitute-keyword-arguments
258 `(#:allowed-references ("out") ,@(package-arguments bash))
259 ((#:phases phases)
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"))
268 #t))))))))))
269
270 (define-public bash-completion
271 (package
272 (name "bash-completion")
273 (version "2.8")
274 (source (origin
275 (method url-fetch)
276 (uri (string-append
277 "https://github.com/scop/" name "/releases/download/"
278 version "/" name "-" version ".tar.xz"))
279 (sha256
280 (base32
281 "0kgmflrr1ga9wfk770vmakna3nj46ylb5ky9ipd0v2k9ymq5a7y0"))
282 (patches
283 (search-patches "bash-completion-directories.patch"))))
284 (build-system gnu-build-system)
285 (native-inputs `(("util-linux" ,util-linux)))
286 (arguments
287 `(#:phases (modify-phases %standard-phases
288 (add-after
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"
299 "/completions"))
300 (already (find-files
301 (string-append
302 util-linux
303 "/etc/bash_completion.d"))))
304 (with-directory-excursion completions
305 (for-each (lambda (file)
306 (when (file-exists? file)
307 (delete-file file)))
308 (map basename already)))
309 #t))))))
310 (synopsis "Bash completions for common commands")
311 (description
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")
315 (license gpl2+)))
316
317 (define-public bash-tap
318 (package
319 (name "bash-tap")
320 (version "1.0.2")
321 (source (origin
322 (method url-fetch)
323 (uri (string-append "https://github.com/illusori/bash-tap/"
324 "archive/" version ".tar.gz"))
325 (file-name (string-append name "-" version ".tar.gz"))
326 (sha256
327 (base32
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)
334 (arguments
335 `(#:tests? #f ; There is no test suite.
336 #:phases
337 (modify-phases %standard-phases
338 ;; Because there are no configure scripts or Makefile, we can
339 ;; remove these phases.
340 (delete 'configure)
341 (delete 'build)
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.
345 (replace 'install
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
353 test library")
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
357 capturing.")
358 (license expat)))