guix-package.el 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. ;;; guix-package.el --- Guix packages -*- lexical-binding: t -*-
  2. ;; Copyright © 2014–2017 Alex Kost <alezost@gmail.com>
  3. ;; This file is part of Emacs-Guix.
  4. ;; Emacs-Guix is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;;
  9. ;; Emacs-Guix is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with Emacs-Guix. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; This file provides a general code related to Guix package.
  18. ;;; Code:
  19. (require 'cl-lib)
  20. (require 'guix-read)
  21. (require 'guix-repl)
  22. (require 'guix-guile)
  23. (require 'guix-misc)
  24. (defun guix-package-name-specification (name version &optional output)
  25. "Return Guix package specification by its NAME, VERSION and OUTPUT."
  26. (concat name "@" version
  27. (when output (concat ":" output))))
  28. (defun guix-package-id-and-output-by-output-id (output-id)
  29. "Return a list (PACKAGE-ID OUTPUT) by OUTPUT-ID."
  30. (cl-multiple-value-bind (package-id-str output)
  31. (split-string output-id ":")
  32. (let ((package-id (string-to-number package-id-str)))
  33. (list (if (= 0 package-id) package-id-str package-id)
  34. output))))
  35. (defun guix-package-build-log-file (id)
  36. "Return build log file name of a package defined by ID."
  37. (guix-eval-read
  38. (guix-make-guile-expression 'package-build-log-file id)))
  39. (declare-function guix-build-log-find-file "guix-build-log" (file))
  40. (defun guix-package-find-build-log (id)
  41. "Show build log of a package defined by ID."
  42. (require 'guix-build-log)
  43. (let ((file (guix-package-build-log-file id)))
  44. (if file
  45. (guix-build-log-find-file file)
  46. (message "Couldn't find the package build log."))))
  47. (defun guix-package-source-file-name (package-id)
  48. "Return a store file name to a source of a package PACKAGE-ID."
  49. (message "Calculating the source derivation ...")
  50. (guix-eval-read
  51. (guix-make-guile-expression
  52. 'package-source-file-name package-id)))
  53. (defun guix-package-store-path (package-id)
  54. "Return a list of store directories of outputs of package PACKAGE-ID."
  55. (message "Calculating the package derivation ...")
  56. (guix-eval-read
  57. (guix-make-guile-expression
  58. 'package-store-path package-id)))
  59. (defvar guix-after-source-download-hook nil
  60. "Hook run after successful performing a 'source-download' operation.")
  61. (defun guix-package-source-build-derivation (package-id &optional prompt)
  62. "Build source derivation of a package PACKAGE-ID.
  63. Ask a user with PROMPT for continuing an operation."
  64. (when (or (not guix-operation-confirm)
  65. (guix-operation-prompt (or prompt
  66. "Build the source derivation?")))
  67. (guix-eval-in-repl
  68. (guix-make-guile-expression
  69. 'package-source-build-derivation
  70. package-id
  71. :use-substitutes? (or guix-use-substitutes 'f)
  72. :dry-run? (or guix-dry-run 'f))
  73. nil 'source-download)))
  74. (defun guix-build-package (package-id &optional prompt)
  75. "Build package with PACKAGE-ID.
  76. Ask a user with PROMPT for continuing the build operation."
  77. (when (or (not guix-operation-confirm)
  78. (guix-operation-prompt (or prompt "Build package?")))
  79. (guix-eval-in-repl
  80. (format (concat "(build-package* (package-by-id %d)"
  81. " #:use-substitutes? %s"
  82. " #:dry-run? %s)")
  83. package-id
  84. (guix-guile-boolean guix-use-substitutes)
  85. (guix-guile-boolean guix-dry-run)))))
  86. (defun guix-read-package-size-type ()
  87. "Prompt a user for a package size type."
  88. (intern
  89. (completing-read "Size type (\"text\" or \"image\"): "
  90. '("text" "image")
  91. nil t nil nil "text")))
  92. ;;;###autoload
  93. (defun guix-package-size (package-or-file &optional type)
  94. "Show size of PACKAGE-OR-FILE.
  95. PACKAGE-OR-FILE should be either a package name or a store file name.
  96. TYPE should be on of the following symbols: `text' (default) or `image'.
  97. Interactively, prompt for a package name and size TYPE."
  98. (interactive
  99. (list (guix-read-package-name)
  100. (guix-read-package-size-type)))
  101. (cl-case (or type 'text)
  102. (text (guix-eval-in-repl
  103. (guix-make-guile-expression
  104. 'guix-command "size" package-or-file)))
  105. (image (let ((map-file (guix-png-file-name)))
  106. (guix-command-output
  107. (list "size"
  108. (concat "--map-file=" map-file)
  109. package-or-file))
  110. (guix-find-file map-file)))
  111. (t (error "Unknown size type (should be `image' or `text'): %S"
  112. type))))
  113. ;;;###autoload
  114. (defun guix-lint (package &optional checkers)
  115. "Lint PACKAGE using CHECKERS.
  116. PACKAGE can be either a package name or a package ID.
  117. CHECKERS is a list of checker names; if nil, use all checkers.
  118. Interactively, prompt for PACKAGE name and use all checkers.
  119. With prefix argument, also prompt for checkers (should be comma
  120. separated).
  121. See Info node `(guix) Invoking guix lint' for details about linting."
  122. (interactive
  123. (list (guix-read-package-name)
  124. (and current-prefix-arg
  125. (guix-read-lint-checker-names))))
  126. (guix-eval-in-repl
  127. (guix-make-guile-expression
  128. 'lint-package package checkers)))
  129. ;;;###autoload
  130. (defalias 'guix-package-lint 'guix-lint)
  131. (provide 'guix-package)
  132. ;;; guix-package.el ends here