Merge branch '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 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 ;;;
7 ;;; This file is part of GNU Guix.
8 ;;;
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.
13 ;;;
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.
18 ;;;
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/>.
21
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))
43
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))
47
48 (define (bash-patch seqno sha256)
49 "Return the origin of Bash patch SEQNO, with expected hash SHA256"
50 (origin
51 (method url-fetch)
52 (uri (patch-url seqno))
53 (sha256 sha256)))
54
55 (define-syntax-rule (patch-series (seqno hash) ...)
56 (list (bash-patch seqno (base32 hash))
57 ...))
58
59 (define %patch-series-4.4
60 ;; This is the current patches series for 4.4, generated using
61 ;; 'download-patches' below.
62 (patch-series
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
76 (define (download-patches store count)
77 "Download COUNT Bash patches into store. Return a list of
78 number/base32-hash tuples, directly usable in the 'patch-series' form."
79 (unfold (cut > <> count)
80 (lambda (number)
81 (let* ((patch (download-to-store store (patch-url number)))
82 (sig (download-to-store store
83 (string-append (patch-url number)
84 ".sig"))))
85 (unless (gnupg-verify* sig patch)
86 (error "failed to verify signature" patch))
87
88 (list number
89 (bytevector->nix-base32-string
90 (call-with-input-file patch port-sha256)))))
91 1+
92 1))
93
94 (define-public bash
95 (let* ((cppflags (string-join '("-DSYS_BASHRC='\"/etc/bashrc\"'"
96 "-DSYS_BASH_LOGOUT='\"/etc/bash_logout\"'"
97 "-DDEFAULT_PATH_VALUE='\"/no-such-path\"'"
98 "-DSTANDARD_UTILS_PATH='\"/no-such-path\"'"
99 "-DNON_INTERACTIVE_LOGIN_SHELLS"
100 "-DSSH_SOURCE_BASHRC")
101 " "))
102 (configure-flags
103 ``("--with-installed-readline"
104 ,,(string-append "CPPFLAGS=" cppflags)
105 ,(string-append
106 "LDFLAGS=-Wl,-rpath -Wl,"
107 (assoc-ref %build-inputs "readline")
108 "/lib"
109 " -Wl,-rpath -Wl,"
110 (assoc-ref %build-inputs "ncurses")
111 "/lib")))
112 (version "4.4"))
113 (package
114 (name "bash")
115 (source (origin
116 (method url-fetch)
117 (uri (string-append
118 "mirror://gnu/bash/bash-" version ".tar.gz"))
119 (sha256
120 (base32
121 "1jyz6snd63xjn6skk7za6psgidsd53k05cr3lksqybi0q6936syq"))
122 (patch-flags '("-p0"))
123 (patches %patch-series-4.4)))
124 (version (string-append version "."
125 (number->string (length %patch-series-4.4))))
126 (build-system gnu-build-system)
127
128 (outputs '("out"
129 "doc" ;1.7 MiB of HTML and extra files
130 "include")) ;headers used by extensions
131 (inputs `(("readline" ,readline)
132 ("ncurses" ,ncurses))) ;TODO: add texinfo
133 (arguments
134 `(;; When cross-compiling, `configure' incorrectly guesses that job
135 ;; control is missing.
136 #:configure-flags ,(if (%current-target-system)
137 `(cons* "bash_cv_job_control_missing=no"
138 ,configure-flags)
139 configure-flags)
140
141 ;; Bash is reportedly not parallel-safe. See, for instance,
142 ;; <http://patches.openembedded.org/patch/32745/> and
143 ;; <http://git.buildroot.net/buildroot/commit/?h=79e2d802a>.
144 #:parallel-build? #f
145 #:parallel-tests? #f
146
147 ;; XXX: The tests have a lot of hard-coded paths, so disable them
148 ;; for now.
149 #:tests? #f
150
151 #:modules ((srfi srfi-26)
152 (guix build utils)
153 (guix build gnu-build-system))
154
155 #:phases
156 (modify-phases %standard-phases
157 (add-after 'install 'install-sh-symlink
158 (lambda* (#:key outputs #:allow-other-keys)
159 ;; Add a `sh' -> `bash' link.
160 (let ((out (assoc-ref outputs "out")))
161 (with-directory-excursion (string-append out "/bin")
162 (symlink "bash" "sh")))))
163
164 (add-after 'install 'move-development-files
165 (lambda* (#:key outputs #:allow-other-keys)
166 ;; Move 'Makefile.inc' and 'bash.pc' to "include" to avoid
167 ;; circular references among the outputs.
168 (let ((out (assoc-ref outputs "out"))
169 (include (assoc-ref outputs "include"))
170 (lib (cut string-append <> "/lib/bash")))
171 (mkdir-p (lib include))
172 (rename-file (string-append (lib out)
173 "/Makefile.inc")
174 (string-append (lib include)
175 "/Makefile.inc"))
176 (rename-file (string-append out "/lib/pkgconfig")
177 (string-append include
178 "/lib/pkgconfig"))
179
180 ;; Don't capture the absolute file name of 'install' to avoid
181 ;; retaining a dependency on Coreutils.
182 (substitute* (string-append (lib include)
183 "/Makefile.inc")
184 (("^INSTALL =.*")
185 "INSTALL = install -c\n"))
186 #t))))))
187
188 (native-search-paths
189 (list (search-path-specification ;new in 4.4
190 (variable "BASH_LOADABLES_PATH")
191 (files '("lib/bash")))))
192
193 (synopsis "The GNU Bourne-Again SHell")
194 (description
195 "Bash is the shell, or command-line interpreter, of the GNU system. It
196 is compatible with the Bourne Shell, but it also integrates useful features
197 from the Korn Shell and the C Shell and new improvements of its own. It
198 allows command-line editing, unlimited command history, shell functions and
199 aliases, and job control while still allowing most sh scripts to be run
200 without modification.")
201 (license gpl3+)
202 (home-page "https://www.gnu.org/software/bash/"))))
203
204 (define-public bash-minimal
205 ;; A stripped-down Bash for non-interactive use.
206 (package (inherit bash)
207 (name "bash-minimal")
208 (inputs '()) ; no readline, no curses
209
210 ;; No "include" output because there's no support for loadable modules.
211 (outputs (delete "include" (package-outputs bash)))
212
213 (arguments
214 (substitute-keyword-arguments (package-arguments bash)
215 ((#:modules _ '())
216 '((guix build gnu-build-system)
217 (guix build utils)
218 (srfi srfi-1)
219 (srfi srfi-26)))
220 ((#:configure-flags flags '())
221 `(list "--without-bash-malloc"
222 "--disable-readline"
223 "--disable-history"
224 "--disable-help-builtin"
225 "--disable-progcomp"
226 "--disable-net-redirections"
227 "--disable-nls"
228
229 ;; Pretend 'dlopen' is missing so we don't build loadable
230 ;; modules and related code.
231 "ac_cv_func_dlopen=no"
232
233 ,@(if (%current-target-system)
234 '("bash_cv_job_control_missing=no"
235 "bash_cv_getcwd_malloc=yes")
236 '())))
237 ((#:phases phases)
238 `(modify-phases ,phases
239 ;; No loadable modules.
240 (delete 'move-development-files)))))))
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 `(modify-phases ,phases
254 (add-after '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
263 (define-public bash-completion
264 (package
265 (name "bash-completion")
266 (version "2.7")
267 (source (origin
268 (method url-fetch)
269 (uri (string-append
270 "https://github.com/scop/" name "/releases/download/"
271 version "/" name "-" version ".tar.xz"))
272 (sha256
273 (base32
274 "07j484vb3k90f4989xh1g1x99g01akrp69p3dml4lza27wnqkfj1"))
275 (patches
276 (search-patches "bash-completion-directories.patch"))))
277 (build-system gnu-build-system)
278 (native-inputs `(("util-linux" ,util-linux)))
279 (arguments
280 `(#:phases (modify-phases %standard-phases
281 (add-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 (synopsis "Bash completions for common commands")
304 (description
305 "This package provides extensions that allow Bash to provide adapted
306 completion for many common commands.")
307 (home-page "https://github.com/scop/bash-completion")
308 (license gpl2+)))
309
310 (define-public bash-tap
311 (package
312 (name "bash-tap")
313 (version "1.0.2")
314 (source (origin
315 (method url-fetch)
316 (uri (string-append "https://github.com/illusori/bash-tap/"
317 "archive/" version ".tar.gz"))
318 (file-name (string-append name "-" version ".tar.gz"))
319 (sha256
320 (base32
321 "0qs1qi38bl3ns4mpagcawv618dsk2q1lgrbddgvs0wl3ia12cyz5"))))
322 ;; There is no compilation process to use this package, however, the bash
323 ;; scripts installed by this package start with "#!/bin/bash". To fix
324 ;; these lines, we use the patch-shebangs of the GNU build system. The
325 ;; project does not use a Makefile.
326 (build-system gnu-build-system)
327 (arguments
328 `(#:tests? #f ; There is no test suite.
329 #:phases
330 (modify-phases %standard-phases
331 ;; Because there are no configure scripts or Makefile, we can
332 ;; remove these phases.
333 (delete 'configure)
334 (delete 'build)
335 ;; The installation involves manually copying the files to a location.
336 ;; To make them easily accessible by setting PATH, we add the scripts
337 ;; to the "bin" folder.
338 (replace 'install
339 (lambda* (#:key outputs #:allow-other-keys)
340 (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
341 (install-file "bash-tap" bin)
342 (install-file "bash-tap-bootstrap" bin)
343 (install-file "bash-tap-mock" bin)))))))
344 (home-page "http://www.illusori.co.uk/projects/bash-tap/")
345 (synopsis "Bash port of a Test::More/Test::Builder-style TAP-compliant
346 test library")
347 (description "Bash TAP is a TAP-compliant Test::More-style testing library
348 for Bash shell scripts and functions. Along with the Test::More-style testing
349 helpers it provides helper functions for mocking commands and in-process output
350 capturing.")
351 (license expat)))