gnu: emacs-svg-icon: Fix grammar.
[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, 2020 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, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
7 ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
8 ;;; Copyright © 2020 Zhu Zihao <all_but_last@163.com>
9 ;;;
10 ;;; This file is part of GNU Guix.
11 ;;;
12 ;;; GNU Guix is free software; you can redistribute it and/or modify it
13 ;;; under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 3 of the License, or (at
15 ;;; your option) any later version.
16 ;;;
17 ;;; GNU Guix is distributed in the hope that it will be useful, but
18 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;;; GNU General Public License for more details.
21 ;;;
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24
25 (define-module (gnu packages bash)
26 #:use-module ((guix licenses) #:prefix license:)
27 #:use-module (gnu packages)
28 #:use-module (gnu packages base)
29 #:use-module (gnu packages bootstrap)
30 #:use-module (gnu packages compression)
31 #:use-module (gnu packages elf)
32 #:use-module (gnu packages ncurses)
33 #:use-module (gnu packages readline)
34 #:use-module (gnu packages bison)
35 #:use-module (gnu packages linux)
36 #:use-module (gnu packages libffi)
37 #:use-module (gnu packages pkg-config)
38 #:use-module (gnu packages guile)
39 #:use-module (guix packages)
40 #:use-module (guix download)
41 #:use-module (guix git-download)
42 #:use-module (guix utils)
43 #:use-module (guix gexp)
44 #:use-module (guix monads)
45 #:use-module (guix store)
46 #:use-module (guix build-system gnu)
47 #:use-module (guix build-system trivial)
48 #:autoload (guix gnupg) (gnupg-verify*)
49 #:autoload (guix base32) (bytevector->nix-base32-string)
50
51 ;; See <https://bugs.gnu.org/41457> for why not #:autoload here.
52 #:use-module ((gcrypt hash) #:select (port-sha256))
53
54 #:use-module (srfi srfi-1)
55 #:use-module (srfi srfi-26)
56 #:use-module (ice-9 format))
57
58 (define (patch-url seqno)
59 "Return the URL of Bash patch number SEQNO."
60 (format #f "mirror://gnu/bash/bash-5.0-patches/bash50-~3,'0d" seqno))
61
62 (define (bash-patch seqno sha256-bv)
63 "Return the origin of Bash patch SEQNO, with expected hash SHA256-BV."
64 (origin
65 (method url-fetch)
66 (uri (patch-url seqno))
67 (sha256 sha256-bv)))
68
69 (define-syntax-rule (patch-series (seqno hash) ...)
70 (list (bash-patch seqno (base32 hash))
71 ...))
72
73 (define %patch-series-5.0
74 ;; This is the current patches series for 5.0, generated using
75 ;; 'download-patches' below.
76 (patch-series
77 (1 "12bjfdy6bg8nhyw27bdgxn7h4paylx8d927skfmi9pxd1wgrxzpj")
78 (2 "01w7yrzmz10mw06ys0546vhl7isv2v402ziyvfd7k67588spvs47")
79 (3 "0ny81ridp5n0j69hb8ixrc7dmxybby54jbsz5hikly8kgg1wvssf")
80 (4 "021gqqvgydixkrmqss64b6srfdlkvnx88lyfzpxfrn5d6bc7li0l")
81 (5 "0xl2kyzm84nlyklrqzkn73ixabhzfhn9x91lzcmis89cppclvxav")
82 (6 "0844749ixk1z60437nkznzms1f0nzh9an62kj7sny6r0zyk2k1fn")
83 (7 "16xg37gp1b8zlj5969w8mcrparwqlcbj9695vn3qhgb7wdz1xd0p")
84 (8 "1qyp19krjh8zxvb0jgwmyjz40djslwcf4xi7kc1ab0iaca44bipf")
85 (9 "00yrjjqd95s81b21qq3ba1y7h879q8jaajlkjggc6grhcwbs4g7d")
86 (10 "04ca5bjv456v538mkspzvn4xb2zdphh31r4fpvfm9p5my0jw7yyn")
87 (11 "1sklyixvsv8993kxzs0jigacpdchjrq7jv5xpdx7kbqyp4rf6k9c")
88 (12 "0cz21qg2gbr40lfgza7g02bqi2qknwqgxnq459pjj640d0cywhr9")
89 (13 "16h9nwz3yzwj7fnxvlidjymdc4yr30h818433gh9j1x3in6igmzm")
90 (14 "12gm5bvv2pd3m72z2ilj26pa08c61az253dsgfl24vpf2ijywvjx")
91 (15 "0pm0px758w4i23s55wajcv6lqfiym7zgxvq0pxf6vclkv8nxy5x5")
92 (16 "0vdha332km2iwx8g2ld15jy7d24cbplzgr1531dpzylr9ajxglgz")))
93
94 (define (download-patches store count)
95 "Download COUNT Bash patches into store. Return a list of
96 number/base32-hash tuples, directly usable in the 'patch-series' form."
97 (unfold (cut > <> count)
98 (lambda (number)
99 (let* ((patch (download-to-store store (patch-url number)))
100 (sig (download-to-store store
101 (string-append (patch-url number)
102 ".sig"))))
103 (unless (eq? 'valid-signature (gnupg-verify* sig patch))
104 (error "failed to verify signature" patch))
105
106 (list number
107 (bytevector->nix-base32-string
108 (call-with-input-file patch port-sha256)))))
109 1+
110 1))
111
112 (define-public bash
113 (let* ((cppflags (string-join '("-DDEFAULT_PATH_VALUE='\"/no-such-path\"'"
114 "-DSTANDARD_UTILS_PATH='\"/no-such-path\"'"
115 "-DNON_INTERACTIVE_LOGIN_SHELLS"
116 "-DSSH_SOURCE_BASHRC")
117 " "))
118 (configure-flags
119 ``("--with-installed-readline"
120 ,,(string-append "CPPFLAGS=" cppflags)
121 ,(string-append
122 "LDFLAGS=-Wl,-rpath -Wl,"
123 (assoc-ref %build-inputs "readline")
124 "/lib"
125 " -Wl,-rpath -Wl,"
126 (assoc-ref %build-inputs "ncurses")
127 "/lib")))
128 (version "5.0"))
129 (package
130 (name "bash")
131 (source (origin
132 (method url-fetch)
133 (uri (string-append
134 "mirror://gnu/bash/bash-" version ".tar.gz"))
135 (sha256
136 (base32
137 "0kgvfwqdcd90waczf4gx39xnrxzijhjrzyzv7s8v4w31qqm0za5l"))
138 (patch-flags '("-p0"))
139 (patches (cons (search-patch "bash-linux-pgrp-pipe.patch")
140 %patch-series-5.0))))
141 (version (string-append version "." (number->string (length %patch-series-5.0))))
142 (build-system gnu-build-system)
143
144 (outputs '("out"
145 "doc" ;1.7 MiB of HTML and extra files
146 "include")) ;headers used by extensions
147 (inputs `(("readline" ,readline)
148 ("ncurses" ,ncurses))) ;TODO: add texinfo
149 (arguments
150 `(;; When cross-compiling, `configure' incorrectly guesses that job
151 ;; control is missing.
152 #:configure-flags ,(if (%current-target-system)
153 `(cons* "bash_cv_job_control_missing=no"
154 ,configure-flags)
155 configure-flags)
156
157 ;; Bash is reportedly not parallel-safe. See, for instance,
158 ;; <http://patches.openembedded.org/patch/32745/> and
159 ;; <http://git.buildroot.net/buildroot/commit/?h=79e2d802a>.
160 #:parallel-build? #f
161 #:parallel-tests? #f
162
163 ;; XXX: The tests have a lot of hard-coded paths, so disable them
164 ;; for now.
165 #:tests? #f
166
167 #:modules ((srfi srfi-26)
168 (guix build utils)
169 (guix build gnu-build-system))
170
171 #:phases
172 (modify-phases %standard-phases
173 (add-after 'install 'install-sh-symlink
174 (lambda* (#:key outputs #:allow-other-keys)
175 ;; Add a `sh' -> `bash' link.
176 (let ((out (assoc-ref outputs "out")))
177 (with-directory-excursion (string-append out "/bin")
178 (symlink "bash" "sh")
179 #t))))
180
181 (add-after 'install 'move-development-files
182 (lambda* (#:key outputs #:allow-other-keys)
183 ;; Move 'Makefile.inc' and 'bash.pc' to "include" to avoid
184 ;; circular references among the outputs.
185 (let ((out (assoc-ref outputs "out"))
186 (include (assoc-ref outputs "include"))
187 (lib (cut string-append <> "/lib/bash")))
188 (mkdir-p (lib include))
189 (rename-file (string-append (lib out)
190 "/Makefile.inc")
191 (string-append (lib include)
192 "/Makefile.inc"))
193 (rename-file (string-append out "/lib/pkgconfig")
194 (string-append include
195 "/lib/pkgconfig"))
196
197 ;; Don't capture the absolute file name of 'install' to avoid
198 ;; retaining a dependency on Coreutils.
199 (substitute* (string-append (lib include)
200 "/Makefile.inc")
201 (("^INSTALL =.*")
202 "INSTALL = install -c\n"))
203 #t))))))
204
205 (native-search-paths
206 (list (search-path-specification ;new in 4.4
207 (variable "BASH_LOADABLES_PATH")
208 (files '("lib/bash")))))
209
210 (synopsis "The GNU Bourne-Again SHell")
211 (description
212 "Bash is the shell, or command-line interpreter, of the GNU system. It
213 is compatible with the Bourne Shell, but it also integrates useful features
214 from the Korn Shell and the C Shell and new improvements of its own. It
215 allows command-line editing, unlimited command history, shell functions and
216 aliases, and job control while still allowing most sh scripts to be run
217 without modification.")
218 (license license:gpl3+)
219 (home-page "https://www.gnu.org/software/bash/"))))
220
221 (define-public bash-minimal
222 ;; A stripped-down Bash for non-interactive use.
223 (package (inherit bash)
224 (name "bash-minimal")
225 (inputs '()) ; no readline, no curses
226
227 ;; No "include" output because there's no support for loadable modules.
228 (outputs (delete "include" (package-outputs bash)))
229
230 (arguments
231 (substitute-keyword-arguments (package-arguments bash)
232 ((#:modules _ '())
233 '((guix build gnu-build-system)
234 (guix build utils)
235 (srfi srfi-1)
236 (srfi srfi-26)))
237 ((#:configure-flags flags '())
238 `(list "--without-bash-malloc"
239 "--disable-readline"
240 "--disable-history"
241 "--disable-help-builtin"
242 "--disable-progcomp"
243 "--disable-net-redirections"
244 "--disable-nls"
245
246 ;; Pretend 'dlopen' is missing so we don't build loadable
247 ;; modules and related code.
248 "ac_cv_func_dlopen=no"
249
250 ,@(if (%current-target-system)
251 '("bash_cv_job_control_missing=no"
252 "bash_cv_getcwd_malloc=yes")
253 '())))
254 ((#:phases phases)
255 `(modify-phases ,phases
256 ;; No loadable modules.
257 (delete 'move-development-files)))))))
258
259 (define-public static-bash
260 ;; Statically-linked Bash that contains nothing but the 'bash' binary and
261 ;; 'sh' symlink, without any reference.
262 (let ((bash (static-package bash-minimal)))
263 (package
264 (inherit bash)
265 (name "bash-static")
266 (arguments
267 (substitute-keyword-arguments
268 `(#:allowed-references ("out") ,@(package-arguments bash))
269 ((#:phases phases)
270 `(modify-phases ,phases
271 (add-after 'strip 'remove-everything-but-the-binary
272 (lambda* (#:key outputs #:allow-other-keys)
273 (let* ((out (assoc-ref outputs "out"))
274 (bin (string-append out "/bin")))
275 (remove-store-references (string-append bin "/bash"))
276 (delete-file (string-append bin "/bashbug"))
277 (delete-file-recursively (string-append out "/share"))
278 #t))))))))))
279
280 (define-public bash-completion
281 (package
282 (name "bash-completion")
283 (version "2.8")
284 (source (origin
285 (method url-fetch)
286 (uri (string-append
287 "https://github.com/scop/" name "/releases/download/"
288 version "/" name "-" version ".tar.xz"))
289 (sha256
290 (base32
291 "0kgmflrr1ga9wfk770vmakna3nj46ylb5ky9ipd0v2k9ymq5a7y0"))
292 (patches
293 (search-patches "bash-completion-directories.patch"))))
294 (build-system gnu-build-system)
295 (native-inputs `(("util-linux" ,util-linux)))
296 (arguments
297 `(#:phases (modify-phases %standard-phases
298 (add-after
299 'install 'remove-redundant-completions
300 (lambda* (#:key
301 inputs native-inputs
302 outputs #:allow-other-keys)
303 ;; Util-linux comes with a bunch of completion files for
304 ;; its own commands which are more sophisticated and
305 ;; up-to-date than those of bash-completion. Remove those
306 ;; from bash-completion.
307 (let* ((out (assoc-ref outputs "out"))
308 (util-linux (assoc-ref (or native-inputs inputs)
309 "util-linux"))
310 (completions (string-append out
311 "/share/bash-completion"
312 "/completions"))
313 (already (find-files
314 (string-append
315 util-linux
316 "/etc/bash_completion.d"))))
317 (with-directory-excursion completions
318 (for-each (lambda (file)
319 (when (file-exists? file)
320 (delete-file file)))
321 (map basename already)))
322 #t))))))
323 (synopsis "Bash completions for common commands")
324 (description
325 "This package provides extensions that allow Bash to provide adapted
326 completion for many common commands.")
327 (home-page "https://github.com/scop/bash-completion")
328 (license license:gpl2+)))
329
330 (define-public bash-tap
331 (package
332 (name "bash-tap")
333 (version "1.0.2")
334 (source
335 (origin
336 (method git-fetch)
337 (uri (git-reference
338 (url "https://github.com/illusori/bash-tap")
339 (commit version)))
340 (file-name (git-file-name name version))
341 (sha256
342 (base32 "13zz9h6bhhnk3hiwhlpafrnf2isws249h3fz785dcgymk02arz9c"))))
343 ;; There is no compilation process to use this package, however, the bash
344 ;; scripts installed by this package start with "#!/bin/bash". To fix
345 ;; these lines, we use the patch-shebangs of the GNU build system. The
346 ;; project does not use a Makefile.
347 (build-system gnu-build-system)
348 (arguments
349 `(#:tests? #f ; There is no test suite.
350 #:phases
351 (modify-phases %standard-phases
352 ;; Because there are no configure scripts or Makefile, we can
353 ;; remove these phases.
354 (delete 'configure)
355 (delete 'build)
356 ;; The installation involves manually copying the files to a location.
357 ;; To make them easily accessible by setting PATH, we add the scripts
358 ;; to the "bin" folder.
359 (replace 'install
360 (lambda* (#:key outputs #:allow-other-keys)
361 (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
362 (install-file "bash-tap" bin)
363 (install-file "bash-tap-bootstrap" bin)
364 (install-file "bash-tap-mock" bin)))))))
365 (home-page "https://www.illusori.co.uk/projects/bash-tap/")
366 (synopsis "Bash port of a Test::More/Test::Builder-style TAP-compliant
367 test library")
368 (description "Bash TAP is a TAP-compliant Test::More-style testing library
369 for Bash shell scripts and functions. Along with the Test::More-style testing
370 helpers it provides helper functions for mocking commands and in-process output
371 capturing.")
372 (license license:expat)))
373
374 (define-public bats
375 (package
376 (name "bats")
377 (version "1.2.0")
378 (source (origin
379 (method git-fetch)
380 (uri (git-reference
381 (url "https://github.com/bats-core/bats-core")
382 (commit (string-append "v" version))))
383 (file-name (git-file-name name version))
384 (sha256
385 (base32
386 "0f59zh4d4pa1a7ybs5zl6h0csbqqv11lbnq0jl1dgwm1s6p49bsq"))))
387 (inputs
388 `(("bash" ,bash)
389 ("coreutils" ,coreutils)
390 ("guile" ,guile-3.0) ;for wrap-script
391 ("grep" ,grep)))
392 (arguments
393 `(#:modules ((guix build utils))
394 #:builder
395 (begin
396 (use-modules (guix build utils))
397 (copy-recursively (assoc-ref %build-inputs "source") ".")
398 (setenv "PATH"
399 (string-append (assoc-ref %build-inputs "bash") "/bin"
400 ":" (assoc-ref %build-inputs "coreutils") "/bin"
401 ":" (assoc-ref %build-inputs "grep") "/bin"
402 ":" (assoc-ref %build-inputs "guile") "/bin"
403 ":" (getenv "PATH")))
404 (for-each (lambda (file) (patch-shebang file)) (find-files "."))
405 (substitute* "bin/bats"
406 (("export BATS_ROOT" line)
407 (string-append "BATS_ROOT=\"${BATS_ROOT:-" %output "/libexec/bats-core}\"\n"
408 line)))
409 ;; Install phase
410 (invoke "./install.sh" %output)
411 (wrap-script (string-append %output "/bin/bats")
412 (list "PATH" 'prefix (string-split (getenv "PATH")
413 #\:))))))
414 (build-system trivial-build-system)
415 (home-page "https://github.com/bats-core/bats-core/")
416 (synopsis "Bash Automated Testing System")
417 (description
418 "Bats is a @acronym{TAP, Test Anything Protocol}-compliant testing
419 framework for Bash. It provides a simple way to verify that the UNIX programs
420 you write behave as expected. Bats is most useful when testing software written
421 in Bash, but you can use it to test any UNIX program.")
422 (license license:expat)))
423
424 (define-public bash-ctypes
425 (package
426 (name "bash-ctypes")
427 (version "1.2")
428 (source
429 (origin
430 (method url-fetch)
431 (uri (string-append "https://github.com/taviso/ctypes.sh/releases/download/v"
432 version "/ctypes-sh-" version ".tar.gz"))
433 (sha256
434 (base32 "0s1sifqzqmr0dnciv06yqrpzgj11d7n0gy5zaxh6b3x8bx7k75l8"))))
435 (build-system gnu-build-system)
436 (inputs
437 `(("elfutils" ,elfutils)
438 ("libelf" ,libelf)
439 ("libffi" ,libffi)
440 ("zlib" ,zlib)
441 ;; Require a bash with C plugin support to build.
442 ("bash" ,bash)))
443 (native-inputs
444 `(("pkg-config" ,pkg-config)))
445 (home-page "https://github.com/taviso/ctypes.sh")
446 (synopsis "Foreign function interface for Bash")
447 (description "Bash-ctypes is a Bash plugin that provides a foreign
448 function interface (FFI) directly in your shell. In other words, it allows
449 you to call routines in shared libraries from within Bash.")
450 (license license:expat)))