Merge branch 'master' into staging
[jackhill/guix/guix.git] / gnu / packages / bash.scm
CommitLineData
233e7676 1;;; GNU Guix --- Functional package management for GNU
f94f9d67 2;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2019 Ludovic Courtès <ludo@gnu.org>
8809a153 3;;; Copyright © 2014, 2015, 2018 Mark H Weaver <mhw@netris.org>
b848f98e 4;;; Copyright © 2015, 2017 Leo Famulari <leo@famulari.name>
847ffe88 5;;; Copyright © 2016, 2017, 2018, 2019 Efraim Flashner <efraim@flashner.co.il>
38e10e08 6;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
d8dbfbce 7;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
c44899a2 8;;;
233e7676 9;;; This file is part of GNU Guix.
c44899a2 10;;;
233e7676 11;;; GNU Guix is free software; you can redistribute it and/or modify it
c44899a2
LC
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;;;
233e7676 16;;; GNU Guix is distributed in the hope that it will be useful, but
c44899a2
LC
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
233e7676 22;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
c44899a2 23
1ffa7090 24(define-module (gnu packages bash)
4a44e743 25 #:use-module (guix licenses)
16629c8a 26 #:use-module (gnu packages)
6c5b56f9 27 #:use-module (gnu packages bootstrap)
1ffa7090
LC
28 #:use-module (gnu packages ncurses)
29 #:use-module (gnu packages readline)
2d5d63d7 30 #:use-module (gnu packages bison)
b16b7790 31 #:use-module (gnu packages linux)
c44899a2 32 #:use-module (guix packages)
87f5d366 33 #:use-module (guix download)
38e10e08 34 #:use-module (guix git-download)
c44899a2 35 #:use-module (guix utils)
50b8a527
LC
36 #:use-module (guix gexp)
37 #:use-module (guix monads)
38 #:use-module (guix store)
c1fe82d5
LC
39 #:use-module (guix build-system gnu)
40 #:autoload (guix gnupg) (gnupg-verify*)
ca719424 41 #:autoload (gcrypt hash) (port-sha256)
c1fe82d5
LC
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."
847ffe88 49 (format #f "mirror://gnu/bash/bash-5.0-patches/bash50-~3,'0d" seqno))
c1fe82d5
LC
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
847ffe88
EF
62(define %patch-series-5.0
63 ;; This is the current patches series for 5.0, generated using
c1fe82d5 64 ;; 'download-patches' below.
feefbb09 65 (patch-series
4aeb42b9 66 (1 "12bjfdy6bg8nhyw27bdgxn7h4paylx8d927skfmi9pxd1wgrxzpj")
13f3893b
EF
67 (2 "01w7yrzmz10mw06ys0546vhl7isv2v402ziyvfd7k67588spvs47")
68 (3 "0ny81ridp5n0j69hb8ixrc7dmxybby54jbsz5hikly8kgg1wvssf")
69 (4 "021gqqvgydixkrmqss64b6srfdlkvnx88lyfzpxfrn5d6bc7li0l")
70 (5 "0xl2kyzm84nlyklrqzkn73ixabhzfhn9x91lzcmis89cppclvxav")
71 (6 "0844749ixk1z60437nkznzms1f0nzh9an62kj7sny6r0zyk2k1fn")
3f0f0d61
EF
72 (7 "16xg37gp1b8zlj5969w8mcrparwqlcbj9695vn3qhgb7wdz1xd0p")
73 (8 "1qyp19krjh8zxvb0jgwmyjz40djslwcf4xi7kc1ab0iaca44bipf")
74 (9 "00yrjjqd95s81b21qq3ba1y7h879q8jaajlkjggc6grhcwbs4g7d")
75 (10 "04ca5bjv456v538mkspzvn4xb2zdphh31r4fpvfm9p5my0jw7yyn")
acb92774
MB
76 (11 "1sklyixvsv8993kxzs0jigacpdchjrq7jv5xpdx7kbqyp4rf6k9c")
77 (12 "0cz21qg2gbr40lfgza7g02bqi2qknwqgxnq459pjj640d0cywhr9")
78 (13 "16h9nwz3yzwj7fnxvlidjymdc4yr30h818433gh9j1x3in6igmzm")
79 (14 "12gm5bvv2pd3m72z2ilj26pa08c61az253dsgfl24vpf2ijywvjx")
80 (15 "0pm0px758w4i23s55wajcv6lqfiym7zgxvq0pxf6vclkv8nxy5x5")
81 (16 "0vdha332km2iwx8g2ld15jy7d24cbplzgr1531dpzylr9ajxglgz")))
a2a9bba4 82
c1fe82d5
LC
83(define (download-patches store count)
84 "Download COUNT Bash patches into store. Return a list of
85number/base32-hash tuples, directly usable in the 'patch-series' form."
86 (unfold (cut > <> count)
87 (lambda (number)
88 (let* ((patch (download-to-store store (patch-url number)))
89 (sig (download-to-store store
90 (string-append (patch-url number)
91 ".sig"))))
f94f9d67 92 (unless (eq? 'valid-signature (gnupg-verify* sig patch))
c1fe82d5
LC
93 (error "failed to verify signature" patch))
94
95 (list number
96 (bytevector->nix-base32-string
97 (call-with-input-file patch port-sha256)))))
98 1+
99 1))
c44899a2
LC
100
101(define-public bash
1382bde9 102 (let* ((cppflags (string-join '("-DDEFAULT_PATH_VALUE='\"/no-such-path\"'"
9a97b814
LC
103 "-DSTANDARD_UTILS_PATH='\"/no-such-path\"'"
104 "-DNON_INTERACTIVE_LOGIN_SHELLS"
105 "-DSSH_SOURCE_BASHRC")
106 " "))
107 (configure-flags
108 ``("--with-installed-readline"
109 ,,(string-append "CPPFLAGS=" cppflags)
110 ,(string-append
111 "LDFLAGS=-Wl,-rpath -Wl,"
112 (assoc-ref %build-inputs "readline")
113 "/lib"
114 " -Wl,-rpath -Wl,"
115 (assoc-ref %build-inputs "ncurses")
116 "/lib")))
847ffe88 117 (version "5.0"))
c44899a2
LC
118 (package
119 (name "bash")
c44899a2 120 (source (origin
87f5d366 121 (method url-fetch)
c44899a2 122 (uri (string-append
0db342a5 123 "mirror://gnu/bash/bash-" version ".tar.gz"))
c44899a2
LC
124 (sha256
125 (base32
4aeb42b9
EF
126 "0kgvfwqdcd90waczf4gx39xnrxzijhjrzyzv7s8v4w31qqm0za5l"))
127 (patch-flags '("-p0"))
567cca26
MW
128 (patches (cons (search-patch "bash-linux-pgrp-pipe.patch")
129 %patch-series-5.0))))
4aeb42b9 130 (version (string-append version "." (number->string (length %patch-series-5.0))))
c44899a2 131 (build-system gnu-build-system)
2b34b4b4
LC
132
133 (outputs '("out"
4d28b97c
LC
134 "doc" ;1.7 MiB of HTML and extra files
135 "include")) ;headers used by extensions
c44899a2 136 (inputs `(("readline" ,readline)
2d5d63d7 137 ("ncurses" ,ncurses))) ;TODO: add texinfo
c44899a2 138 (arguments
9a97b814
LC
139 `(;; When cross-compiling, `configure' incorrectly guesses that job
140 ;; control is missing.
141 #:configure-flags ,(if (%current-target-system)
142 `(cons* "bash_cv_job_control_missing=no"
143 ,configure-flags)
144 configure-flags)
c44899a2
LC
145
146 ;; Bash is reportedly not parallel-safe. See, for instance,
147 ;; <http://patches.openembedded.org/patch/32745/> and
a124bbd2 148 ;; <http://git.buildroot.net/buildroot/commit/?h=79e2d802a>.
c44899a2
LC
149 #:parallel-build? #f
150 #:parallel-tests? #f
151
152 ;; XXX: The tests have a lot of hard-coded paths, so disable them
153 ;; for now.
154 #:tests? #f
155
c573f5a5 156 #:modules ((srfi srfi-26)
3dcbb75f
LF
157 (guix build utils)
158 (guix build gnu-build-system))
159
c573f5a5
LC
160 #:phases
161 (modify-phases %standard-phases
162 (add-after 'install 'install-sh-symlink
163 (lambda* (#:key outputs #:allow-other-keys)
164 ;; Add a `sh' -> `bash' link.
165 (let ((out (assoc-ref outputs "out")))
166 (with-directory-excursion (string-append out "/bin")
8809a153
MW
167 (symlink "bash" "sh")
168 #t))))
c573f5a5
LC
169
170 (add-after 'install 'move-development-files
171 (lambda* (#:key outputs #:allow-other-keys)
172 ;; Move 'Makefile.inc' and 'bash.pc' to "include" to avoid
173 ;; circular references among the outputs.
174 (let ((out (assoc-ref outputs "out"))
175 (include (assoc-ref outputs "include"))
176 (lib (cut string-append <> "/lib/bash")))
177 (mkdir-p (lib include))
178 (rename-file (string-append (lib out)
179 "/Makefile.inc")
180 (string-append (lib include)
181 "/Makefile.inc"))
182 (rename-file (string-append out "/lib/pkgconfig")
183 (string-append include
184 "/lib/pkgconfig"))
d9b4cbc2
LC
185
186 ;; Don't capture the absolute file name of 'install' to avoid
187 ;; retaining a dependency on Coreutils.
188 (substitute* (string-append (lib include)
189 "/Makefile.inc")
190 (("^INSTALL =.*")
191 "INSTALL = install -c\n"))
c573f5a5
LC
192 #t))))))
193
194 (native-search-paths
195 (list (search-path-specification ;new in 4.4
196 (variable "BASH_LOADABLES_PATH")
197 (files '("lib/bash")))))
198
f50d2669 199 (synopsis "The GNU Bourne-Again SHell")
c44899a2 200 (description
79c311b8 201 "Bash is the shell, or command-line interpreter, of the GNU system. It
a22dc0c4
LC
202is compatible with the Bourne Shell, but it also integrates useful features
203from the Korn Shell and the C Shell and new improvements of its own. It
79c311b8 204allows command-line editing, unlimited command history, shell functions and
a22dc0c4
LC
205aliases, and job control while still allowing most sh scripts to be run
206without modification.")
4a44e743 207 (license gpl3+)
6fd52309 208 (home-page "https://www.gnu.org/software/bash/"))))
450fb5a6 209
f24931d8 210(define-public bash-minimal
450fb5a6
LC
211 ;; A stripped-down Bash for non-interactive use.
212 (package (inherit bash)
f24931d8 213 (name "bash-minimal")
450fb5a6 214 (inputs '()) ; no readline, no curses
c86447f4
LC
215
216 ;; No "include" output because there's no support for loadable modules.
217 (outputs (delete "include" (package-outputs bash)))
218
450fb5a6 219 (arguments
4cc80c94
LC
220 (substitute-keyword-arguments (package-arguments bash)
221 ((#:modules _ '())
222 '((guix build gnu-build-system)
223 (guix build utils)
224 (srfi srfi-1)
225 (srfi srfi-26)))
226 ((#:configure-flags flags '())
227 `(list "--without-bash-malloc"
228 "--disable-readline"
229 "--disable-history"
230 "--disable-help-builtin"
231 "--disable-progcomp"
232 "--disable-net-redirections"
233 "--disable-nls"
234
235 ;; Pretend 'dlopen' is missing so we don't build loadable
236 ;; modules and related code.
237 "ac_cv_func_dlopen=no"
238
239 ,@(if (%current-target-system)
240 '("bash_cv_job_control_missing=no"
241 "bash_cv_getcwd_malloc=yes")
242 '())))
243 ((#:phases phases)
244 `(modify-phases ,phases
245 ;; No loadable modules.
246 (delete 'move-development-files)))))))
928d62f2 247
6c7f44ef
LC
248(define-public static-bash
249 ;; Statically-linked Bash that contains nothing but the 'bash' binary and
250 ;; 'sh' symlink, without any reference.
f24931d8 251 (let ((bash (static-package bash-minimal)))
6c7f44ef
LC
252 (package
253 (inherit bash)
254 (name "bash-static")
255 (arguments
256 (substitute-keyword-arguments
257 `(#:allowed-references ("out") ,@(package-arguments bash))
258 ((#:phases phases)
a7a1cf29
LC
259 `(modify-phases ,phases
260 (add-after 'strip 'remove-everything-but-the-binary
261 (lambda* (#:key outputs #:allow-other-keys)
262 (let* ((out (assoc-ref outputs "out"))
263 (bin (string-append out "/bin")))
264 (remove-store-references (string-append bin "/bash"))
265 (delete-file (string-append bin "/bashbug"))
266 (delete-file-recursively (string-append out "/share"))
e543c8a2 267 #t))))))))))
6c7f44ef 268
928d62f2
LC
269(define-public bash-completion
270 (package
271 (name "bash-completion")
504be7db 272 (version "2.8")
928d62f2
LC
273 (source (origin
274 (method url-fetch)
275 (uri (string-append
ba6d25f3
276 "https://github.com/scop/" name "/releases/download/"
277 version "/" name "-" version ".tar.xz"))
928d62f2
LC
278 (sha256
279 (base32
504be7db 280 "0kgmflrr1ga9wfk770vmakna3nj46ylb5ky9ipd0v2k9ymq5a7y0"))
16629c8a 281 (patches
fc1adab1 282 (search-patches "bash-completion-directories.patch"))))
928d62f2 283 (build-system gnu-build-system)
b16b7790
LC
284 (native-inputs `(("util-linux" ,util-linux)))
285 (arguments
aa67d3c5
286 `(#:phases (modify-phases %standard-phases
287 (add-after
288 'install 'remove-redundant-completions
d8dbfbce
MO
289 (lambda* (#:key
290 inputs native-inputs
291 outputs #:allow-other-keys)
aa67d3c5
292 ;; Util-linux comes with a bunch of completion files for
293 ;; its own commands which are more sophisticated and
294 ;; up-to-date than those of bash-completion. Remove those
295 ;; from bash-completion.
296 (let* ((out (assoc-ref outputs "out"))
d8dbfbce
MO
297 (util-linux (assoc-ref (or native-inputs inputs)
298 "util-linux"))
aa67d3c5
299 (completions (string-append out
300 "/share/bash-completion"
301 "/completions"))
302 (already (find-files
303 (string-append
304 util-linux
305 "/etc/bash_completion.d"))))
306 (with-directory-excursion completions
307 (for-each (lambda (file)
308 (when (file-exists? file)
309 (delete-file file)))
310 (map basename already)))
311 #t))))))
928d62f2
LC
312 (synopsis "Bash completions for common commands")
313 (description
314 "This package provides extensions that allow Bash to provide adapted
315completion for many common commands.")
b07e0863 316 (home-page "https://github.com/scop/bash-completion")
928d62f2 317 (license gpl2+)))
2d4422d5
RJ
318
319(define-public bash-tap
320 (package
321 (name "bash-tap")
322 (version "1.0.2")
38e10e08
TGR
323 (source
324 (origin
325 (method git-fetch)
326 (uri (git-reference
327 (url "https://github.com/illusori/bash-tap.git")
328 (commit version)))
329 (file-name (git-file-name name version))
330 (sha256
331 (base32 "13zz9h6bhhnk3hiwhlpafrnf2isws249h3fz785dcgymk02arz9c"))))
2d4422d5
RJ
332 ;; There is no compilation process to use this package, however, the bash
333 ;; scripts installed by this package start with "#!/bin/bash". To fix
334 ;; these lines, we use the patch-shebangs of the GNU build system. The
335 ;; project does not use a Makefile.
336 (build-system gnu-build-system)
337 (arguments
338 `(#:tests? #f ; There is no test suite.
339 #:phases
340 (modify-phases %standard-phases
341 ;; Because there are no configure scripts or Makefile, we can
342 ;; remove these phases.
343 (delete 'configure)
344 (delete 'build)
345 ;; The installation involves manually copying the files to a location.
346 ;; To make them easily accessible by setting PATH, we add the scripts
347 ;; to the "bin" folder.
348 (replace 'install
349 (lambda* (#:key outputs #:allow-other-keys)
350 (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
351 (install-file "bash-tap" bin)
352 (install-file "bash-tap-bootstrap" bin)
353 (install-file "bash-tap-mock" bin)))))))
a8a8a3df 354 (home-page "https://www.illusori.co.uk/projects/bash-tap/")
2d4422d5
RJ
355 (synopsis "Bash port of a Test::More/Test::Builder-style TAP-compliant
356test library")
357 (description "Bash TAP is a TAP-compliant Test::More-style testing library
358for Bash shell scripts and functions. Along with the Test::More-style testing
359helpers it provides helper functions for mocking commands and in-process output
360capturing.")
361 (license expat)))