Merge branch 'staging' 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, 2019 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, 2018, 2019 Efraim Flashner <efraim@flashner.co.il>
6 ;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
7 ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
8 ;;;
9 ;;; This file is part of GNU Guix.
10 ;;;
11 ;;; GNU Guix is free software; you can redistribute it and/or modify it
12 ;;; under the terms of the GNU General Public License as published by
13 ;;; the Free Software Foundation; either version 3 of the License, or (at
14 ;;; your option) any later version.
15 ;;;
16 ;;; GNU Guix is distributed in the hope that it will be useful, but
17 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;;; GNU General Public License for more details.
20 ;;;
21 ;;; You should have received a copy of the GNU General Public License
22 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
23
24 (define-module (gnu packages bash)
25 #:use-module (guix licenses)
26 #:use-module (gnu packages)
27 #:use-module (gnu packages bootstrap)
28 #:use-module (gnu packages ncurses)
29 #:use-module (gnu packages readline)
30 #:use-module (gnu packages bison)
31 #:use-module (gnu packages linux)
32 #:use-module (guix packages)
33 #:use-module (guix download)
34 #:use-module (guix git-download)
35 #:use-module (guix utils)
36 #:use-module (guix gexp)
37 #:use-module (guix monads)
38 #:use-module (guix store)
39 #:use-module (guix build-system gnu)
40 #:autoload (guix gnupg) (gnupg-verify*)
41 #:autoload (gcrypt hash) (port-sha256)
42 #:autoload (guix base32) (bytevector->nix-base32-string)
43 #:use-module (srfi srfi-1)
44 #:use-module (srfi srfi-26)
45 #:use-module (ice-9 format))
46
47 (define (patch-url seqno)
48 "Return the URL of Bash patch number SEQNO."
49 (format #f "mirror://gnu/bash/bash-5.0-patches/bash50-~3,'0d" seqno))
50
51 (define (bash-patch seqno sha256)
52 "Return the origin of Bash patch SEQNO, with expected hash SHA256"
53 (origin
54 (method url-fetch)
55 (uri (patch-url seqno))
56 (sha256 sha256)))
57
58 (define-syntax-rule (patch-series (seqno hash) ...)
59 (list (bash-patch seqno (base32 hash))
60 ...))
61
62 (define %patch-series-5.0
63 ;; This is the current patches series for 5.0, generated using
64 ;; 'download-patches' below.
65 (patch-series
66 (1 "12bjfdy6bg8nhyw27bdgxn7h4paylx8d927skfmi9pxd1wgrxzpj")
67 (2 "01w7yrzmz10mw06ys0546vhl7isv2v402ziyvfd7k67588spvs47")
68 (3 "0ny81ridp5n0j69hb8ixrc7dmxybby54jbsz5hikly8kgg1wvssf")
69 (4 "021gqqvgydixkrmqss64b6srfdlkvnx88lyfzpxfrn5d6bc7li0l")
70 (5 "0xl2kyzm84nlyklrqzkn73ixabhzfhn9x91lzcmis89cppclvxav")
71 (6 "0844749ixk1z60437nkznzms1f0nzh9an62kj7sny6r0zyk2k1fn")
72 (7 "16xg37gp1b8zlj5969w8mcrparwqlcbj9695vn3qhgb7wdz1xd0p")
73 (8 "1qyp19krjh8zxvb0jgwmyjz40djslwcf4xi7kc1ab0iaca44bipf")
74 (9 "00yrjjqd95s81b21qq3ba1y7h879q8jaajlkjggc6grhcwbs4g7d")
75 (10 "04ca5bjv456v538mkspzvn4xb2zdphh31r4fpvfm9p5my0jw7yyn")
76 (11 "1sklyixvsv8993kxzs0jigacpdchjrq7jv5xpdx7kbqyp4rf6k9c")))
77
78 (define (download-patches store count)
79 "Download COUNT Bash patches into store. Return a list of
80 number/base32-hash tuples, directly usable in the 'patch-series' form."
81 (unfold (cut > <> count)
82 (lambda (number)
83 (let* ((patch (download-to-store store (patch-url number)))
84 (sig (download-to-store store
85 (string-append (patch-url number)
86 ".sig"))))
87 (unless (eq? 'valid-signature (gnupg-verify* sig patch))
88 (error "failed to verify signature" patch))
89
90 (list number
91 (bytevector->nix-base32-string
92 (call-with-input-file patch port-sha256)))))
93 1+
94 1))
95
96 (define-public bash
97 (let* ((cppflags (string-join '("-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 "5.0"))
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 "0kgvfwqdcd90waczf4gx39xnrxzijhjrzyzv7s8v4w31qqm0za5l"))
122 (patch-flags '("-p0"))
123 (patches (cons (search-patch "bash-linux-pgrp-pipe.patch")
124 %patch-series-5.0))))
125 (version (string-append version "." (number->string (length %patch-series-5.0))))
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 #t))))
164
165 (add-after 'install 'move-development-files
166 (lambda* (#:key outputs #:allow-other-keys)
167 ;; Move 'Makefile.inc' and 'bash.pc' to "include" to avoid
168 ;; circular references among the outputs.
169 (let ((out (assoc-ref outputs "out"))
170 (include (assoc-ref outputs "include"))
171 (lib (cut string-append <> "/lib/bash")))
172 (mkdir-p (lib include))
173 (rename-file (string-append (lib out)
174 "/Makefile.inc")
175 (string-append (lib include)
176 "/Makefile.inc"))
177 (rename-file (string-append out "/lib/pkgconfig")
178 (string-append include
179 "/lib/pkgconfig"))
180
181 ;; Don't capture the absolute file name of 'install' to avoid
182 ;; retaining a dependency on Coreutils.
183 (substitute* (string-append (lib include)
184 "/Makefile.inc")
185 (("^INSTALL =.*")
186 "INSTALL = install -c\n"))
187 #t))))))
188
189 (native-search-paths
190 (list (search-path-specification ;new in 4.4
191 (variable "BASH_LOADABLES_PATH")
192 (files '("lib/bash")))))
193
194 (synopsis "The GNU Bourne-Again SHell")
195 (description
196 "Bash is the shell, or command-line interpreter, of the GNU system. It
197 is compatible with the Bourne Shell, but it also integrates useful features
198 from the Korn Shell and the C Shell and new improvements of its own. It
199 allows command-line editing, unlimited command history, shell functions and
200 aliases, and job control while still allowing most sh scripts to be run
201 without modification.")
202 (license gpl3+)
203 (home-page "https://www.gnu.org/software/bash/"))))
204
205 (define-public bash-minimal
206 ;; A stripped-down Bash for non-interactive use.
207 (package (inherit bash)
208 (name "bash-minimal")
209 (inputs '()) ; no readline, no curses
210
211 ;; No "include" output because there's no support for loadable modules.
212 (outputs (delete "include" (package-outputs bash)))
213
214 (arguments
215 (substitute-keyword-arguments (package-arguments bash)
216 ((#:modules _ '())
217 '((guix build gnu-build-system)
218 (guix build utils)
219 (srfi srfi-1)
220 (srfi srfi-26)))
221 ((#:configure-flags flags '())
222 `(list "--without-bash-malloc"
223 "--disable-readline"
224 "--disable-history"
225 "--disable-help-builtin"
226 "--disable-progcomp"
227 "--disable-net-redirections"
228 "--disable-nls"
229
230 ;; Pretend 'dlopen' is missing so we don't build loadable
231 ;; modules and related code.
232 "ac_cv_func_dlopen=no"
233
234 ,@(if (%current-target-system)
235 '("bash_cv_job_control_missing=no"
236 "bash_cv_getcwd_malloc=yes")
237 '())))
238 ((#:phases phases)
239 `(modify-phases ,phases
240 ;; No loadable modules.
241 (delete 'move-development-files)))))))
242
243 (define-public static-bash
244 ;; Statically-linked Bash that contains nothing but the 'bash' binary and
245 ;; 'sh' symlink, without any reference.
246 (let ((bash (static-package bash-minimal)))
247 (package
248 (inherit bash)
249 (name "bash-static")
250 (arguments
251 (substitute-keyword-arguments
252 `(#:allowed-references ("out") ,@(package-arguments bash))
253 ((#:phases phases)
254 `(modify-phases ,phases
255 (add-after 'strip 'remove-everything-but-the-binary
256 (lambda* (#:key outputs #:allow-other-keys)
257 (let* ((out (assoc-ref outputs "out"))
258 (bin (string-append out "/bin")))
259 (remove-store-references (string-append bin "/bash"))
260 (delete-file (string-append bin "/bashbug"))
261 (delete-file-recursively (string-append out "/share"))
262 #t))))))))))
263
264 (define-public bash-completion
265 (package
266 (name "bash-completion")
267 (version "2.8")
268 (source (origin
269 (method url-fetch)
270 (uri (string-append
271 "https://github.com/scop/" name "/releases/download/"
272 version "/" name "-" version ".tar.xz"))
273 (sha256
274 (base32
275 "0kgmflrr1ga9wfk770vmakna3nj46ylb5ky9ipd0v2k9ymq5a7y0"))
276 (patches
277 (search-patches "bash-completion-directories.patch"))))
278 (build-system gnu-build-system)
279 (native-inputs `(("util-linux" ,util-linux)))
280 (arguments
281 `(#:phases (modify-phases %standard-phases
282 (add-after
283 'install 'remove-redundant-completions
284 (lambda* (#:key
285 inputs native-inputs
286 outputs #:allow-other-keys)
287 ;; Util-linux comes with a bunch of completion files for
288 ;; its own commands which are more sophisticated and
289 ;; up-to-date than those of bash-completion. Remove those
290 ;; from bash-completion.
291 (let* ((out (assoc-ref outputs "out"))
292 (util-linux (assoc-ref (or native-inputs inputs)
293 "util-linux"))
294 (completions (string-append out
295 "/share/bash-completion"
296 "/completions"))
297 (already (find-files
298 (string-append
299 util-linux
300 "/etc/bash_completion.d"))))
301 (with-directory-excursion completions
302 (for-each (lambda (file)
303 (when (file-exists? file)
304 (delete-file file)))
305 (map basename already)))
306 #t))))))
307 (synopsis "Bash completions for common commands")
308 (description
309 "This package provides extensions that allow Bash to provide adapted
310 completion for many common commands.")
311 (home-page "https://github.com/scop/bash-completion")
312 (license gpl2+)))
313
314 (define-public bash-tap
315 (package
316 (name "bash-tap")
317 (version "1.0.2")
318 (source
319 (origin
320 (method git-fetch)
321 (uri (git-reference
322 (url "https://github.com/illusori/bash-tap.git")
323 (commit version)))
324 (file-name (git-file-name name version))
325 (sha256
326 (base32 "13zz9h6bhhnk3hiwhlpafrnf2isws249h3fz785dcgymk02arz9c"))))
327 ;; There is no compilation process to use this package, however, the bash
328 ;; scripts installed by this package start with "#!/bin/bash". To fix
329 ;; these lines, we use the patch-shebangs of the GNU build system. The
330 ;; project does not use a Makefile.
331 (build-system gnu-build-system)
332 (arguments
333 `(#:tests? #f ; There is no test suite.
334 #:phases
335 (modify-phases %standard-phases
336 ;; Because there are no configure scripts or Makefile, we can
337 ;; remove these phases.
338 (delete 'configure)
339 (delete 'build)
340 ;; The installation involves manually copying the files to a location.
341 ;; To make them easily accessible by setting PATH, we add the scripts
342 ;; to the "bin" folder.
343 (replace 'install
344 (lambda* (#:key outputs #:allow-other-keys)
345 (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
346 (install-file "bash-tap" bin)
347 (install-file "bash-tap-bootstrap" bin)
348 (install-file "bash-tap-mock" bin)))))))
349 (home-page "http://www.illusori.co.uk/projects/bash-tap/")
350 (synopsis "Bash port of a Test::More/Test::Builder-style TAP-compliant
351 test library")
352 (description "Bash TAP is a TAP-compliant Test::More-style testing library
353 for Bash shell scripts and functions. Along with the Test::More-style testing
354 helpers it provides helper functions for mocking commands and in-process output
355 capturing.")
356 (license expat)))