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