gnu: Adjust formatting as recommended by 'guix lint'.
[jackhill/guix/guix.git] / gnu / packages / bash.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
3 ;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
11 ;;;
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
16 ;;;
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20 (define-module (gnu packages bash)
21 #:use-module (guix licenses)
22 #:use-module (gnu packages)
23 #:use-module (gnu packages ncurses)
24 #:use-module (gnu packages readline)
25 #:use-module (gnu packages bison)
26 #:use-module (gnu packages linux)
27 #:use-module (guix packages)
28 #:use-module (guix download)
29 #:use-module (guix utils)
30 #:use-module (guix build-system gnu)
31 #:autoload (guix gnupg) (gnupg-verify*)
32 #:autoload (guix hash) (port-sha256)
33 #:autoload (guix base32) (bytevector->nix-base32-string)
34 #:use-module (srfi srfi-1)
35 #:use-module (srfi srfi-26)
36 #:use-module (ice-9 format))
37
38 (define (patch-url seqno)
39 "Return the URL of Bash patch number SEQNO."
40 (format #f "mirror://gnu/bash/bash-4.3-patches/bash43-~3,'0d" seqno))
41
42 (define (bash-patch seqno sha256)
43 "Return the origin of Bash patch SEQNO, with expected hash SHA256"
44 (origin
45 (method url-fetch)
46 (uri (patch-url seqno))
47 (sha256 sha256)))
48
49 (define-syntax-rule (patch-series (seqno hash) ...)
50 (list (bash-patch seqno (base32 hash))
51 ...))
52
53 (define %patch-series-4.3
54 ;; This is the current patches series for 4.3, generated using
55 ;; 'download-patches' below.
56 (patch-series
57 (1 "0hip2n2s5hws8p4nfcz37379zn6cak83ljsm64z52rw6ckrdzczc")
58 (2 "0ashj5d1g3zbyr7zf0r72s5wnk96cz1xj919y3jajadbc9qcvrzf")
59 (3 "0z88q4daq7dmw93iqd9c5i5d1sndklih3nrh0v75746da2n6w3h0")
60 (4 "0f0kh9j5k4ym6knshscx31przm50x5cc7ifkwqk0swh6clna982y")
61 (5 "1ym3b8b7lgmdp3dklp8qaqhyq965wd5392namq8mz7rb0d231j0s")
62 (6 "04q20igq49py49ynb0f83f6f52cdkyqwd9bpic6akr0m5pkqwr50")
63 (7 "18zkz23d9myshrwfcwcdjk7qmkqp8az5n91ni9jaixlwqlhy64qi")
64 (8 "0pprcwvh7ngdli0x95pc1cpssg4qg7layi9xrv2jq6c7965ajhcr")
65 (9 "19a0pf0alp30d1bjj0zf3zq2f5n0s6y91w7brm9jyswl51kns8n0")
66 (10 "1dzhr5ammyijisz48cqi5vaw26hfr5vh9smnqxq4qc9p06f7j1ff")
67 (11 "0fvzdzzi142a8rf3v965r6gbpn0k7fv2gif1yq8a4160vcn40qvw")
68 (12 "04lcgfcyz7p3zagb4hkia3hkpd7lii9m8ycy9qqwzyrm1c1pj4ry")
69 (13 "0y9cqi378z6flapkd5k5lfl4lq3ivzg4njj3i3wmw7xb6r9wma5z")
70 (14 "04xcb0k9fxxq4vashgzb98567xzdnm4655nlm4jvfvjv6si6ykas")
71 (15 "13ay6lldy1p00xj41nfjpq8lai3vw2qwca79gx6s80z04j53wa8k")
72 (16 "0wq7bvx3pfw90pnfb86yg5nr9jgjsvm2nq5rrkqxf6zn977hpmlj")
73 (17 "103p7sibihv6cshqj12k546zsbz0dnd5cv5vlx1719avddfc4rqj")
74 (18 "0n1x3812y1brb9xbabaj3fvr4cpvm2225iwckmqk2fcpkq5b9a3s")
75 (19 "08rd1p7zpzgbpmmmnj2im8wj2pcwmbbx51psr9vdc5c049si9ad7")
76 (20 "163c6g05qpag2plx5q795pmw3f3m904jy7z93xj2i08pgzc8cpna")
77 (21 "1a90cl3h10dh8k9f2ddrsjmw5ywaw2d5x78xb4fd2sryi039yhs1")
78 (22 "120s0s4qcqd0q12j1iv0hkpf9fp3w5jnqw646kv66n66jnxlfkgx")
79 (23 "1m00sfi88p2akgiyrg4hw0gvz3s1586pkzjdr3dm73vs773m1hls")
80 (24 "0v0gjqzjsqjfgj5x17fq7g649k94jn8zq92qsxkhc2d6l215hl1v")
81 (25 "0lcj96i659q35f1jcmwwbnw3p7w7vvlxjxqi989vn6d6qksqcl8y") ;CVE-2014-6271
82 (26 "0k919ir0inwn4wai2vdzpbwqq5h54fnrlkmgccxjg91v3ch15k1f") ;CVE-2014-7169
83 (27 "1gnsfvq6bhb3srlbh0cannj2hackdsipcg7z0ds7zlk1hp96mdqy")
84 (28 "17a65c4fn4c5rgsiw9gqqnzhznh3gwnd2xzzv2dppyi48znxpc78") ;CVE-2014-7186
85 (29 "14k27p28r5l2fz3r03kd0x72vvsq8bja8c6hjz5kxikbzsbs7i2c") ;CVE-2014-6277
86 (30 "0nrqb0m7s89qsrbfaffpilc5gcf82bx9yvgzld4hr79p5y54yhw5") ;CVE-2014-6278
87 (31 "07d62bl3z7qa8v6kgk47vzzazw563mlk9zhrsr4xsbqgvmcrylnd")
88 (32 "0jjgapfq4qhmndfrw8c3q3lva8xjdhlbd9cc631v41b0kb95g4w8")
89 (33 "05ma5rlxiadnfh925p4y7s0vvk917kmsdb1mfdx05gizl63pfapv")
90 (34 "12gq9whkq3naa3iy7c7x5pfpvrg7d0kwqld8609zxphhy424ysgi")
91 (35 "1qy1jflmbazjykq766gwabkaiswnx7pwa66whqiny0w02zjqa39p")
92 (36 "0z6jbyy70lfdm6d3x0sbazbqdxb3xnpn9bmz7madpvrnbd284pxc")
93 (37 "04sqr8zkl6s5fccfvb775ppn3ldij5imria9swc39aq0fkfp1w9k")
94 (38 "0rv3g14mpgv8br267bf7rmgqlgwnc4v6g3g8y0sjba571i8amgmd")
95 (39 "1v3l3vkc3g2b6fjycqwlakr8xhiw6bmw6q0zd6bi0m0m4bnxr55b")))
96 (define (download-patches store count)
97 "Download COUNT Bash patches into store. Return a list of
98 number/base32-hash tuples, directly usable in the 'patch-series' form."
99 (unfold (cut > <> count)
100 (lambda (number)
101 (let* ((patch (download-to-store store (patch-url number)))
102 (sig (download-to-store store
103 (string-append (patch-url number)
104 ".sig"))))
105 (unless (gnupg-verify* sig patch)
106 (error "failed to verify signature" patch))
107
108 (list number
109 (bytevector->nix-base32-string
110 (call-with-input-file patch port-sha256)))))
111 1+
112 1))
113
114 (define-public bash
115 (let* ((cppflags (string-join '("-DSYS_BASHRC='\"/etc/bashrc\"'"
116 "-DSYS_BASH_LOGOUT='\"/etc/bash_logout\"'"
117 "-DDEFAULT_PATH_VALUE='\"/no-such-path\"'"
118 "-DSTANDARD_UTILS_PATH='\"/no-such-path\"'"
119 "-DNON_INTERACTIVE_LOGIN_SHELLS"
120 "-DSSH_SOURCE_BASHRC")
121 " "))
122 (configure-flags
123 ``("--with-installed-readline"
124 ,,(string-append "CPPFLAGS=" cppflags)
125 ,(string-append
126 "LDFLAGS=-Wl,-rpath -Wl,"
127 (assoc-ref %build-inputs "readline")
128 "/lib"
129 " -Wl,-rpath -Wl,"
130 (assoc-ref %build-inputs "ncurses")
131 "/lib")))
132 (post-install-phase
133 '(lambda* (#:key outputs #:allow-other-keys)
134 ;; Add a `bash' -> `sh' link.
135 (let ((out (assoc-ref outputs "out")))
136 (with-directory-excursion (string-append out "/bin")
137 (symlink "bash" "sh")))))
138 (install-headers-phase
139 '(lambda* (#:key outputs #:allow-other-keys)
140 ;; Install Bash headers so that packages that provide extensions
141 ;; can use them. We install them in include/bash; that's what
142 ;; Debian does and what Bash extensions like recutils or
143 ;; guile-bash expect.
144 (let ((include (string-append (assoc-ref outputs "include")
145 "/include/bash"))
146 (headers "^\\./(builtins/|lib/glob/|lib/tilde/|)[^/]+\\.h$"))
147 (mkdir-p include)
148 (for-each (lambda (file)
149 (when ((@ (ice-9 regex) string-match) headers file)
150 (let ((directory (string-append include "/"
151 (dirname file))))
152 (mkdir-p directory)
153 (copy-file file
154 (string-append directory "/"
155 (basename file))))))
156 (find-files "." "\\.h$"))
157 #t)))
158 (version "4.3"))
159 (package
160 (name "bash")
161 (source (origin
162 (method url-fetch)
163 (uri (string-append
164 "mirror://gnu/bash/bash-" version ".tar.gz"))
165 (sha256
166 (base32
167 "1m14s1f61mf6bijfibcjm9y6pkyvz6gibyl8p4hxq90fisi8gimg"))
168 (patch-flags '("-p0"))
169 (patches %patch-series-4.3)
170
171 ;; The patches above modify 'parse.y', so force a rebuild of the
172 ;; parser.
173 (snippet '(for-each delete-file
174 '("y.tab.c" "y.tab.h" "parser-built")))))
175 (version (string-append version "."
176 (number->string (length %patch-series-4.3))))
177 (build-system gnu-build-system)
178
179 (outputs '("out"
180 "include")) ;headers used by extensions
181 (native-inputs `(("bison" ,bison))) ;to rebuild the parser
182 (inputs `(("readline" ,readline)
183 ("ncurses" ,ncurses))) ;TODO: add texinfo
184 (arguments
185 `(;; When cross-compiling, `configure' incorrectly guesses that job
186 ;; control is missing.
187 #:configure-flags ,(if (%current-target-system)
188 `(cons* "bash_cv_job_control_missing=no"
189 ,configure-flags)
190 configure-flags)
191
192 ;; Bash is reportedly not parallel-safe. See, for instance,
193 ;; <http://patches.openembedded.org/patch/32745/> and
194 ;; <http://git.buildroot.net/buildroot/commit/?h=79e2d802a>.
195 #:parallel-build? #f
196 #:parallel-tests? #f
197
198 ;; XXX: The tests have a lot of hard-coded paths, so disable them
199 ;; for now.
200 #:tests? #f
201
202 #:phases (modify-phases %standard-phases
203 (add-after 'install 'post-install ,post-install-phase)
204 (add-after 'install 'install-headers
205 ,install-headers-phase))))
206 (synopsis "The GNU Bourne-Again SHell")
207 (description
208 "Bash is the shell, or command-line interpreter, of the GNU system. It
209 is compatible with the Bourne Shell, but it also integrates useful features
210 from the Korn Shell and the C Shell and new improvements of its own. It
211 allows command-line editing, unlimited command history, shell functions and
212 aliases, and job control while still allowing most sh scripts to be run
213 without modification.")
214 (license gpl3+)
215 (home-page "http://www.gnu.org/software/bash/"))))
216
217 (define-public bash-minimal
218 ;; A stripped-down Bash for non-interactive use.
219 (package (inherit bash)
220 (name "bash-minimal")
221 (inputs '()) ; no readline, no curses
222 (arguments
223 (let ((args `(#:modules ((guix build gnu-build-system)
224 (guix build utils)
225 (srfi srfi-1)
226 (srfi srfi-26))
227 ,@(package-arguments bash))))
228 (substitute-keyword-arguments args
229 ((#:configure-flags flags)
230 `(list "--without-bash-malloc"
231 "--disable-readline"
232 "--disable-history"
233 "--disable-help-builtin"
234 "--disable-progcomp"
235 "--disable-net-redirections"
236 "--disable-nls"
237
238 ,@(if (%current-target-system)
239 '("bash_cv_job_control_missing=no")
240 '()))))))))
241
242 (define-public static-bash
243 ;; Statically-linked Bash that contains nothing but the 'bash' binary and
244 ;; 'sh' symlink, without any reference.
245 (let ((bash (static-package bash-minimal)))
246 (package
247 (inherit bash)
248 (name "bash-static")
249 (arguments
250 (substitute-keyword-arguments
251 `(#:allowed-references ("out") ,@(package-arguments bash))
252 ((#:phases phases)
253 `(alist-cons-after
254 'strip 'remove-everything-but-the-binary
255 (lambda* (#:key outputs #:allow-other-keys)
256 (let* ((out (assoc-ref outputs "out"))
257 (bin (string-append out "/bin")))
258 (remove-store-references (string-append bin "/bash"))
259 (delete-file (string-append bin "/bashbug"))
260 (delete-file-recursively (string-append out "/share"))
261 #t))
262 ,phases)))))))
263
264 (define-public bash-completion
265 (package
266 (name "bash-completion")
267 (version "2.1")
268 (source (origin
269 (method url-fetch)
270 (uri (string-append
271 "http://bash-completion.alioth.debian.org/files/"
272 "bash-completion-" version ".tar.bz2"))
273 (sha256
274 (base32
275 "0kxf8s5bw7y50x0ksb77d3kv0dwadixhybl818w27y6mlw26hq1b"))
276 (patches
277 (list (search-patch "bash-completion-directories.patch")))))
278 (build-system gnu-build-system)
279 (native-inputs `(("util-linux" ,util-linux)))
280 (arguments
281 `(#:phases (alist-cons-after
282 'install 'remove-redundant-completions
283 (lambda* (#:key inputs outputs #:allow-other-keys)
284 ;; Util-linux comes with a bunch of completion files for
285 ;; its own commands which are more sophisticated and
286 ;; up-to-date than those of bash-completion. Remove those
287 ;; from bash-completion.
288 (let* ((out (assoc-ref outputs "out"))
289 (util-linux (assoc-ref inputs "util-linux"))
290 (completions (string-append out
291 "/share/bash-completion"
292 "/completions"))
293 (already (find-files
294 (string-append
295 util-linux
296 "/etc/bash_completion.d"))))
297 (with-directory-excursion completions
298 (for-each (lambda (file)
299 (when (file-exists? file)
300 (delete-file file)))
301 (map basename already)))
302 #t))
303 %standard-phases)))
304 (synopsis "Bash completions for common commands")
305 (description
306 "This package provides extensions that allow Bash to provide adapted
307 completion for many common commands.")
308 (home-page "http://bash-completion.alioth.debian.org/")
309 (license gpl2+)))