You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

359 lines
15 KiB

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