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