bash.scm 15 KB

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