Commit | Line | Data |
---|---|---|
233e7676 | 1 | ;;; GNU Guix --- Functional package management for GNU |
ce0be567 | 2 | ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2020 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> |
1e8b8dcf | 6 | ;;; Copyright © 2018, 2019, 2020 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) |
5a88d3df | 27 | #:use-module (gnu packages base) |
6c5b56f9 | 28 | #:use-module (gnu packages bootstrap) |
1ffa7090 LC |
29 | #:use-module (gnu packages ncurses) |
30 | #:use-module (gnu packages readline) | |
2d5d63d7 | 31 | #:use-module (gnu packages bison) |
b16b7790 | 32 | #:use-module (gnu packages linux) |
5a88d3df | 33 | #:use-module (gnu packages guile) |
c44899a2 | 34 | #:use-module (guix packages) |
87f5d366 | 35 | #:use-module (guix download) |
38e10e08 | 36 | #:use-module (guix git-download) |
c44899a2 | 37 | #:use-module (guix utils) |
50b8a527 LC |
38 | #:use-module (guix gexp) |
39 | #:use-module (guix monads) | |
40 | #:use-module (guix store) | |
c1fe82d5 | 41 | #:use-module (guix build-system gnu) |
5a88d3df | 42 | #:use-module (guix build-system trivial) |
c1fe82d5 | 43 | #:autoload (guix gnupg) (gnupg-verify*) |
c1fe82d5 | 44 | #:autoload (guix base32) (bytevector->nix-base32-string) |
50ea3135 LC |
45 | |
46 | ;; See <https://bugs.gnu.org/41457> for why not #:autoload here. | |
47 | #:use-module ((gcrypt hash) #:select (port-sha256)) | |
48 | ||
c1fe82d5 LC |
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." | |
847ffe88 | 55 | (format #f "mirror://gnu/bash/bash-5.0-patches/bash50-~3,'0d" seqno)) |
c1fe82d5 | 56 | |
ce0be567 LC |
57 | (define (bash-patch seqno sha256-bv) |
58 | "Return the origin of Bash patch SEQNO, with expected hash SHA256-BV." | |
c1fe82d5 LC |
59 | (origin |
60 | (method url-fetch) | |
61 | (uri (patch-url seqno)) | |
ce0be567 | 62 | (sha256 sha256-bv))) |
c1fe82d5 LC |
63 | |
64 | (define-syntax-rule (patch-series (seqno hash) ...) | |
65 | (list (bash-patch seqno (base32 hash)) | |
66 | ...)) | |
67 | ||
847ffe88 EF |
68 | (define %patch-series-5.0 |
69 | ;; This is the current patches series for 5.0, generated using | |
c1fe82d5 | 70 | ;; 'download-patches' below. |
feefbb09 | 71 | (patch-series |
4aeb42b9 | 72 | (1 "12bjfdy6bg8nhyw27bdgxn7h4paylx8d927skfmi9pxd1wgrxzpj") |
13f3893b EF |
73 | (2 "01w7yrzmz10mw06ys0546vhl7isv2v402ziyvfd7k67588spvs47") |
74 | (3 "0ny81ridp5n0j69hb8ixrc7dmxybby54jbsz5hikly8kgg1wvssf") | |
75 | (4 "021gqqvgydixkrmqss64b6srfdlkvnx88lyfzpxfrn5d6bc7li0l") | |
76 | (5 "0xl2kyzm84nlyklrqzkn73ixabhzfhn9x91lzcmis89cppclvxav") | |
77 | (6 "0844749ixk1z60437nkznzms1f0nzh9an62kj7sny6r0zyk2k1fn") | |
3f0f0d61 EF |
78 | (7 "16xg37gp1b8zlj5969w8mcrparwqlcbj9695vn3qhgb7wdz1xd0p") |
79 | (8 "1qyp19krjh8zxvb0jgwmyjz40djslwcf4xi7kc1ab0iaca44bipf") | |
80 | (9 "00yrjjqd95s81b21qq3ba1y7h879q8jaajlkjggc6grhcwbs4g7d") | |
81 | (10 "04ca5bjv456v538mkspzvn4xb2zdphh31r4fpvfm9p5my0jw7yyn") | |
acb92774 MB |
82 | (11 "1sklyixvsv8993kxzs0jigacpdchjrq7jv5xpdx7kbqyp4rf6k9c") |
83 | (12 "0cz21qg2gbr40lfgza7g02bqi2qknwqgxnq459pjj640d0cywhr9") | |
84 | (13 "16h9nwz3yzwj7fnxvlidjymdc4yr30h818433gh9j1x3in6igmzm") | |
85 | (14 "12gm5bvv2pd3m72z2ilj26pa08c61az253dsgfl24vpf2ijywvjx") | |
86 | (15 "0pm0px758w4i23s55wajcv6lqfiym7zgxvq0pxf6vclkv8nxy5x5") | |
87 | (16 "0vdha332km2iwx8g2ld15jy7d24cbplzgr1531dpzylr9ajxglgz"))) | |
a2a9bba4 | 88 | |
c1fe82d5 LC |
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")))) | |
f94f9d67 | 98 | (unless (eq? 'valid-signature (gnupg-verify* sig patch)) |
c1fe82d5 LC |
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)) | |
c44899a2 LC |
106 | |
107 | (define-public bash | |
1382bde9 | 108 | (let* ((cppflags (string-join '("-DDEFAULT_PATH_VALUE='\"/no-such-path\"'" |
9a97b814 LC |
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"))) | |
847ffe88 | 123 | (version "5.0")) |
c44899a2 LC |
124 | (package |
125 | (name "bash") | |
c44899a2 | 126 | (source (origin |
87f5d366 | 127 | (method url-fetch) |
c44899a2 | 128 | (uri (string-append |
0db342a5 | 129 | "mirror://gnu/bash/bash-" version ".tar.gz")) |
c44899a2 LC |
130 | (sha256 |
131 | (base32 | |
4aeb42b9 EF |
132 | "0kgvfwqdcd90waczf4gx39xnrxzijhjrzyzv7s8v4w31qqm0za5l")) |
133 | (patch-flags '("-p0")) | |
567cca26 MW |
134 | (patches (cons (search-patch "bash-linux-pgrp-pipe.patch") |
135 | %patch-series-5.0)))) | |
4aeb42b9 | 136 | (version (string-append version "." (number->string (length %patch-series-5.0)))) |
c44899a2 | 137 | (build-system gnu-build-system) |
2b34b4b4 LC |
138 | |
139 | (outputs '("out" | |
4d28b97c LC |
140 | "doc" ;1.7 MiB of HTML and extra files |
141 | "include")) ;headers used by extensions | |
c44899a2 | 142 | (inputs `(("readline" ,readline) |
2d5d63d7 | 143 | ("ncurses" ,ncurses))) ;TODO: add texinfo |
c44899a2 | 144 | (arguments |
9a97b814 LC |
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) | |
c44899a2 LC |
151 | |
152 | ;; Bash is reportedly not parallel-safe. See, for instance, | |
153 | ;; <http://patches.openembedded.org/patch/32745/> and | |
a124bbd2 | 154 | ;; <http://git.buildroot.net/buildroot/commit/?h=79e2d802a>. |
c44899a2 LC |
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 | ||
c573f5a5 | 162 | #:modules ((srfi srfi-26) |
3dcbb75f LF |
163 | (guix build utils) |
164 | (guix build gnu-build-system)) | |
165 | ||
c573f5a5 LC |
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") | |
8809a153 MW |
173 | (symlink "bash" "sh") |
174 | #t)))) | |
c573f5a5 LC |
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")) | |
d9b4cbc2 LC |
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")) | |
c573f5a5 LC |
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 | ||
f50d2669 | 205 | (synopsis "The GNU Bourne-Again SHell") |
c44899a2 | 206 | (description |
79c311b8 | 207 | "Bash is the shell, or command-line interpreter, of the GNU system. It |
a22dc0c4 LC |
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 | |
79c311b8 | 210 | allows command-line editing, unlimited command history, shell functions and |
a22dc0c4 LC |
211 | aliases, and job control while still allowing most sh scripts to be run |
212 | without modification.") | |
4a44e743 | 213 | (license gpl3+) |
6fd52309 | 214 | (home-page "https://www.gnu.org/software/bash/")))) |
450fb5a6 | 215 | |
f24931d8 | 216 | (define-public bash-minimal |
450fb5a6 LC |
217 | ;; A stripped-down Bash for non-interactive use. |
218 | (package (inherit bash) | |
f24931d8 | 219 | (name "bash-minimal") |
450fb5a6 | 220 | (inputs '()) ; no readline, no curses |
c86447f4 LC |
221 | |
222 | ;; No "include" output because there's no support for loadable modules. | |
223 | (outputs (delete "include" (package-outputs bash))) | |
224 | ||
450fb5a6 | 225 | (arguments |
4cc80c94 LC |
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))))))) | |
928d62f2 | 253 | |
6c7f44ef LC |
254 | (define-public static-bash |
255 | ;; Statically-linked Bash that contains nothing but the 'bash' binary and | |
256 | ;; 'sh' symlink, without any reference. | |
f24931d8 | 257 | (let ((bash (static-package bash-minimal))) |
6c7f44ef LC |
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) | |
a7a1cf29 LC |
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")) | |
e543c8a2 | 273 | #t)))))))))) |
6c7f44ef | 274 | |
928d62f2 LC |
275 | (define-public bash-completion |
276 | (package | |
277 | (name "bash-completion") | |
504be7db | 278 | (version "2.8") |
928d62f2 LC |
279 | (source (origin |
280 | (method url-fetch) | |
281 | (uri (string-append | |
ba6d25f3 TČ |
282 | "https://github.com/scop/" name "/releases/download/" |
283 | version "/" name "-" version ".tar.xz")) | |
928d62f2 LC |
284 | (sha256 |
285 | (base32 | |
504be7db | 286 | "0kgmflrr1ga9wfk770vmakna3nj46ylb5ky9ipd0v2k9ymq5a7y0")) |
16629c8a | 287 | (patches |
fc1adab1 | 288 | (search-patches "bash-completion-directories.patch")))) |
928d62f2 | 289 | (build-system gnu-build-system) |
b16b7790 LC |
290 | (native-inputs `(("util-linux" ,util-linux))) |
291 | (arguments | |
aa67d3c5 TČ |
292 | `(#:phases (modify-phases %standard-phases |
293 | (add-after | |
294 | 'install 'remove-redundant-completions | |
d8dbfbce MO |
295 | (lambda* (#:key |
296 | inputs native-inputs | |
297 | outputs #:allow-other-keys) | |
aa67d3c5 TČ |
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")) | |
d8dbfbce MO |
303 | (util-linux (assoc-ref (or native-inputs inputs) |
304 | "util-linux")) | |
aa67d3c5 TČ |
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)))))) | |
928d62f2 LC |
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.") | |
b07e0863 | 322 | (home-page "https://github.com/scop/bash-completion") |
928d62f2 | 323 | (license gpl2+))) |
2d4422d5 RJ |
324 | |
325 | (define-public bash-tap | |
326 | (package | |
327 | (name "bash-tap") | |
328 | (version "1.0.2") | |
38e10e08 TGR |
329 | (source |
330 | (origin | |
331 | (method git-fetch) | |
332 | (uri (git-reference | |
b0e7b699 | 333 | (url "https://github.com/illusori/bash-tap") |
38e10e08 TGR |
334 | (commit version))) |
335 | (file-name (git-file-name name version)) | |
336 | (sha256 | |
337 | (base32 "13zz9h6bhhnk3hiwhlpafrnf2isws249h3fz785dcgymk02arz9c")))) | |
2d4422d5 RJ |
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))))))) | |
a8a8a3df | 360 | (home-page "https://www.illusori.co.uk/projects/bash-tap/") |
2d4422d5 RJ |
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))) | |
5a88d3df OP |
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 | |
b0e7b699 | 376 | (url "https://github.com/bats-core/bats-core") |
5a88d3df OP |
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") | |
1e8b8dcf TGR |
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.") | |
5a88d3df | 417 | (license expat))) |