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