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