guix-ui-package.el 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. ;;; guix-ui-package.el --- Interface for displaying 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 an interface for displaying packages and outputs
  18. ;; in 'list' and 'info' buffers, and commands for working with them.
  19. ;;; Code:
  20. (require 'cl-lib)
  21. (require 'dash)
  22. (require 'bui)
  23. (require 'guix nil t)
  24. (require 'guix-ui)
  25. (require 'guix-misc)
  26. (require 'guix-repl)
  27. (require 'guix-guile)
  28. (require 'guix-utils)
  29. (require 'guix-hydra)
  30. (require 'guix-hydra-build)
  31. (require 'guix-read)
  32. (require 'guix-license)
  33. (require 'guix-location)
  34. (require 'guix-package)
  35. (require 'guix-profiles)
  36. (guix-ui-define-entry-type package)
  37. (guix-ui-define-entry-type output)
  38. (defcustom guix-package-list-type 'output
  39. "Define how to display packages in 'list' buffer.
  40. Should be a symbol `package' or `output' (if `output', display each
  41. output on a separate line; if `package', display each package on
  42. a separate line)."
  43. :type '(choice (const :tag "List of packages" package)
  44. (const :tag "List of outputs" output))
  45. :group 'guix-package)
  46. (defun guix-package-list-type ()
  47. "Return BUI list entry-type by `guix-package-list-type' variable."
  48. (guix-make-symbol guix-package-list-type))
  49. ;; To avoid compilation warning: this variable is actually defined later
  50. ;; along with the rest "package-list" interface stuff.
  51. (defvar guix-package-list-show-single)
  52. (defun guix-package-get-display (profile search-type &rest search-values)
  53. "Search for packages/outputs and show results.
  54. If PROFILE is nil, use `guix-current-profile'.
  55. See `guix-ui-get-entries' for the meaning of SEARCH-TYPE and
  56. SEARCH-VALUES.
  57. Results are displayed in the list buffer, unless a single package
  58. is found and `guix-package-list-show-single' is nil."
  59. (let* ((args (cl-list* (or profile guix-current-profile)
  60. search-type search-values))
  61. (entries (bui-get-entries (guix-package-list-type) 'list args)))
  62. (if (or guix-package-list-show-single
  63. (null entries)
  64. (cdr entries))
  65. (bui-display-entries entries (guix-package-list-type) 'list args)
  66. (bui-get-display-entries 'guix-package 'info args))))
  67. (defun guix-package-entry->name-specification (entry &optional output)
  68. "Return name specification of the package ENTRY and OUTPUT."
  69. (guix-package-name-specification
  70. (bui-entry-non-void-value entry 'name)
  71. (bui-entry-non-void-value entry 'version)
  72. (or output (bui-entry-non-void-value entry 'output))))
  73. (defun guix-package-entries->name-specifications (entries)
  74. "Return name specifications by the package or output ENTRIES."
  75. (cl-remove-duplicates (mapcar #'guix-package-entry->name-specification
  76. entries)
  77. :test #'string=))
  78. (defun guix-package-entry-installed-outputs (entry)
  79. "Return a list of installed outputs for the package ENTRY."
  80. (--map (bui-entry-non-void-value it 'output)
  81. (bui-entry-non-void-value entry 'installed)))
  82. ;;; Processing package actions
  83. (defvar guix-package-name-width 40
  84. "Width of a package name \"column\".
  85. This variable is used in a buffer to confirm operation.")
  86. (defun guix-process-package-actions (profile actions
  87. &optional operation-buffer)
  88. "Process package ACTIONS on PROFILE.
  89. Each action is a list of the form:
  90. (ACTION-TYPE PACKAGE-SPEC ...)
  91. ACTION-TYPE is one of the following symbols: `install',
  92. `upgrade', `remove'/`delete'.
  93. PACKAGE-SPEC should have the following form: (ID [OUTPUT] ...)."
  94. (let (install upgrade remove)
  95. (mapc (lambda (action)
  96. (let ((action-type (car action))
  97. (specs (cdr action)))
  98. (cl-case action-type
  99. (install (setq install (append install specs)))
  100. (upgrade (setq upgrade (append upgrade specs)))
  101. ((remove delete) (setq remove (append remove specs))))))
  102. actions)
  103. (when (guix-continue-package-operation-p
  104. profile
  105. :install install :upgrade upgrade :remove remove)
  106. (guix-eval-in-repl
  107. (guix-make-guile-expression
  108. 'process-package-actions profile
  109. :install install :upgrade upgrade :remove remove
  110. :use-substitutes? (or guix-use-substitutes 'f)
  111. :dry-run? (or guix-dry-run 'f))
  112. (and (not guix-dry-run) operation-buffer)))))
  113. (cl-defun guix-continue-package-operation-p (profile
  114. &key install upgrade remove)
  115. "Return non-nil if a package operation should be continued.
  116. Ask a user if needed (see `guix-operation-confirm').
  117. INSTALL, UPGRADE, REMOVE are 'package action specifications'.
  118. See `guix-process-package-actions' for details."
  119. (or (null guix-operation-confirm)
  120. (let* ((entries (guix-ui-get-entries
  121. profile 'package 'id
  122. (append (mapcar #'car install)
  123. (mapcar #'car upgrade)
  124. (mapcar #'car remove))
  125. '(id name version location)))
  126. (install-strings (guix-get-package-strings install entries))
  127. (upgrade-strings (guix-get-package-strings upgrade entries))
  128. (remove-strings (guix-get-package-strings remove entries)))
  129. (if (or install-strings upgrade-strings remove-strings)
  130. (let ((buf (get-buffer-create guix-temp-buffer-name)))
  131. (with-current-buffer buf
  132. (setq-local cursor-type nil)
  133. (setq buffer-read-only nil)
  134. (erase-buffer)
  135. (insert (propertize "Profile" 'face 'bold)
  136. ": " profile "\n\n")
  137. (guix-insert-package-strings install-strings "install")
  138. (guix-insert-package-strings upgrade-strings "upgrade")
  139. (guix-insert-package-strings remove-strings "remove")
  140. (let ((win (temp-buffer-window-show
  141. buf
  142. '((display-buffer-reuse-window
  143. display-buffer-at-bottom)
  144. (window-height . fit-window-to-buffer)))))
  145. (prog1 (guix-operation-prompt)
  146. (quit-window nil win)))))
  147. (message "Nothing to be done.
  148. If Guix REPL was restarted, the data is not up-to-date.")
  149. nil))))
  150. (defun guix-get-package-strings (specs entries)
  151. "Return short package descriptions for performing package actions.
  152. See `guix-process-package-actions' for the meaning of SPECS.
  153. ENTRIES is a list of package entries to get info about packages."
  154. (-non-nil
  155. (-map (-lambda ((id . outputs))
  156. (--when-let (bui-entry-by-id entries id)
  157. (let ((location (bui-entry-non-void-value it 'location))
  158. (name (guix-package-entry->name-specification it)))
  159. (with-temp-buffer
  160. (insert name)
  161. (when outputs
  162. (insert ":" (guix-concat-strings outputs ",")))
  163. (when location
  164. (indent-to guix-package-name-width 2)
  165. (insert "(" location ")"))
  166. (buffer-string)))))
  167. specs)))
  168. (defun guix-insert-package-strings (strings action)
  169. "Insert information STRINGS at point for performing package ACTION."
  170. (when strings
  171. (insert "Package(s) to " (propertize action 'face 'bold) ":\n")
  172. (dolist (str strings)
  173. (insert " " str "\n"))
  174. (bui-newline)))
  175. ;;; Package 'info'
  176. (guix-ui-define-interface package info
  177. :mode-name "Package-Info"
  178. :buffer-name "*Guix Package Info*"
  179. :get-entries-function 'guix-package-info-get-entries
  180. :format '(guix-package-info-insert-heading
  181. nil
  182. (synopsis nil (simple guix-package-info-synopsis))
  183. nil
  184. (description nil (simple guix-package-info-description))
  185. nil
  186. (outputs simple guix-package-info-insert-outputs)
  187. guix-package-info-insert-misc
  188. (source simple guix-package-info-insert-source)
  189. (location simple guix-package-info-insert-location)
  190. (home-url format (format bui-url))
  191. (license format (format guix-package-license))
  192. (systems format guix-package-info-insert-systems)
  193. (inputs format (format guix-package-input))
  194. (native-inputs format (format guix-package-native-input))
  195. (propagated-inputs format
  196. (format guix-package-propagated-input)))
  197. :titles '((home-url . "Home page")
  198. (systems . "Supported systems"))
  199. :required '(id name version installed non-unique))
  200. (bui-define-interface guix-installed-output info
  201. :format '((file-name simple guix-installed-output-info-insert-file-name)
  202. (dependencies simple (indent bui-file)))
  203. :titles '((file-name . "Store directory"))
  204. :reduced? t)
  205. (defface guix-package-info-heading
  206. '((t :inherit bui-info-heading))
  207. "Face for package name and version headings."
  208. :group 'guix-package-info-faces)
  209. (defface guix-package-info-name-button
  210. '((t :inherit button))
  211. "Face used for a full name that can be used to describe a package."
  212. :group 'guix-package-info-faces)
  213. ;; Currently, `guix-package-info-name' and `guix-package-info-version'
  214. ;; faces are not used, but they were in the past and may be used in
  215. ;; future, so they were not removed.
  216. (defface guix-package-info-name
  217. '((t :inherit font-lock-keyword-face))
  218. "Face used for a name of a package."
  219. :group 'guix-package-info-faces)
  220. (defface guix-package-info-version
  221. '((t :inherit font-lock-builtin-face))
  222. "Face used for a version of a package."
  223. :group 'guix-package-info-faces)
  224. (defface guix-package-info-synopsis
  225. '((((type tty pc) (class color)) :weight bold)
  226. (t :height 1.1 :weight bold :inherit variable-pitch))
  227. "Face used for a synopsis of a package."
  228. :group 'guix-package-info-faces)
  229. (defface guix-package-info-description
  230. '((t))
  231. "Face used for a description of a package."
  232. :group 'guix-package-info-faces)
  233. (defface guix-package-info-license
  234. '((t :inherit font-lock-string-face))
  235. "Face used for a license of a package."
  236. :group 'guix-package-info-faces)
  237. (defface guix-package-info-location
  238. '((t :inherit bui-file-name))
  239. "Face used for a location of a package."
  240. :group 'guix-package-info-faces)
  241. (defface guix-package-info-source
  242. '((t :inherit bui-url :underline nil))
  243. "Face used for a source URL of a package."
  244. :group 'guix-package-info-faces)
  245. (defface guix-package-info-installed-outputs
  246. '((default :weight bold)
  247. (((class color) (min-colors 88) (background light))
  248. :foreground "ForestGreen")
  249. (((class color) (min-colors 88) (background dark))
  250. :foreground "PaleGreen")
  251. (((class color) (min-colors 8))
  252. :foreground "green")
  253. (t :underline t))
  254. "Face used for installed outputs of a package."
  255. :group 'guix-package-info-faces)
  256. (defface guix-package-info-uninstalled-outputs
  257. '((t :weight bold))
  258. "Face used for uninstalled outputs of a package."
  259. :group 'guix-package-info-faces)
  260. (defface guix-package-info-obsolete
  261. '((t :inherit error))
  262. "Face used if a package is obsolete."
  263. :group 'guix-package-info-faces)
  264. (defcustom guix-package-info-auto-find-package t
  265. "If non-nil, open store directory after pressing \"Show\" package button.
  266. If nil, just display the store directory (or directories) without finding."
  267. :type 'boolean
  268. :group 'guix-package-info)
  269. (defcustom guix-package-info-auto-find-source nil
  270. "If non-nil, open source file after pressing \"Show\" source button.
  271. If nil, just display the source file name without finding."
  272. :type 'boolean
  273. :group 'guix-package-info)
  274. (defcustom guix-package-info-auto-download-source t
  275. "If nil, do not automatically download a source file if it doesn't exist.
  276. After pressing a \"Show\" button, a derivation of the package
  277. source is calculated and a store file name is displayed. If this
  278. variable is non-nil and the source file does not exist in the
  279. store, it will be automatically downloaded (with a possible
  280. prompt depending on `guix-operation-confirm' variable)."
  281. :type 'boolean
  282. :group 'guix-package-info)
  283. (defcustom guix-package-info-button-functions
  284. '(guix-package-info-insert-build-button
  285. guix-package-info-insert-build-log-button
  286. guix-package-info-insert-graph-button
  287. guix-package-info-insert-size-button
  288. guix-package-info-insert-lint-button)
  289. "List of functions used to insert package buttons in Info buffer.
  290. Each function is called with 2 arguments: package ID and full name."
  291. :type '(repeat function)
  292. :group 'guix-package-info)
  293. (defvar guix-package-info-download-buffer nil
  294. "Buffer from which a current download operation was performed.")
  295. (defvar guix-package-info-output-format "%-10s"
  296. "String used to format output names of the packages.
  297. It should be a '%s'-sequence. After inserting an output name
  298. formatted with this string, an action button is inserted.")
  299. (defvar guix-package-info-obsolete-string "(This package is obsolete)"
  300. "String used if a package is obsolete.")
  301. (define-button-type 'guix-package-location
  302. :supertype 'bui
  303. 'face 'guix-package-info-location
  304. 'help-echo "Find location of this package"
  305. 'action (lambda (btn)
  306. (guix-find-location (button-label btn))))
  307. (define-button-type 'guix-package-license
  308. :supertype 'bui
  309. 'face 'guix-package-info-license
  310. 'help-echo "Display license info"
  311. 'action (lambda (btn)
  312. (require 'guix-ui-license)
  313. (bui-get-display-entries
  314. 'guix-license 'info
  315. (list 'name (button-label btn))
  316. 'add)))
  317. (define-button-type 'guix-package-name
  318. :supertype 'bui
  319. 'face 'guix-package-info-name-button
  320. 'help-echo "Describe this package"
  321. 'action (lambda (btn)
  322. (bui-get-display-entries-current
  323. 'guix-package 'info
  324. (list (guix-ui-current-profile)
  325. 'name (or (button-get btn 'spec)
  326. (button-label btn)))
  327. 'add)))
  328. (define-button-type 'guix-package-heading
  329. :supertype 'guix-package-name
  330. 'face 'guix-package-info-heading)
  331. (define-button-type 'guix-package-source
  332. :supertype 'bui
  333. 'face 'guix-package-info-source
  334. 'help-echo ""
  335. 'action (lambda (_)
  336. ;; As a source may not be a real URL (e.g., "mirror://..."),
  337. ;; no action is bound to a source button.
  338. (message "Yes, this is the source URL. What did you expect?")))
  339. (defun guix-package-info-get-entries (profile search-type
  340. &rest search-values)
  341. "Return 'package' entries for displaying them in 'info' buffer."
  342. (guix-eval-read
  343. (guix-make-guile-expression
  344. 'package/output-sexps
  345. profile 'package search-type search-values
  346. (cl-union guix-package-info-required-params
  347. (bui-info-displayed-params 'guix-package)))))
  348. (defun guix-package-info-insert-heading (entry)
  349. "Insert package ENTRY heading (name and version) at point."
  350. (bui-insert-button
  351. (concat (bui-entry-non-void-value entry 'name) " "
  352. (bui-entry-non-void-value entry 'version))
  353. 'guix-package-heading
  354. 'spec (guix-package-entry->name-specification entry))
  355. (bui-newline))
  356. (defun guix-package-info-insert-location (location &optional _)
  357. "Insert package LOCATION at point."
  358. (bui-insert-non-nil location
  359. (let ((location-file (car (split-string location ":"))))
  360. (bui-info-insert-value-indent location 'guix-package-location)
  361. ;; Do not show "Packages" button if a package 'from file' is displayed.
  362. (unless (eq (guix-ui-current-search-type) 'from-file)
  363. (bui-insert-indent)
  364. (bui-insert-action-button
  365. "Packages"
  366. (lambda (btn)
  367. (guix-package-get-display (guix-ui-current-profile)
  368. 'location
  369. (button-get btn 'location)))
  370. (format "Display packages from location '%s'" location-file)
  371. 'location location-file)))))
  372. (defun guix-package-info-insert-systems (systems entry)
  373. "Insert supported package SYSTEMS at point."
  374. (bui-info-insert-value-format
  375. systems 'guix-hydra-build-system
  376. 'action (lambda (btn)
  377. (let ((args (guix-hydra-build-latest-prompt-args
  378. :job (button-get btn 'job-name)
  379. :system (button-label btn))))
  380. (apply #'guix-hydra-build-get-display
  381. 'latest args)))
  382. 'job-name (guix-hydra-job-name-specification
  383. (bui-entry-non-void-value entry 'name)
  384. (bui-entry-non-void-value entry 'version))))
  385. (defmacro guix-package-info-define-insert-inputs (&optional type)
  386. "Define a face and a function for inserting package inputs.
  387. TYPE is a type of inputs.
  388. Function name is `guix-package-info-insert-TYPE-inputs'.
  389. Face name is `guix-package-info-TYPE-inputs'."
  390. (let* ((type-str (symbol-name type))
  391. (type-name (and type (concat type-str "-")))
  392. (type-desc (and type (concat type-str " ")))
  393. (face (intern (concat "guix-package-info-" type-name "inputs")))
  394. (btn (intern (concat "guix-package-" type-name "input"))))
  395. `(progn
  396. (defface ,face
  397. '((t :inherit guix-package-info-name-button))
  398. ,(concat "Face used for " type-desc "inputs of a package.")
  399. :group 'guix-package-info-faces)
  400. (define-button-type ',btn
  401. :supertype 'guix-package-name
  402. 'face ',face))))
  403. (guix-package-info-define-insert-inputs)
  404. (guix-package-info-define-insert-inputs native)
  405. (guix-package-info-define-insert-inputs propagated)
  406. (defun guix-package-info-insert-outputs (outputs entry)
  407. "Insert OUTPUTS from package ENTRY at point."
  408. (and (bui-entry-non-void-value entry 'obsolete)
  409. (guix-package-info-insert-obsolete-text))
  410. (and (bui-entry-non-void-value entry 'non-unique)
  411. (bui-entry-non-void-value entry 'installed)
  412. (guix-package-info-insert-non-unique-text
  413. (guix-package-entry->name-specification entry)))
  414. (bui-newline)
  415. (dolist (output outputs)
  416. (guix-package-info-insert-output output entry)))
  417. (defun guix-package-info-insert-obsolete-text ()
  418. "Insert a message about obsolete package at point."
  419. (bui-insert-indent)
  420. (bui-format-insert guix-package-info-obsolete-string
  421. 'guix-package-info-obsolete))
  422. (defun guix-package-info-insert-non-unique-text (full-name)
  423. "Insert a message about non-unique package with FULL-NAME at point."
  424. (bui-newline)
  425. (bui-insert-indent)
  426. (insert "Installed outputs are displayed for a non-unique ")
  427. (bui-insert-button full-name 'guix-package-name)
  428. (insert " package."))
  429. (defun guix-package-info-insert-output (output entry)
  430. "Insert OUTPUT at point.
  431. Make some fancy text with buttons and additional stuff if the
  432. current OUTPUT is installed (if there is such output in
  433. `installed' parameter of a package ENTRY)."
  434. (let* ((installed (bui-entry-non-void-value entry 'installed))
  435. (obsolete (bui-entry-non-void-value entry 'obsolete))
  436. (installed-entry (--find
  437. (string= (bui-entry-non-void-value it 'output)
  438. output)
  439. installed))
  440. (action-type (if installed-entry 'delete 'install))
  441. (profile (guix-ui-current-profile)))
  442. (bui-insert-indent)
  443. (bui-format-insert output
  444. (if installed-entry
  445. 'guix-package-info-installed-outputs
  446. 'guix-package-info-uninstalled-outputs)
  447. guix-package-info-output-format)
  448. ;; Do not allow a user to install/delete anything to/from a system
  449. ;; profile, so add action buttons only for non-system profiles.
  450. (when (and profile
  451. (not (guix-system-profile? profile)))
  452. (guix-package-info-insert-action-button action-type entry output)
  453. (when obsolete
  454. (bui-insert-indent)
  455. (guix-package-info-insert-action-button 'upgrade entry output)))
  456. (bui-newline)
  457. (when installed-entry
  458. (bui-info-insert-entry installed-entry 'guix-installed-output 2))))
  459. (defun guix-installed-output-info-insert-file-name (file-name &optional _)
  460. "Insert package store FILE-NAME at point."
  461. (bui-insert-non-nil file-name
  462. (bui-info-insert-value-indent file-name 'bui-file)
  463. (bui-insert-indent)
  464. (bui-insert-action-button
  465. "Size"
  466. (lambda (btn)
  467. (guix-package-size (button-get btn 'file-name)
  468. (guix-read-package-size-type)))
  469. "View package size of the current store file name"
  470. 'file-name file-name)))
  471. (defun guix-package-info-insert-action-button (type entry output)
  472. "Insert button to process an action on a package OUTPUT at point.
  473. TYPE is one of the following symbols: `install', `delete', `upgrade'.
  474. ENTRY is an alist with package info."
  475. (let ((type-str (capitalize (symbol-name type)))
  476. (full-name (guix-package-entry->name-specification entry output)))
  477. (bui-insert-action-button
  478. type-str
  479. (lambda (btn)
  480. (guix-process-package-actions
  481. (guix-ui-current-profile)
  482. `((,(button-get btn 'action-type) (,(button-get btn 'id)
  483. ,(button-get btn 'output))))
  484. (current-buffer)))
  485. (concat type-str " '" full-name "'")
  486. 'action-type type
  487. 'id (or (bui-entry-non-void-value entry 'package-id)
  488. (bui-entry-id entry))
  489. 'output output)))
  490. (defun guix-package-info-show-store-path (entry-id package-id)
  491. "Show store directories of the package outputs in the current buffer.
  492. ENTRY-ID is an ID of the current entry (package or output).
  493. PACKAGE-ID is an ID of the package which store path to show."
  494. (let* ((entries (bui-current-entries))
  495. (entry (bui-entry-by-id entries entry-id))
  496. (dirs (guix-package-store-path package-id)))
  497. (or dirs
  498. (error "Couldn't define store directory of the package"))
  499. (let* ((new-entry (cons (cons 'store-path dirs)
  500. entry))
  501. (new-entries (bui-replace-entry entries entry-id new-entry)))
  502. (setf (bui-item-entries bui-item)
  503. new-entries)
  504. (bui-redisplay-goto-button)
  505. (let ((dir (car dirs)))
  506. (if (file-exists-p dir)
  507. (if guix-package-info-auto-find-package
  508. (find-file dir)
  509. (message nil))
  510. (message "'%s' does not exist.\nTry to build this package."
  511. dir))))))
  512. (defun guix-package-info-insert-misc (entry)
  513. "Insert various buttons and other info for package ENTRY at point."
  514. (unless (bui-entry-non-void-value entry 'obsolete)
  515. (let* ((entry-id (bui-entry-id entry))
  516. (package-id (or (bui-entry-non-void-value entry 'package-id)
  517. entry-id))
  518. (full-name (guix-package-entry->name-specification entry))
  519. (store-path (bui-entry-non-void-value entry 'store-path)))
  520. (bui-info-insert-title-simple "Package")
  521. (if store-path
  522. (bui-info-insert-value-indent store-path 'bui-file)
  523. (bui-insert-action-button
  524. "Show"
  525. (lambda (btn)
  526. (guix-package-info-show-store-path
  527. (button-get btn 'entry-id)
  528. (button-get btn 'package-id)))
  529. "Show the store directory of the current package"
  530. 'entry-id entry-id
  531. 'package-id package-id))
  532. (when guix-package-info-button-functions
  533. (bui-newline)
  534. (bui-mapinsert (lambda (fun)
  535. (funcall fun package-id full-name))
  536. guix-package-info-button-functions
  537. (bui-get-indent)
  538. :indent bui-indent
  539. :column (bui-fill-column)))
  540. (bui-newline))))
  541. (defun guix-package-info-insert-build-button (id full-name)
  542. "Insert button to build a package defined by ID."
  543. (bui-insert-action-button
  544. "Build"
  545. (lambda (btn)
  546. (guix-build-package (button-get btn 'id)
  547. (format "Build '%s' package?" full-name)))
  548. (format "Build the current package")
  549. 'id id))
  550. (defun guix-package-info-insert-build-log-button (id _name)
  551. "Insert button to show build log of a package defined by ID."
  552. (bui-insert-action-button
  553. "Build Log"
  554. (lambda (btn)
  555. (guix-package-find-build-log (button-get btn 'id)))
  556. "View build log of the current package"
  557. 'id id))
  558. (declare-function guix-package-graph "guix-graph" t)
  559. (defun guix-package-info-insert-graph-button (id _name)
  560. "Insert button to show a graph of a package defined by ID."
  561. (bui-insert-action-button
  562. "Graph"
  563. (lambda (btn)
  564. (guix-package-graph (button-get btn 'id)
  565. (guix-read-graph-backend)
  566. (guix-read-graph-node-type)))
  567. "View graph of the current package"
  568. 'id id))
  569. (defun guix-package-info-insert-size-button (_id name)
  570. "Insert button to show a size of a package NAME."
  571. (bui-insert-action-button
  572. "Size"
  573. (lambda (btn)
  574. (guix-package-size (button-get btn 'name)
  575. (guix-read-package-size-type)))
  576. (format "View size of '%s' package" name)
  577. 'name name))
  578. (defun guix-package-info-insert-lint-button (id _name)
  579. "Insert button to lint a package defined by ID."
  580. (bui-insert-action-button
  581. "Lint"
  582. (lambda (btn)
  583. (guix-lint (button-get btn 'id)
  584. (and current-prefix-arg
  585. (guix-read-lint-checker-names))))
  586. "Lint the current package"
  587. 'id id))
  588. (defun guix-package-info-show-source (entry-id package-id)
  589. "Show file name of a package source in the current info buffer.
  590. Find the file if needed (see `guix-package-info-auto-find-source').
  591. ENTRY-ID is an ID of the current entry (package or output).
  592. PACKAGE-ID is an ID of the package which source to show."
  593. (let* ((entries (bui-current-entries))
  594. (entry (bui-entry-by-id entries entry-id))
  595. (file (guix-package-source-file-name package-id)))
  596. (or file
  597. (error "Couldn't define file name of the package source"))
  598. (let* ((new-entry (cons (cons 'source-file file)
  599. entry))
  600. (new-entries (bui-replace-entry entries entry-id new-entry)))
  601. (setf (bui-item-entries bui-item)
  602. new-entries)
  603. (bui-redisplay-goto-button)
  604. (if (file-exists-p file)
  605. (if guix-package-info-auto-find-source
  606. (guix-find-file file)
  607. (message "The file name of the package source is displayed."))
  608. (if guix-package-info-auto-download-source
  609. (guix-package-info-download-source package-id)
  610. (message "The source does not exist in the store."))))))
  611. (defun guix-package-info-download-source (package-id)
  612. "Download a source of the package PACKAGE-ID."
  613. (setq guix-package-info-download-buffer (current-buffer))
  614. (guix-package-source-build-derivation
  615. package-id
  616. "The source does not exist in the store. Download it?"))
  617. (defun guix-package-info-insert-source (source entry)
  618. "Insert SOURCE from package ENTRY at point.
  619. SOURCE is a list of URLs."
  620. (bui-insert-non-nil source
  621. (let* ((source-file (bui-entry-non-void-value entry 'source-file))
  622. (entry-id (bui-entry-id entry))
  623. (package-id (or (bui-entry-non-void-value entry 'package-id)
  624. entry-id)))
  625. (if (null source-file)
  626. (bui-insert-action-button
  627. "Show"
  628. (lambda (btn)
  629. (guix-package-info-show-source (button-get btn 'entry-id)
  630. (button-get btn 'package-id)))
  631. "Show the source store directory of the current package"
  632. 'entry-id entry-id
  633. 'package-id package-id)
  634. (unless (file-exists-p source-file)
  635. (bui-insert-action-button
  636. "Download"
  637. (lambda (btn)
  638. (guix-package-info-download-source
  639. (button-get btn 'package-id)))
  640. "Download the source into the store"
  641. 'package-id package-id))
  642. (bui-info-insert-value-indent source-file 'bui-file))
  643. (bui-info-insert-value-indent source 'guix-package-source))))
  644. (defun guix-package-info-redisplay-after-download ()
  645. "Redisplay an 'info' buffer after downloading the package source.
  646. This function is used to hide a \"Download\" button if needed."
  647. (when (buffer-live-p guix-package-info-download-buffer)
  648. (with-current-buffer guix-package-info-download-buffer
  649. (bui-redisplay-goto-button))
  650. (setq guix-package-info-download-buffer nil)))
  651. (add-hook 'guix-after-source-download-hook
  652. 'guix-package-info-redisplay-after-download)
  653. ;;; Package 'list'
  654. (guix-ui-define-interface package list
  655. :mode-name "Package-List"
  656. :buffer-name "*Guix Packages*"
  657. :get-entries-function 'guix-package-list-get-entries
  658. :describe-function 'guix-ui-list-describe
  659. :format '((name guix-package-list-get-name 20 t)
  660. (version nil 10 nil)
  661. (outputs nil 13 t)
  662. (installed guix-package-list-get-installed-outputs 13 t)
  663. (synopsis bui-list-get-one-line 30 nil))
  664. :hint 'guix-package-list-hint
  665. :sort-key '(name)
  666. :marks '((install . ?I)
  667. (upgrade . ?U)
  668. (delete . ?D)))
  669. (let ((map guix-package-list-mode-map))
  670. (define-key map (kbd "B") 'guix-package-list-latest-builds)
  671. (define-key map (kbd "G") 'guix-package-list-graph)
  672. (define-key map (kbd "z") 'guix-package-list-size)
  673. (define-key map (kbd "L") 'guix-package-list-lint)
  674. (define-key map (kbd "e") 'guix-package-list-edit)
  675. (define-key map (kbd "x") 'guix-package-list-execute)
  676. (define-key map (kbd "i") 'guix-package-list-mark-install)
  677. (define-key map (kbd "d") 'guix-package-list-mark-delete)
  678. (define-key map (kbd "U") 'guix-package-list-mark-upgrade)
  679. (define-key map (kbd "^") 'guix-package-list-mark-upgrades))
  680. (defface guix-package-list-installed
  681. '((t :inherit guix-package-info-installed-outputs))
  682. "Face used if there are installed outputs for the current package."
  683. :group 'guix-package-list-faces)
  684. (defface guix-package-list-obsolete
  685. '((t :inherit guix-package-info-obsolete))
  686. "Face used if a package is obsolete."
  687. :group 'guix-package-list-faces)
  688. (defcustom guix-package-list-generation-marking-enabled nil
  689. "If non-nil, allow putting marks in a list with 'generation packages'.
  690. By default this is disabled, because it may be confusing. For
  691. example, a package is installed in some generation, so a user can
  692. mark it for deletion in the list of packages from this
  693. generation, but the package may not be installed in the latest
  694. generation, so actually it cannot be deleted.
  695. If you managed to understand the explanation above or if you
  696. really know what you do or if you just don't care, you can set
  697. this variable to t. It should not do much harm anyway (most
  698. likely)."
  699. :type 'boolean
  700. :group 'guix-package-list)
  701. (defvar guix-package-list-default-hint
  702. '(("\\[guix-package-list-edit]") " edit (go to) the package definition;\n"
  703. ("\\[guix-package-list-graph]") " view package graph; "
  704. ("\\[guix-package-list-size]") " view package size; "
  705. ("\\[guix-package-list-lint]") " lint;\n"
  706. ("\\[guix-package-list-mark-install]") " mark for installation; "
  707. ("\\[guix-package-list-mark-delete]") " mark for deletion;\n"
  708. ("\\[guix-package-list-mark-upgrade]") " mark for upgrading; "
  709. ("\\[guix-package-list-mark-upgrades]") " mark all for upgrading;\n"
  710. ("\\[guix-package-list-execute]") " execute operation;\n"))
  711. (defun guix-package-list-hint ()
  712. (bui-format-hints
  713. guix-package-list-default-hint
  714. (bui-default-hint)))
  715. (defun guix-package-list-get-entries (profile search-type
  716. &rest search-values)
  717. "Return 'package' entries for displaying them in 'list' buffer."
  718. (guix-eval-read
  719. (guix-make-guile-expression
  720. 'package/output-sexps
  721. profile 'package search-type search-values
  722. (cl-union guix-package-list-required-params
  723. (bui-list-displayed-params 'guix-package)))))
  724. (defun guix-package-list-get-name (name entry)
  725. "Return NAME of the package ENTRY.
  726. Colorize it with `guix-package-list-installed' or
  727. `guix-package-list-obsolete' if needed."
  728. (bui-get-string
  729. name
  730. (cond ((bui-entry-non-void-value entry 'obsolete)
  731. 'guix-package-list-obsolete)
  732. ((bui-entry-non-void-value entry 'installed)
  733. 'guix-package-list-installed))))
  734. (defun guix-package-list-get-installed-outputs (installed &optional _)
  735. "Return string with outputs from INSTALLED entries."
  736. (bui-get-string
  737. (--map (bui-entry-non-void-value it 'output)
  738. installed)))
  739. (defun guix-package-list-marking-check ()
  740. "Signal an error if marking is disabled for the current buffer."
  741. (when (and (not guix-package-list-generation-marking-enabled)
  742. (or (derived-mode-p 'guix-package-list-mode)
  743. (derived-mode-p 'guix-output-list-mode))
  744. (eq (guix-ui-current-search-type) 'generation))
  745. (error "Action marks are disabled for lists of 'generation packages'")))
  746. (defun guix-package-list-mark-outputs (mark default
  747. &optional prompt available)
  748. "Mark the current package with MARK and move to the next line.
  749. If PROMPT is non-nil, use it to ask a user for outputs from
  750. AVAILABLE list, otherwise mark all DEFAULT outputs."
  751. (let ((outputs (if prompt
  752. (guix-completing-read-multiple
  753. prompt available nil t)
  754. default)))
  755. (apply #'bui-list--mark mark t outputs)))
  756. (defun guix-package-list-mark-install (&optional arg)
  757. "Mark the current package for installation and move to the next line.
  758. With ARG, prompt for the outputs to install (several outputs may
  759. be separated with \",\")."
  760. (interactive "P")
  761. (guix-package-list-marking-check)
  762. (let* ((entry (bui-list-current-entry))
  763. (all (bui-entry-non-void-value entry 'outputs))
  764. (installed (guix-package-entry-installed-outputs entry))
  765. (available (cl-set-difference all installed :test #'string=)))
  766. (or available
  767. (user-error "This package is already installed"))
  768. (guix-package-list-mark-outputs
  769. 'install '("out")
  770. (and arg "Output(s) to install: ")
  771. available)))
  772. (defun guix-package-list-mark-delete (&optional arg)
  773. "Mark the current package for deletion and move to the next line.
  774. With ARG, prompt for the outputs to delete (several outputs may
  775. be separated with \",\")."
  776. (interactive "P")
  777. (guix-package-list-marking-check)
  778. (let* ((entry (bui-list-current-entry))
  779. (installed (guix-package-entry-installed-outputs entry)))
  780. (or installed
  781. (user-error "This package is not installed"))
  782. (guix-package-list-mark-outputs
  783. 'delete installed
  784. (and arg "Output(s) to delete: ")
  785. installed)))
  786. (defun guix-package-list-mark-upgrade (&optional arg)
  787. "Mark the current package for upgrading and move to the next line.
  788. With ARG, prompt for the outputs to upgrade (several outputs may
  789. be separated with \",\")."
  790. (interactive "P")
  791. (guix-package-list-marking-check)
  792. (let* ((entry (bui-list-current-entry))
  793. (installed (guix-package-entry-installed-outputs entry)))
  794. (or installed
  795. (user-error "This package is not installed"))
  796. (when (or (bui-entry-non-void-value entry 'obsolete)
  797. (y-or-n-p "This package is not obsolete. Try to upgrade it anyway? "))
  798. (guix-package-list-mark-outputs
  799. 'upgrade installed
  800. (and arg "Output(s) to upgrade: ")
  801. installed))))
  802. (defun guix-package-mark-upgrades (fun &optional all)
  803. "Mark all obsolete packages for upgrading.
  804. Use FUN to perform marking of the current line. FUN should
  805. take an entry as argument.
  806. If ALL is non-nil, mark all installed (not only obsolete) packages."
  807. (guix-package-list-marking-check)
  808. (let ((entries (--filter (bui-entry-non-void-value
  809. it (if all 'installed 'obsolete))
  810. (bui-current-entries))))
  811. (bui-list-for-each-line
  812. (lambda ()
  813. (let* ((id (bui-list-current-id))
  814. (entry (--find (equal id (bui-entry-id it))
  815. entries)))
  816. (when entry
  817. (funcall fun entry)))))))
  818. (defun guix-package-list-mark-upgrades (&optional arg)
  819. "Mark all obsolete packages for upgrading.
  820. With ARG, mark all installed (including non-obsolete) packages."
  821. (interactive "P")
  822. (guix-package-mark-upgrades
  823. (lambda (entry)
  824. (apply #'bui-list--mark
  825. 'upgrade nil
  826. (guix-package-entry-installed-outputs entry)))
  827. arg))
  828. (defun guix-package-assert-non-system-profile ()
  829. "Verify that the current profile is not a system one.
  830. The current profile is the one used by the current buffer."
  831. (--when-let (guix-ui-current-profile)
  832. (guix-assert-non-system-profile it)))
  833. (defun guix-package-execute-actions (fun)
  834. "Perform actions on the marked packages.
  835. Use FUN to define actions suitable for `guix-process-package-actions'.
  836. FUN should take action-type as argument."
  837. (guix-package-assert-non-system-profile)
  838. (let ((actions (-non-nil (mapcar fun '(install delete upgrade)))))
  839. (if actions
  840. (guix-process-package-actions (guix-ui-current-profile)
  841. actions (current-buffer))
  842. (user-error "No operations specified"))))
  843. (defun guix-package-list-execute ()
  844. "Perform actions on the marked packages."
  845. (interactive)
  846. (guix-package-execute-actions #'guix-package-list-make-action))
  847. (defun guix-package-list-make-action (action-type)
  848. "Return action specification for the packages marked with ACTION-TYPE.
  849. Return nil, if there are no packages marked with ACTION-TYPE.
  850. The specification is suitable for `guix-process-package-actions'."
  851. (let ((specs (bui-list-get-marked-args action-type)))
  852. (and specs (cons action-type specs))))
  853. (defun guix-package-list-edit (&optional directory)
  854. "Go to the location of the current package.
  855. See `guix-find-location' for the meaning of DIRECTORY."
  856. (interactive (list (guix-read-directory)))
  857. (guix-edit (bui-list-current-id) directory))
  858. (defun guix-package-list-graph (backend node-type)
  859. "Show BACKEND/NODE-TYPE graph for the current package."
  860. (interactive
  861. (list (guix-read-graph-backend)
  862. (guix-read-graph-node-type)))
  863. (let ((entry (bui-list-current-entry)))
  864. (guix-package-graph (if (bui-entry-non-void-value entry 'obsolete)
  865. (bui-entry-non-void-value entry 'name)
  866. (bui-list-current-id))
  867. backend node-type)))
  868. (defun guix-package-list-size (&optional type)
  869. "Show size of the current package.
  870. See `guix-package-size' for the meaning of TYPE."
  871. (interactive (list (guix-read-package-size-type)))
  872. (guix-package-size (guix-package-entry->name-specification
  873. (bui-list-current-entry))
  874. type))
  875. (defun guix-package-list-lint (&optional checkers)
  876. "Lint the current package.
  877. Interactively with prefix, prompt for CHECKERS.
  878. See `guix-lint' for details."
  879. (interactive
  880. (list (and current-prefix-arg
  881. (guix-read-lint-checker-names))))
  882. (guix-lint (bui-list-current-id) checkers))
  883. (defun guix-package-list-latest-builds (number &rest args)
  884. "Display latest NUMBER of Hydra builds of the current package.
  885. Interactively, prompt for NUMBER. With prefix argument, prompt
  886. for all ARGS."
  887. (interactive
  888. (let ((entry (bui-list-current-entry)))
  889. (guix-hydra-build-latest-prompt-args
  890. :job (guix-hydra-job-name-specification
  891. (bui-entry-non-void-value entry 'name)
  892. (bui-entry-non-void-value entry 'version)))))
  893. (apply #'guix-hydra-latest-builds number args))
  894. ;;; Output 'list'
  895. (guix-ui-define-interface output list
  896. :mode-name "Output-List"
  897. :buffer-name "*Guix Packages*"
  898. :get-entries-function 'guix-output-list-get-entries
  899. :describe-function 'guix-output-list-describe
  900. :format '((name guix-package-list-get-name 20 t)
  901. (version nil 10 nil)
  902. (output nil 9 t)
  903. (installed nil 12 t)
  904. (synopsis bui-list-get-one-line 30 nil))
  905. :required '(id package-id)
  906. :hint 'guix-output-list-hint
  907. :sort-key '(name)
  908. :marks '((install . ?I)
  909. (upgrade . ?U)
  910. (delete . ?D)))
  911. (let ((map guix-output-list-mode-map))
  912. (define-key map (kbd "B") 'guix-package-list-latest-builds)
  913. (define-key map (kbd "G") 'guix-output-list-graph)
  914. (define-key map (kbd "z") 'guix-package-list-size)
  915. (define-key map (kbd "L") 'guix-output-list-lint)
  916. (define-key map (kbd "e") 'guix-output-list-edit)
  917. (define-key map (kbd "x") 'guix-output-list-execute)
  918. (define-key map (kbd "i") 'guix-output-list-mark-install)
  919. (define-key map (kbd "d") 'guix-output-list-mark-delete)
  920. (define-key map (kbd "U") 'guix-output-list-mark-upgrade)
  921. (define-key map (kbd "^") 'guix-output-list-mark-upgrades))
  922. (defvar guix-output-list-default-hint
  923. '(("\\[guix-output-list-edit]") " edit (go to) the package definition;\n"
  924. ("\\[guix-output-list-graph]") " view package graph; "
  925. ("\\[guix-package-list-size]") " view package size; "
  926. ("\\[guix-output-list-lint]") " lint;\n"
  927. ("\\[guix-output-list-mark-install]") " mark for installation; "
  928. ("\\[guix-output-list-mark-delete]") " mark for deletion;\n"
  929. ("\\[guix-output-list-mark-upgrade]") " mark for upgrading; "
  930. ("\\[guix-output-list-mark-upgrades]") " mark all for upgrading;\n"
  931. ("\\[guix-output-list-execute]") " execute operation;\n"))
  932. (defun guix-output-list-hint ()
  933. (bui-format-hints
  934. guix-output-list-default-hint
  935. (bui-default-hint)))
  936. (defun guix-output-list-get-entries (profile search-type
  937. &rest search-values)
  938. "Return 'output' entries for displaying them in 'list' buffer."
  939. (guix-eval-read
  940. (guix-make-guile-expression
  941. 'package/output-sexps
  942. profile 'output search-type search-values
  943. (cl-union guix-output-list-required-params
  944. (bui-list-displayed-params 'guix-output)))))
  945. (defun guix-output-list-mark-install ()
  946. "Mark the current output for installation and move to the next line."
  947. (interactive)
  948. (guix-package-list-marking-check)
  949. (let* ((entry (bui-list-current-entry))
  950. (installed (bui-entry-non-void-value entry 'installed)))
  951. (if installed
  952. (user-error "This output is already installed")
  953. (bui-list--mark 'install t))))
  954. (defun guix-output-list-mark-delete ()
  955. "Mark the current output for deletion and move to the next line."
  956. (interactive)
  957. (guix-package-list-marking-check)
  958. (let* ((entry (bui-list-current-entry))
  959. (installed (bui-entry-non-void-value entry 'installed)))
  960. (if installed
  961. (bui-list--mark 'delete t)
  962. (user-error "This output is not installed"))))
  963. (defun guix-output-list-mark-upgrade ()
  964. "Mark the current output for upgrading and move to the next line."
  965. (interactive)
  966. (guix-package-list-marking-check)
  967. (let* ((entry (bui-list-current-entry))
  968. (installed (bui-entry-non-void-value entry 'installed)))
  969. (or installed
  970. (user-error "This output is not installed"))
  971. (when (or (bui-entry-non-void-value entry 'obsolete)
  972. (y-or-n-p "This output is not obsolete. Try to upgrade it anyway? "))
  973. (bui-list--mark 'upgrade t))))
  974. (defun guix-output-list-mark-upgrades (&optional arg)
  975. "Mark all obsolete package outputs for upgrading.
  976. With ARG, mark all installed (including non-obsolete) packages."
  977. (interactive "P")
  978. (guix-package-mark-upgrades
  979. (lambda (_) (bui-list--mark 'upgrade))
  980. arg))
  981. (defun guix-output-list-execute ()
  982. "Perform actions on the marked outputs."
  983. (interactive)
  984. (guix-package-execute-actions #'guix-output-list-make-action))
  985. (defun guix-output-list-make-action (action-type)
  986. "Return action specification for the outputs marked with ACTION-TYPE.
  987. Return nil, if there are no outputs marked with ACTION-TYPE.
  988. The specification is suitable for `guix-process-output-actions'."
  989. (let ((ids (bui-list-get-marked-id-list action-type)))
  990. (and ids (cons action-type
  991. (mapcar #'guix-package-id-and-output-by-output-id
  992. ids)))))
  993. (defun guix-output-list-describe (&rest ids)
  994. "Describe outputs with IDS (list of output identifiers)."
  995. (let ((pids (--map (car (guix-package-id-and-output-by-output-id it))
  996. ids)))
  997. (bui-get-display-entries
  998. 'guix-package 'info
  999. (cl-list* (guix-ui-current-profile)
  1000. 'id (cl-remove-duplicates pids))
  1001. 'add)))
  1002. (defun guix-output-list-edit (&optional directory)
  1003. "Go to the location of the current package.
  1004. See `guix-find-location' for the meaning of DIRECTORY."
  1005. (interactive (list (guix-read-directory)))
  1006. (guix-edit (bui-entry-non-void-value (bui-list-current-entry)
  1007. 'package-id)
  1008. directory))
  1009. (defun guix-output-list-graph (backend node-type)
  1010. "Show BACKEND/NODE-TYPE graph for the current package."
  1011. (interactive
  1012. (list (guix-read-graph-backend)
  1013. (guix-read-graph-node-type)))
  1014. (let ((entry (bui-list-current-entry)))
  1015. (guix-package-graph (if (bui-entry-non-void-value entry 'obsolete)
  1016. (bui-entry-non-void-value entry 'name)
  1017. (bui-entry-non-void-value entry 'package-id))
  1018. backend node-type)))
  1019. (defun guix-output-list-lint (&optional checkers)
  1020. "Lint the current package.
  1021. Interactively with prefix, prompt for CHECKERS.
  1022. See `guix-lint' for details."
  1023. (interactive
  1024. (list (and current-prefix-arg
  1025. (guix-read-lint-checker-names))))
  1026. (guix-lint (bui-entry-non-void-value (bui-list-current-entry)
  1027. 'package-id)
  1028. checkers))
  1029. ;;; Interactive commands
  1030. (defvar guix-package-search-params '(name synopsis description)
  1031. "Default list of package parameters for searching by regexp.")
  1032. (defvar guix-package-search-history nil
  1033. "A history of minibuffer prompts.")
  1034. ;;;###autoload
  1035. (defun guix-packages-by-name (name &optional profile)
  1036. "Display Guix packages with NAME.
  1037. NAME is a string with name specification. It may optionally contain
  1038. a version number. Examples: \"guile\", \"guile@2.0.11\".
  1039. If PROFILE is nil, use `guix-current-profile'.
  1040. Interactively with prefix, prompt for PROFILE."
  1041. (interactive
  1042. (list (guix-read-package-name)
  1043. (guix-ui-read-package-profile)))
  1044. (guix-package-get-display profile 'name name))
  1045. ;;;###autoload
  1046. (defun guix-packages-by-license (license &optional profile)
  1047. "Display Guix packages with LICENSE.
  1048. LICENSE is a license name string.
  1049. If PROFILE is nil, use `guix-current-profile'.
  1050. Interactively with prefix, prompt for PROFILE."
  1051. (interactive
  1052. (list (guix-read-license-name)
  1053. (guix-ui-read-package-profile)))
  1054. (guix-package-get-display profile 'license license))
  1055. ;;;###autoload
  1056. (defun guix-packages-by-location (location &optional profile)
  1057. "Display Guix packages placed in LOCATION file.
  1058. If PROFILE is nil, use `guix-current-profile'.
  1059. Interactively with prefix, prompt for PROFILE."
  1060. (interactive
  1061. (list (guix-read-package-location)
  1062. (guix-ui-read-package-profile)))
  1063. (guix-package-get-display profile 'location location))
  1064. ;;;###autoload
  1065. (defun guix-package-from-file (file &optional profile)
  1066. "Display Guix package that the code from FILE evaluates to.
  1067. If PROFILE is nil, use `guix-current-profile'.
  1068. Interactively with prefix, prompt for PROFILE."
  1069. (interactive
  1070. (list (guix-read-file-name "File with package: ")
  1071. (guix-ui-read-package-profile)))
  1072. (bui-get-display-entries
  1073. 'guix-package 'info
  1074. (list (or profile guix-current-profile) 'from-file file)
  1075. 'add))
  1076. ;;;###autoload
  1077. (defun guix-packages-from-system-config-file (file &optional profile)
  1078. "Display Guix packages from the operating system configuration FILE.
  1079. Make sure FILE has a proper operating-system declaration. You
  1080. may check it, for example, by running the following shell command:
  1081. guix system build --dry-run FILE
  1082. See also Info node `(guix) System Configuration'.
  1083. If PROFILE is nil, use system profile (it is used to show what
  1084. packages from FILE are installed in PROFILE).
  1085. Interactively, prompt for FILE. With prefix argument, also prompt
  1086. for PROFILE.
  1087. Note: This command displays only those packages that are placed
  1088. in 'packages' field of the 'operating-system' declaration. An
  1089. installed system also contains packages installed by
  1090. services (like 'guix' or 'shepherd'). To see all the packages
  1091. installed in a system profile, use
  1092. '\\[guix-installed-system-packages]' command."
  1093. (interactive
  1094. (list (guix-read-file-name "System configuration file: ")
  1095. (and current-prefix-arg
  1096. (guix-read-package-profile guix-system-profile))))
  1097. (guix-package-get-display (or profile (guix-package-profile
  1098. guix-system-profile))
  1099. 'from-os-file file))
  1100. ;;;###autoload
  1101. (defun guix-search-by-regexp (regexp &optional params profile)
  1102. "Search for Guix packages by REGEXP.
  1103. PARAMS are package parameters that should be searched.
  1104. If PARAMS are not specified, use `guix-package-search-params'.
  1105. If PROFILE is nil, use `guix-current-profile'.
  1106. Interactively with prefix, prompt for PROFILE."
  1107. (interactive
  1108. (list (read-regexp "Regexp: " nil 'guix-package-search-history)
  1109. nil (guix-ui-read-package-profile)))
  1110. (guix-package-get-display profile 'regexp regexp
  1111. (or params guix-package-search-params)))
  1112. ;;;###autoload
  1113. (defun guix-search-by-name (regexp &optional profile)
  1114. "Search for Guix packages matching REGEXP in a package name.
  1115. If PROFILE is nil, use `guix-current-profile'.
  1116. Interactively with prefix, prompt for PROFILE."
  1117. (interactive
  1118. (list (read-string "Package name by regexp: "
  1119. nil 'guix-package-search-history)
  1120. (guix-ui-read-package-profile)))
  1121. (guix-search-by-regexp regexp '(name) profile))
  1122. ;;;###autoload
  1123. (defun guix-installed-packages (&optional profile)
  1124. "Display information about installed Guix packages.
  1125. If PROFILE is nil, use `guix-current-profile'.
  1126. Interactively with prefix, prompt for PROFILE."
  1127. (interactive (list (guix-ui-read-package-profile)))
  1128. (guix-package-get-display profile 'installed))
  1129. ;;;###autoload
  1130. (defun guix-installed-user-packages ()
  1131. "Display information about Guix packages installed in a user profile."
  1132. (interactive)
  1133. (guix-installed-packages (guix-package-profile guix-user-profile)))
  1134. ;;;###autoload
  1135. (defun guix-installed-system-packages ()
  1136. "Display information about Guix packages installed in a system profile."
  1137. (interactive)
  1138. (guix-installed-packages (guix-package-profile guix-system-profile)))
  1139. ;;;###autoload
  1140. (defun guix-obsolete-packages (&optional profile)
  1141. "Display information about obsolete Guix packages.
  1142. If PROFILE is nil, use `guix-current-profile'.
  1143. Interactively with prefix, prompt for PROFILE."
  1144. (interactive (list (guix-ui-read-package-profile)))
  1145. (guix-package-get-display profile 'obsolete))
  1146. ;;;###autoload
  1147. (defun guix-all-available-packages (&optional profile)
  1148. "Display information about all available Guix packages.
  1149. If PROFILE is nil, use `guix-current-profile'.
  1150. Interactively with prefix, prompt for PROFILE."
  1151. (interactive (list (guix-ui-read-package-profile)))
  1152. (guix-package-get-display profile 'all-available))
  1153. ;;;###autoload
  1154. (defun guix-newest-available-packages (&optional profile)
  1155. "Display information about the newest available Guix packages.
  1156. If PROFILE is nil, use `guix-current-profile'.
  1157. Interactively with prefix, prompt for PROFILE."
  1158. (interactive (list (guix-ui-read-package-profile)))
  1159. (guix-package-get-display profile 'newest-available))
  1160. (provide 'guix-ui-package)
  1161. ;;; guix-ui-package.el ends here