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 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2015, 2017 Leo Famulari <leo@famulari.name>
5 ;;; Copyright © 2016, 2017 Efraim Flashner <efraim@flashner.co.il>
6 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
8 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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 (guix 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))
45 (define (patch-url seqno)
46 "Return the URL of Bash patch number SEQNO."
47 (format #f "mirror://gnu/bash/bash-4.4-patches/bash44-~3,'0d" seqno))
49 (define (bash-patch seqno sha256)
50 "Return the origin of Bash patch SEQNO, with expected hash SHA256"
53 (uri (patch-url seqno))
56 (define-syntax-rule (patch-series (seqno hash) ...)
57 (list (bash-patch seqno (base32 hash))
60 (define %patch-series-4.4
61 ;; This is the current patches series for 4.4, generated using
62 ;; 'download-patches' below.
64 (1 "03vzy7qwjdd5qvl3ydg99naazas2qmyd0yhnrflgjbbm64axja1y")
65 (2 "0lrwq6vyqism3yqv9s7kzaf3dsl4q5w9r5svcqz279qp7qca083h")
66 (3 "1chqww2rj6g42b8s60q5zlzy0jzp684jkpsbrbfy1vzxja8mmpsi")
67 (4 "1cy8abf96hkrjhw921ndr0shlcnc52bg45rn6xri4v5clhq0l25d")
68 (5 "0a8515kyk4zsgmvlqvlganjfr7pq0j6kzpr4d6xx02kpbdr4n7i2")
69 (6 "1f24wgqngmj2mrj9yibwvc2zvlmn5xi53mnw777g3l40c4m2x3ka")
70 (7 "1bzdsnqaf05gdbqpsixhan8vygjxpcxlz1dd8d9f5jdznw3wq76y") ;CVE-2017-5932
71 (8 "1firw915mjm03hbbw9a70ch3cpgrgnvqjpllgdnn6csr8q04f546")
72 (9 "0g1l56kvw61rpw7dqa9fcl9llkl693h73g631hrhxlm030ddssqb")
73 (10 "01lfhrkdsdkdz8ypzapr614ras23x7ckjnr60aa5bzkaqprccrc4")
74 (11 "038p7mhnq9m65g505hi3827jkf9f35nd1cy00w8mwafpyxp44mnx")
75 (12 "0gh6lbb1rwpk44pvbamm6vzdfi50xnwkqd9v7s8cjwk3pz973hps")))
77 (define (download-patches store count)
78 "Download COUNT Bash patches into store. Return a list of
79 number/base32-hash tuples, directly usable in the 'patch-series' form."
80 (unfold (cut > <> count)
82 (let* ((patch (download-to-store store (patch-url number)))
83 (sig (download-to-store store
84 (string-append (patch-url number)
86 (unless (gnupg-verify* sig patch)
87 (error "failed to verify signature" patch))
90 (bytevector->nix-base32-string
91 (call-with-input-file patch port-sha256)))))
96 (let* ((cppflags (string-join '("-DSYS_BASHRC='\"/etc/bashrc\"'"
97 "-DSYS_BASH_LOGOUT='\"/etc/bash_logout\"'"
98 "-DDEFAULT_PATH_VALUE='\"/no-such-path\"'"
99 "-DSTANDARD_UTILS_PATH='\"/no-such-path\"'"
100 "-DNON_INTERACTIVE_LOGIN_SHELLS"
101 "-DSSH_SOURCE_BASHRC")
104 ``("--with-installed-readline"
105 ,,(string-append "CPPFLAGS=" cppflags)
107 "LDFLAGS=-Wl,-rpath -Wl,"
108 (assoc-ref %build-inputs "readline")
111 (assoc-ref %build-inputs "ncurses")
119 "mirror://gnu/bash/bash-" version ".tar.gz"))
122 "1jyz6snd63xjn6skk7za6psgidsd53k05cr3lksqybi0q6936syq"))
123 (patch-flags '("-p0"))
124 (patches %patch-series-4.4)))
125 (version (string-append version "."
126 (number->string (length %patch-series-4.4))))
127 (build-system gnu-build-system)
130 "doc" ;1.7 MiB of HTML and extra files
131 "include")) ;headers used by extensions
132 (inputs `(("readline" ,readline)
133 ("ncurses" ,ncurses))) ;TODO: add texinfo
135 `(;; When cross-compiling, `configure' incorrectly guesses that job
136 ;; control is missing.
137 #:configure-flags ,(if (%current-target-system)
138 `(cons* "bash_cv_job_control_missing=no"
142 ;; Bash is reportedly not parallel-safe. See, for instance,
143 ;; <http://patches.openembedded.org/patch/32745/> and
144 ;; <http://git.buildroot.net/buildroot/commit/?h=79e2d802a>.
148 ;; XXX: The tests have a lot of hard-coded paths, so disable them
152 #:modules ((srfi srfi-26)
154 (guix build gnu-build-system))
157 (modify-phases %standard-phases
158 (add-after 'install 'install-sh-symlink
159 (lambda* (#:key outputs #:allow-other-keys)
160 ;; Add a `sh' -> `bash' link.
161 (let ((out (assoc-ref outputs "out")))
162 (with-directory-excursion (string-append out "/bin")
163 (symlink "bash" "sh")))))
165 (add-after 'install 'move-development-files
166 (lambda* (#:key outputs #:allow-other-keys)
167 ;; Move 'Makefile.inc' and 'bash.pc' to "include" to avoid
168 ;; circular references among the outputs.
169 (let ((out (assoc-ref outputs "out"))
170 (include (assoc-ref outputs "include"))
171 (lib (cut string-append <> "/lib/bash")))
172 (mkdir-p (lib include))
173 (rename-file (string-append (lib out)
175 (string-append (lib include)
177 (rename-file (string-append out "/lib/pkgconfig")
178 (string-append include
181 ;; Don't capture the absolute file name of 'install' to avoid
182 ;; retaining a dependency on Coreutils.
183 (substitute* (string-append (lib include)
186 "INSTALL = install -c\n"))
190 (list (search-path-specification ;new in 4.4
191 (variable "BASH_LOADABLES_PATH")
192 (files '("lib/bash")))))
194 (synopsis "The GNU Bourne-Again SHell")
196 "Bash is the shell, or command-line interpreter, of the GNU system. It
197 is compatible with the Bourne Shell, but it also integrates useful features
198 from the Korn Shell and the C Shell and new improvements of its own. It
199 allows command-line editing, unlimited command history, shell functions and
200 aliases, and job control while still allowing most sh scripts to be run
201 without modification.")
203 (home-page "https://www.gnu.org/software/bash/"))))
205 (define-public bash-minimal
206 ;; A stripped-down Bash for non-interactive use.
207 (package (inherit bash)
208 (name "bash-minimal")
209 (inputs '()) ; no readline, no curses
211 ;; No "include" output because there's no support for loadable modules.
212 (outputs (delete "include" (package-outputs bash)))
215 (substitute-keyword-arguments (package-arguments bash)
217 '((guix build gnu-build-system)
221 ((#:configure-flags flags '())
222 `(list "--without-bash-malloc"
225 "--disable-help-builtin"
227 "--disable-net-redirections"
230 ;; Pretend 'dlopen' is missing so we don't build loadable
231 ;; modules and related code.
232 "ac_cv_func_dlopen=no"
234 ,@(if (%current-target-system)
235 '("bash_cv_job_control_missing=no"
236 "bash_cv_getcwd_malloc=yes")
239 `(modify-phases ,phases
240 ;; No loadable modules.
241 (delete 'move-development-files)))))))
243 (define-public static-bash
244 ;; Statically-linked Bash that contains nothing but the 'bash' binary and
245 ;; 'sh' symlink, without any reference.
246 (let ((bash (static-package bash-minimal)))
251 (substitute-keyword-arguments
252 `(#:allowed-references ("out") ,@(package-arguments bash))
254 `(modify-phases ,phases
255 (add-after 'strip 'remove-everything-but-the-binary
256 (lambda* (#:key outputs #:allow-other-keys)
257 (let* ((out (assoc-ref outputs "out"))
258 (bin (string-append out "/bin")))
259 (remove-store-references (string-append bin "/bash"))
260 (delete-file (string-append bin "/bashbug"))
261 (delete-file-recursively (string-append out "/share"))
264 (define-public bash-completion
266 (name "bash-completion")
271 "https://github.com/scop/" name "/releases/download/"
272 version "/" name "-" version ".tar.xz"))
275 "0kgmflrr1ga9wfk770vmakna3nj46ylb5ky9ipd0v2k9ymq5a7y0"))
277 (search-patches "bash-completion-directories.patch"))))
278 (build-system gnu-build-system)
279 (native-inputs `(("util-linux" ,util-linux)))
281 `(#:phases (modify-phases %standard-phases
283 'install 'remove-redundant-completions
284 (lambda* (#:key inputs outputs #:allow-other-keys)
285 ;; Util-linux comes with a bunch of completion files for
286 ;; its own commands which are more sophisticated and
287 ;; up-to-date than those of bash-completion. Remove those
288 ;; from bash-completion.
289 (let* ((out (assoc-ref outputs "out"))
290 (util-linux (assoc-ref inputs "util-linux"))
291 (completions (string-append out
292 "/share/bash-completion"
297 "/etc/bash_completion.d"))))
298 (with-directory-excursion completions
299 (for-each (lambda (file)
300 (when (file-exists? file)
302 (map basename already)))
304 (synopsis "Bash completions for common commands")
306 "This package provides extensions that allow Bash to provide adapted
307 completion for many common commands.")
308 (home-page "https://github.com/scop/bash-completion")
311 (define-public bash-tap
317 (uri (string-append "https://github.com/illusori/bash-tap/"
318 "archive/" version ".tar.gz"))
319 (file-name (string-append name "-" version ".tar.gz"))
322 "0qs1qi38bl3ns4mpagcawv618dsk2q1lgrbddgvs0wl3ia12cyz5"))))
323 ;; There is no compilation process to use this package, however, the bash
324 ;; scripts installed by this package start with "#!/bin/bash". To fix
325 ;; these lines, we use the patch-shebangs of the GNU build system. The
326 ;; project does not use a Makefile.
327 (build-system gnu-build-system)
329 `(#:tests? #f ; There is no test suite.
331 (modify-phases %standard-phases
332 ;; Because there are no configure scripts or Makefile, we can
333 ;; remove these phases.
336 ;; The installation involves manually copying the files to a location.
337 ;; To make them easily accessible by setting PATH, we add the scripts
338 ;; to the "bin" folder.
340 (lambda* (#:key outputs #:allow-other-keys)
341 (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
342 (install-file "bash-tap" bin)
343 (install-file "bash-tap-bootstrap" bin)
344 (install-file "bash-tap-mock" bin)))))))
345 (home-page "http://www.illusori.co.uk/projects/bash-tap/")
346 (synopsis "Bash port of a Test::More/Test::Builder-style TAP-compliant
348 (description "Bash TAP is a TAP-compliant Test::More-style testing library
349 for Bash shell scripts and functions. Along with the Test::More-style testing
350 helpers it provides helper functions for mocking commands and in-process output