1 ;;; guix-ui-package.el --- Interface for displaying packages -*- lexical-binding: t -*-
3 ;; Copyright © 2014, 2015, 2016 Alex Kost <alezost@gmail.com>
5 ;; This file is part of GNU Guix.
7 ;; GNU Guix is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; GNU Guix is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ;; This file provides an interface for displaying packages and outputs
23 ;; in 'list' and 'info' buffers, and commands for working with them.
28 (require 'guix-buffer
)
33 (require 'guix-backend
)
38 (require 'guix-hydra-build
)
40 (require 'guix-license
)
41 (require 'guix-location
)
42 (require 'guix-profiles
)
44 (guix-ui-define-entry-type package
)
45 (guix-ui-define-entry-type output
)
47 (defcustom guix-package-list-type
'output
48 "Define how to display packages in 'list' buffer.
49 Should be a symbol `package' or `output' (if `output', display each
50 output on a separate line; if `package', display each package on
52 :type
'(choice (const :tag
"List of packages" package
)
53 (const :tag
"List of outputs" output
))
56 (defcustom guix-package-info-type
'package
57 "Define how to display packages in 'info' buffer.
58 Should be a symbol `package' or `output' (if `output', display
59 each output separately; if `package', display outputs inside
61 :type
'(choice (const :tag
"Display packages" package
)
62 (const :tag
"Display outputs" output
))
65 (defun guix-package-get-display (profile search-type
&rest search-values
)
66 "Search for packages/outputs and show results.
68 If PROFILE is nil, use `guix-current-profile'.
70 See `guix-ui-get-entries' for the meaning of SEARCH-TYPE and
73 Results are displayed in the list buffer, unless a single package
74 is found and `guix-package-list-single' is nil."
75 (let* ((args (cl-list* (or profile guix-current-profile
)
76 search-type search-values
))
77 (entries (guix-buffer-get-entries
78 'list guix-package-list-type args
)))
79 (if (or guix-package-list-single
82 (guix-buffer-display-entries
83 entries
'list guix-package-list-type args
'add
)
84 (guix-buffer-get-display-entries
85 'info guix-package-info-type args
'add
))))
87 (defun guix-package-entry->name-specification
(entry &optional output
)
88 "Return name specification of the package ENTRY and OUTPUT."
89 (guix-package-name-specification
90 (guix-entry-value entry
'name
)
91 (guix-entry-value entry
'version
)
92 (or output
(guix-entry-value entry
'output
))))
94 (defun guix-package-entries->name-specifications
(entries)
95 "Return name specifications by the package or output ENTRIES."
96 (cl-remove-duplicates (mapcar #'guix-package-entry-
>name-specification
100 (defun guix-package-installed-outputs (entry)
101 "Return a list of installed outputs for the package ENTRY."
102 (mapcar (lambda (installed-entry)
103 (guix-entry-value installed-entry
'output
))
104 (guix-entry-value entry
'installed
)))
106 (defun guix-package-id-and-output-by-output-id (output-id)
107 "Return a list (PACKAGE-ID OUTPUT) by OUTPUT-ID."
108 (cl-multiple-value-bind (package-id-str output
)
109 (split-string output-id
":")
110 (let ((package-id (string-to-number package-id-str
)))
111 (list (if (= 0 package-id
) package-id-str package-id
)
115 ;;; Processing package actions
117 (defun guix-process-package-actions (profile actions
118 &optional operation-buffer
)
119 "Process package ACTIONS on PROFILE.
120 Each action is a list of the form:
122 (ACTION-TYPE PACKAGE-SPEC ...)
124 ACTION-TYPE is one of the following symbols: `install',
125 `upgrade', `remove'/`delete'.
126 PACKAGE-SPEC should have the following form: (ID [OUTPUT] ...)."
127 (let (install upgrade remove
)
128 (mapc (lambda (action)
129 (let ((action-type (car action
))
130 (specs (cdr action
)))
132 (install (setq install
(append install specs
)))
133 (upgrade (setq upgrade
(append upgrade specs
)))
134 ((remove delete
) (setq remove
(append remove specs
))))))
136 (when (guix-continue-package-operation-p
138 :install install
:upgrade upgrade
:remove remove
)
140 (guix-make-guile-expression
141 'process-package-actions profile
142 :install install
:upgrade upgrade
:remove remove
143 :use-substitutes?
(or guix-use-substitutes
'f
)
144 :dry-run?
(or guix-dry-run
'f
))
145 (and (not guix-dry-run
) operation-buffer
)))))
147 (cl-defun guix-continue-package-operation-p (profile
148 &key install upgrade remove
)
149 "Return non-nil if a package operation should be continued.
150 Ask a user if needed (see `guix-operation-confirm').
151 INSTALL, UPGRADE, REMOVE are 'package action specifications'.
152 See `guix-process-package-actions' for details."
153 (or (null guix-operation-confirm
)
154 (let* ((entries (guix-ui-get-entries
156 (append (mapcar #'car install
)
157 (mapcar #'car upgrade
)
158 (mapcar #'car remove
))
159 '(id name version location
)))
160 (install-strings (guix-get-package-strings install entries
))
161 (upgrade-strings (guix-get-package-strings upgrade entries
))
162 (remove-strings (guix-get-package-strings remove entries
)))
163 (if (or install-strings upgrade-strings remove-strings
)
164 (let ((buf (get-buffer-create guix-temp-buffer-name
)))
165 (with-current-buffer buf
166 (setq-local cursor-type nil
)
167 (setq buffer-read-only nil
)
169 (insert "Profile: " profile
"\n\n")
170 (guix-insert-package-strings install-strings
"install")
171 (guix-insert-package-strings upgrade-strings
"upgrade")
172 (guix-insert-package-strings remove-strings
"remove")
173 (let ((win (temp-buffer-window-show
175 '((display-buffer-reuse-window
176 display-buffer-at-bottom
)
177 (window-height . fit-window-to-buffer
)))))
178 (prog1 (guix-operation-prompt)
179 (quit-window nil win
)))))
180 (message "Nothing to be done.
181 If Guix REPL was restarted, the data is not up-to-date.")
184 (defun guix-get-package-strings (specs entries
)
185 "Return short package descriptions for performing package actions.
186 See `guix-process-package-actions' for the meaning of SPECS.
187 ENTRIES is a list of package entries to get info about packages."
191 (let* ((id (car spec
))
193 (entry (guix-entry-by-id id entries
)))
195 (let ((location (guix-entry-value entry
'location
)))
196 (concat (guix-package-entry->name-specification entry
)
199 (guix-concat-strings outputs
",")))
201 (concat "\t(" location
")")))))))
204 (defun guix-insert-package-strings (strings action
)
205 "Insert information STRINGS at point for performing package ACTION."
207 (insert "Package(s) to " (propertize action
'face
'bold
) ":\n")
209 (insert " " str
"\n"))
216 (guix-ui-info-define-interface package
217 :buffer-name
"*Guix Package Info*"
218 :format
'(guix-package-info-insert-heading
220 (synopsis ignore
(simple guix-package-info-synopsis
))
222 (description ignore
(simple guix-package-info-description
))
224 (outputs simple guix-package-info-insert-outputs
)
225 (source simple guix-package-info-insert-source
)
226 (location simple guix-package-info-insert-location
)
227 (home-url format
(format guix-url
))
228 (license format
(format guix-package-license
))
229 (systems format guix-package-info-insert-systems
)
230 (inputs format
(format guix-package-input
))
231 (native-inputs format
(format guix-package-native-input
))
232 (propagated-inputs format
233 (format guix-package-propagated-input
)))
234 :titles
'((home-url .
"Home page")
235 (systems .
"Supported systems"))
236 :required
'(id name version installed non-unique
))
238 (guix-info-define-interface installed-output
239 :format
'((path simple
(indent guix-file
))
240 (dependencies simple
(indent guix-file
)))
241 :titles
'((path .
"Store directory"))
244 (defface guix-package-info-heading
245 '((t :inherit guix-info-heading
))
246 "Face for package name and version headings."
247 :group
'guix-package-info-faces
)
249 (defface guix-package-info-name
250 '((t :inherit font-lock-keyword-face
))
251 "Face used for a name of a package."
252 :group
'guix-package-info-faces
)
254 (defface guix-package-info-name-button
255 '((t :inherit button
))
256 "Face used for a full name that can be used to describe a package."
257 :group
'guix-package-info-faces
)
259 (defface guix-package-info-version
260 '((t :inherit font-lock-builtin-face
))
261 "Face used for a version of a package."
262 :group
'guix-package-info-faces
)
264 (defface guix-package-info-synopsis
265 '((((type tty pc
) (class color
)) :weight bold
)
266 (t :height
1.1 :weight bold
:inherit variable-pitch
))
267 "Face used for a synopsis of a package."
268 :group
'guix-package-info-faces
)
270 (defface guix-package-info-description
272 "Face used for a description of a package."
273 :group
'guix-package-info-faces
)
275 (defface guix-package-info-license
276 '((t :inherit font-lock-string-face
))
277 "Face used for a license of a package."
278 :group
'guix-package-info-faces
)
280 (defface guix-package-info-location
282 "Face used for a location of a package."
283 :group
'guix-package-info-faces
)
285 (defface guix-package-info-source
286 '((t :inherit link
:underline nil
))
287 "Face used for a source URL of a package."
288 :group
'guix-package-info-faces
)
290 (defface guix-package-info-installed-outputs
291 '((default :weight bold
)
292 (((class color
) (min-colors 88) (background light
))
293 :foreground
"ForestGreen")
294 (((class color
) (min-colors 88) (background dark
))
295 :foreground
"PaleGreen")
296 (((class color
) (min-colors 8))
299 "Face used for installed outputs of a package."
300 :group
'guix-package-info-faces
)
302 (defface guix-package-info-uninstalled-outputs
304 "Face used for uninstalled outputs of a package."
305 :group
'guix-package-info-faces
)
307 (defface guix-package-info-obsolete
308 '((t :inherit error
))
309 "Face used if a package is obsolete."
310 :group
'guix-package-info-faces
)
312 (defcustom guix-package-info-auto-find-source nil
313 "If non-nil, find a source file after pressing a \"Show\" button.
314 If nil, just display the source file path without finding."
316 :group
'guix-package-info
)
318 (defcustom guix-package-info-auto-download-source t
319 "If nil, do not automatically download a source file if it doesn't exist.
320 After pressing a \"Show\" button, a derivation of the package
321 source is calculated and a store file path is displayed. If this
322 variable is non-nil and the source file does not exist in the
323 store, it will be automatically downloaded (with a possible
324 prompt depending on `guix-operation-confirm' variable)."
326 :group
'guix-package-info
)
328 (defvar guix-package-info-download-buffer nil
329 "Buffer from which a current download operation was performed.")
331 (defvar guix-package-info-output-format
"%-10s"
332 "String used to format output names of the packages.
333 It should be a '%s'-sequence. After inserting an output name
334 formatted with this string, an action button is inserted.")
336 (defvar guix-package-info-obsolete-string
"(This package is obsolete)"
337 "String used if a package is obsolete.")
339 (define-button-type 'guix-package-location
341 'face
'guix-package-info-location
342 'help-echo
"Find location of this package"
343 'action
(lambda (btn)
344 (guix-find-location (button-label btn
))))
346 (define-button-type 'guix-package-license
348 'face
'guix-package-info-license
349 'help-echo
"Display license info"
350 'action
(lambda (btn)
351 (require 'guix-ui-license
)
352 (guix-buffer-get-display-entries
354 (list 'name
(button-label btn
))
357 (define-button-type 'guix-package-name
359 'face
'guix-package-info-name-button
360 'help-echo
"Describe this package"
361 'action
(lambda (btn)
362 (guix-buffer-get-display-entries-current
363 'info guix-package-info-type
364 (list (guix-ui-current-profile)
365 'name
(or (button-get btn
'spec
)
369 (define-button-type 'guix-package-heading
370 :supertype
'guix-package-name
371 'face
'guix-package-info-heading
)
373 (define-button-type 'guix-package-source
375 'face
'guix-package-info-source
378 ;; As a source may not be a real URL (e.g., "mirror://..."),
379 ;; no action is bound to a source button.
380 (message "Yes, this is the source URL. What did you expect?")))
382 (defun guix-package-info-insert-heading (entry)
383 "Insert package ENTRY heading (name and version) at point."
385 (concat (guix-entry-value entry
'name
) " "
386 (guix-entry-value entry
'version
))
387 'guix-package-heading
388 'spec
(guix-package-entry->name-specification entry
)))
390 (defun guix-package-info-insert-location (location &optional _
)
391 "Insert package LOCATION at point."
393 (guix-format-insert nil
)
394 (let ((location-file (car (split-string location
":"))))
395 (guix-info-insert-value-indent location
'guix-package-location
)
396 (guix-info-insert-indent)
397 (guix-info-insert-action-button
400 (guix-package-get-display (guix-ui-current-profile)
402 (button-get btn
'location
)))
403 (format "Display packages from location '%s'" location-file
)
404 'location location-file
))))
406 (defun guix-package-info-insert-systems (systems entry
)
407 "Insert supported package SYSTEMS at point."
408 (guix-info-insert-value-format
409 systems
'guix-hydra-build-system
410 'action
(lambda (btn)
411 (let ((args (guix-hydra-build-latest-prompt-args
412 :job
(button-get btn
'job-name
)
413 :system
(button-label btn
))))
414 (apply #'guix-hydra-build-get-display
416 'job-name
(guix-hydra-job-name-specification
417 (guix-entry-value entry
'name
)
418 (guix-entry-value entry
'version
))))
420 (defmacro guix-package-info-define-insert-inputs
(&optional type
)
421 "Define a face and a function for inserting package inputs.
422 TYPE is a type of inputs.
423 Function name is `guix-package-info-insert-TYPE-inputs'.
424 Face name is `guix-package-info-TYPE-inputs'."
425 (let* ((type-str (symbol-name type
))
426 (type-name (and type
(concat type-str
"-")))
427 (type-desc (and type
(concat type-str
" ")))
428 (face (intern (concat "guix-package-info-" type-name
"inputs")))
429 (btn (intern (concat "guix-package-" type-name
"input"))))
432 '((t :inherit guix-package-info-name-button
))
433 ,(concat "Face used for " type-desc
"inputs of a package.")
434 :group
'guix-package-info-faces
)
436 (define-button-type ',btn
437 :supertype
'guix-package-name
440 (guix-package-info-define-insert-inputs)
441 (guix-package-info-define-insert-inputs native
)
442 (guix-package-info-define-insert-inputs propagated
)
444 (defun guix-package-info-insert-outputs (outputs entry
)
445 "Insert OUTPUTS from package ENTRY at point."
446 (and (guix-entry-value entry
'obsolete
)
447 (guix-package-info-insert-obsolete-text))
448 (and (guix-entry-value entry
'non-unique
)
449 (guix-entry-value entry
'installed
)
450 (guix-package-info-insert-non-unique-text
451 (guix-package-entry->name-specification entry
)))
453 (dolist (output outputs
)
454 (guix-package-info-insert-output output entry
)))
456 (defun guix-package-info-insert-obsolete-text ()
457 "Insert a message about obsolete package at point."
458 (guix-info-insert-indent)
459 (guix-format-insert guix-package-info-obsolete-string
460 'guix-package-info-obsolete
))
462 (defun guix-package-info-insert-non-unique-text (full-name)
463 "Insert a message about non-unique package with FULL-NAME at point."
465 (guix-info-insert-indent)
466 (insert "Installed outputs are displayed for a non-unique ")
467 (guix-insert-button full-name
'guix-package-name
)
468 (insert " package."))
470 (defun guix-package-info-insert-output (output entry
)
471 "Insert OUTPUT at point.
472 Make some fancy text with buttons and additional stuff if the
473 current OUTPUT is installed (if there is such output in
474 `installed' parameter of a package ENTRY)."
475 (let* ((installed (guix-entry-value entry
'installed
))
476 (obsolete (guix-entry-value entry
'obsolete
))
477 (installed-entry (cl-find-if
479 (string= (guix-entry-value entry
'output
)
482 (action-type (if installed-entry
'delete
'install
))
483 (profile (guix-ui-current-profile)))
484 (guix-info-insert-indent)
485 (guix-format-insert output
487 'guix-package-info-installed-outputs
488 'guix-package-info-uninstalled-outputs
)
489 guix-package-info-output-format
)
490 ;; Do not allow a user to install/delete anything to/from a system
491 ;; profile, so add action buttons only for non-system profiles.
493 (not (guix-system-profile? profile
)))
494 (guix-package-info-insert-action-button action-type entry output
)
496 (guix-info-insert-indent)
497 (guix-package-info-insert-action-button 'upgrade entry output
)))
499 (when installed-entry
500 (guix-info-insert-entry installed-entry
'installed-output
2))))
502 (defun guix-package-info-insert-action-button (type entry output
)
503 "Insert button to process an action on a package OUTPUT at point.
504 TYPE is one of the following symbols: `install', `delete', `upgrade'.
505 ENTRY is an alist with package info."
506 (let ((type-str (capitalize (symbol-name type
)))
507 (full-name (guix-package-entry->name-specification entry output
)))
508 (guix-info-insert-action-button
511 (guix-process-package-actions
512 (guix-ui-current-profile)
513 `((,(button-get btn
'action-type
) (,(button-get btn
'id
)
514 ,(button-get btn
'output
))))
516 (concat type-str
" '" full-name
"'")
518 'id
(or (guix-entry-value entry
'package-id
)
519 (guix-entry-id entry
))
522 (defun guix-package-info-show-source (entry-id package-id
)
523 "Show file name of a package source in the current info buffer.
524 Find the file if needed (see `guix-package-info-auto-find-source').
525 ENTRY-ID is an ID of the current entry (package or output).
526 PACKAGE-ID is an ID of the package which source to show."
527 (let* ((entries (guix-buffer-current-entries))
528 (entry (guix-entry-by-id entry-id entries
))
529 (file (guix-package-source-path package-id
)))
531 (error "Couldn't define file name of the package source"))
532 (let* ((new-entry (cons (cons 'source-file file
)
534 (new-entries (guix-replace-entry entry-id new-entry entries
)))
535 (setf (guix-buffer-item-entries guix-buffer-item
)
537 (guix-buffer-redisplay-goto-button)
538 (if (file-exists-p file
)
539 (if guix-package-info-auto-find-source
540 (guix-find-file file
)
541 (message "The source store path is displayed."))
542 (if guix-package-info-auto-download-source
543 (guix-package-info-download-source package-id
)
544 (message "The source does not exist in the store."))))))
546 (defun guix-package-info-download-source (package-id)
547 "Download a source of the package PACKAGE-ID."
548 (setq guix-package-info-download-buffer
(current-buffer))
549 (guix-package-source-build-derivation
551 "The source does not exist in the store. Download it?"))
553 (defun guix-package-info-insert-source (source entry
)
554 "Insert SOURCE from package ENTRY at point.
555 SOURCE is a list of URLs."
557 (guix-format-insert nil
)
558 (let* ((source-file (guix-entry-value entry
'source-file
))
559 (entry-id (guix-entry-id entry
))
560 (package-id (or (guix-entry-value entry
'package-id
)
562 (if (null source-file
)
563 (guix-info-insert-action-button
566 (guix-package-info-show-source (button-get btn
'entry-id
)
567 (button-get btn
'package-id
)))
568 "Show the source store directory of the current package"
570 'package-id package-id
)
571 (unless (file-exists-p source-file
)
572 (guix-info-insert-action-button
575 (guix-package-info-download-source
576 (button-get btn
'package-id
)))
577 "Download the source into the store"
578 'package-id package-id
))
579 (guix-info-insert-value-indent source-file
'guix-file
))
580 (guix-info-insert-value-indent source
'guix-package-source
))))
582 (defun guix-package-info-redisplay-after-download ()
583 "Redisplay an 'info' buffer after downloading the package source.
584 This function is used to hide a \"Download\" button if needed."
585 (when (buffer-live-p guix-package-info-download-buffer
)
586 (with-current-buffer guix-package-info-download-buffer
587 (guix-buffer-redisplay-goto-button))
588 (setq guix-package-info-download-buffer nil
)))
590 (add-hook 'guix-after-source-download-hook
591 'guix-package-info-redisplay-after-download
)
596 (guix-ui-list-define-interface package
597 :buffer-name
"*Guix Package List*"
598 :format
'((name guix-package-list-get-name
20 t
)
601 (installed guix-package-list-get-installed-outputs
13 t
)
602 (synopsis guix-list-get-one-line
30 nil
))
604 :marks
'((install . ?I
)
608 (let ((map guix-package-list-mode-map
))
609 (define-key map
(kbd "B") 'guix-package-list-latest-builds
)
610 (define-key map
(kbd "e") 'guix-package-list-edit
)
611 (define-key map
(kbd "x") 'guix-package-list-execute
)
612 (define-key map
(kbd "i") 'guix-package-list-mark-install
)
613 (define-key map
(kbd "d") 'guix-package-list-mark-delete
)
614 (define-key map
(kbd "U") 'guix-package-list-mark-upgrade
)
615 (define-key map
(kbd "^") 'guix-package-list-mark-upgrades
))
617 (defface guix-package-list-installed
618 '((t :inherit guix-package-info-installed-outputs
))
619 "Face used if there are installed outputs for the current package."
620 :group
'guix-package-list-faces
)
622 (defface guix-package-list-obsolete
623 '((t :inherit guix-package-info-obsolete
))
624 "Face used if a package is obsolete."
625 :group
'guix-package-list-faces
)
627 (defcustom guix-package-list-generation-marking-enabled nil
628 "If non-nil, allow putting marks in a list with 'generation packages'.
630 By default this is disabled, because it may be confusing. For
631 example, a package is installed in some generation, so a user can
632 mark it for deletion in the list of packages from this
633 generation, but the package may not be installed in the latest
634 generation, so actually it cannot be deleted.
636 If you managed to understand the explanation above or if you
637 really know what you do or if you just don't care, you can set
638 this variable to t. It should not do much harm anyway (most
641 :group
'guix-package-list
)
643 (defun guix-package-list-get-name (name entry
)
644 "Return NAME of the package ENTRY.
645 Colorize it with `guix-package-list-installed' or
646 `guix-package-list-obsolete' if needed."
647 (guix-get-string name
648 (cond ((guix-entry-value entry
'obsolete
)
649 'guix-package-list-obsolete
)
650 ((guix-entry-value entry
'installed
)
651 'guix-package-list-installed
))))
653 (defun guix-package-list-get-installed-outputs (installed &optional _
)
654 "Return string with outputs from INSTALLED entries."
656 (mapcar (lambda (entry)
657 (guix-entry-value entry
'output
))
660 (defun guix-package-list-marking-check ()
661 "Signal an error if marking is disabled for the current buffer."
662 (when (and (not guix-package-list-generation-marking-enabled
)
663 (or (derived-mode-p 'guix-package-list-mode
)
664 (derived-mode-p 'guix-output-list-mode
))
665 (eq (guix-ui-current-search-type) 'generation
))
666 (error "Action marks are disabled for lists of 'generation packages'")))
668 (defun guix-package-list-mark-outputs (mark default
669 &optional prompt available
)
670 "Mark the current package with MARK and move to the next line.
671 If PROMPT is non-nil, use it to ask a user for outputs from
672 AVAILABLE list, otherwise mark all DEFAULT outputs."
673 (let ((outputs (if prompt
674 (guix-completing-read-multiple
675 prompt available nil t
)
677 (apply #'guix-list--mark mark t outputs
)))
679 (defun guix-package-list-mark-install (&optional arg
)
680 "Mark the current package for installation and move to the next line.
681 With ARG, prompt for the outputs to install (several outputs may
682 be separated with \",\")."
684 (guix-package-list-marking-check)
685 (let* ((entry (guix-list-current-entry))
686 (all (guix-entry-value entry
'outputs
))
687 (installed (guix-package-installed-outputs entry
))
688 (available (cl-set-difference all installed
:test
#'string
=)))
690 (user-error "This package is already installed"))
691 (guix-package-list-mark-outputs
693 (and arg
"Output(s) to install: ")
696 (defun guix-package-list-mark-delete (&optional arg
)
697 "Mark the current package for deletion and move to the next line.
698 With ARG, prompt for the outputs to delete (several outputs may
699 be separated with \",\")."
701 (guix-package-list-marking-check)
702 (let* ((entry (guix-list-current-entry))
703 (installed (guix-package-installed-outputs entry
)))
705 (user-error "This package is not installed"))
706 (guix-package-list-mark-outputs
708 (and arg
"Output(s) to delete: ")
711 (defun guix-package-list-mark-upgrade (&optional arg
)
712 "Mark the current package for upgrading and move to the next line.
713 With ARG, prompt for the outputs to upgrade (several outputs may
714 be separated with \",\")."
716 (guix-package-list-marking-check)
717 (let* ((entry (guix-list-current-entry))
718 (installed (guix-package-installed-outputs entry
)))
720 (user-error "This package is not installed"))
721 (when (or (guix-entry-value entry
'obsolete
)
722 (y-or-n-p "This package is not obsolete. Try to upgrade it anyway? "))
723 (guix-package-list-mark-outputs
725 (and arg
"Output(s) to upgrade: ")
728 (defun guix-package-mark-upgrades (fun)
729 "Mark all obsolete packages for upgrading.
730 Use FUN to perform marking of the current line. FUN should
731 take an entry as argument."
732 (guix-package-list-marking-check)
733 (let ((obsolete (cl-remove-if-not
735 (guix-entry-value entry
'obsolete
))
736 (guix-buffer-current-entries))))
737 (guix-list-for-each-line
739 (let* ((id (guix-list-current-id))
742 (equal id
(guix-entry-id entry
)))
745 (funcall fun entry
)))))))
747 (defun guix-package-list-mark-upgrades ()
748 "Mark all obsolete packages for upgrading."
750 (guix-package-mark-upgrades
752 (apply #'guix-list--mark
754 (guix-package-installed-outputs entry
)))))
756 (defun guix-package-assert-non-system-profile ()
757 "Verify that the current profile is not a system one.
758 The current profile is the one used by the current buffer."
759 (let ((profile (guix-ui-current-profile)))
761 (guix-system-profile? profile
)
762 (user-error "Packages cannot be installed or removed to/from \
764 Use 'guix system reconfigure' shell command to modify a system profile."
767 (defun guix-package-execute-actions (fun)
768 "Perform actions on the marked packages.
769 Use FUN to define actions suitable for `guix-process-package-actions'.
770 FUN should take action-type as argument."
771 (guix-package-assert-non-system-profile)
772 (let ((actions (delq nil
773 (mapcar fun
'(install delete upgrade
)))))
775 (guix-process-package-actions (guix-ui-current-profile)
776 actions
(current-buffer))
777 (user-error "No operations specified"))))
779 (defun guix-package-list-execute ()
780 "Perform actions on the marked packages."
782 (guix-package-execute-actions #'guix-package-list-make-action
))
784 (defun guix-package-list-make-action (action-type)
785 "Return action specification for the packages marked with ACTION-TYPE.
786 Return nil, if there are no packages marked with ACTION-TYPE.
787 The specification is suitable for `guix-process-package-actions'."
788 (let ((specs (guix-list-get-marked-args action-type
)))
789 (and specs
(cons action-type specs
))))
791 (defun guix-package-list-edit (&optional directory
)
792 "Go to the location of the current package.
793 See `guix-find-location' for the meaning of DIRECTORY."
794 (interactive (list (guix-read-directory)))
795 (guix-edit (guix-list-current-id) directory
))
797 (defun guix-package-list-latest-builds (number &rest args
)
798 "Display latest NUMBER of Hydra builds of the current package.
799 Interactively, prompt for NUMBER. With prefix argument, prompt
802 (let ((entry (guix-list-current-entry)))
803 (guix-hydra-build-latest-prompt-args
804 :job
(guix-hydra-job-name-specification
805 (guix-entry-value entry
'name
)
806 (guix-entry-value entry
'version
)))))
807 (apply #'guix-hydra-latest-builds number args
))
812 (guix-ui-info-define-interface output
813 :buffer-name
"*Guix Package Info*"
814 :format
'((name format
(format guix-package-info-name
))
815 (version format guix-output-info-insert-version
)
816 (output format guix-output-info-insert-output
)
817 (synopsis simple
(indent guix-package-info-synopsis
))
818 (source simple guix-package-info-insert-source
)
819 (path simple
(indent guix-file
))
820 (dependencies simple
(indent guix-file
))
821 (location simple guix-package-info-insert-location
)
822 (home-url format
(format guix-url
))
823 (license format
(format guix-package-license
))
824 (systems format guix-package-info-insert-systems
)
825 (inputs format
(format guix-package-input
))
826 (native-inputs format
(format guix-package-native-input
))
827 (propagated-inputs format
828 (format guix-package-propagated-input
))
829 (description simple
(indent guix-package-info-description
)))
830 :titles guix-package-info-titles
831 :required
'(id package-id installed non-unique
))
833 (defun guix-output-info-insert-version (version entry
)
834 "Insert output VERSION and obsolete text if needed at point."
835 (guix-info-insert-value-format version
836 'guix-package-info-version
)
837 (and (guix-entry-value entry
'obsolete
)
838 (guix-package-info-insert-obsolete-text)))
840 (defun guix-output-info-insert-output (output entry
)
841 "Insert OUTPUT and action buttons at point."
842 (let* ((installed (guix-entry-value entry
'installed
))
843 (obsolete (guix-entry-value entry
'obsolete
))
844 (action-type (if installed
'delete
'install
)))
845 (guix-info-insert-value-format
848 'guix-package-info-installed-outputs
849 'guix-package-info-uninstalled-outputs
))
850 (guix-info-insert-indent)
851 (guix-package-info-insert-action-button action-type entry output
)
853 (guix-info-insert-indent)
854 (guix-package-info-insert-action-button 'upgrade entry output
))))
859 (guix-ui-list-define-interface output
860 :buffer-name
"*Guix Package List*"
861 :describe-function
'guix-output-list-describe
862 :format
'((name guix-package-list-get-name
20 t
)
866 (synopsis guix-list-get-one-line
30 nil
))
867 :required
'(id package-id
)
869 :marks
'((install . ?I
)
873 (let ((map guix-output-list-mode-map
))
874 (define-key map
(kbd "B") 'guix-package-list-latest-builds
)
875 (define-key map
(kbd "e") 'guix-output-list-edit
)
876 (define-key map
(kbd "x") 'guix-output-list-execute
)
877 (define-key map
(kbd "i") 'guix-output-list-mark-install
)
878 (define-key map
(kbd "d") 'guix-output-list-mark-delete
)
879 (define-key map
(kbd "U") 'guix-output-list-mark-upgrade
)
880 (define-key map
(kbd "^") 'guix-output-list-mark-upgrades
))
882 (defun guix-output-list-mark-install ()
883 "Mark the current output for installation and move to the next line."
885 (guix-package-list-marking-check)
886 (let* ((entry (guix-list-current-entry))
887 (installed (guix-entry-value entry
'installed
)))
889 (user-error "This output is already installed")
890 (guix-list--mark 'install t
))))
892 (defun guix-output-list-mark-delete ()
893 "Mark the current output for deletion and move to the next line."
895 (guix-package-list-marking-check)
896 (let* ((entry (guix-list-current-entry))
897 (installed (guix-entry-value entry
'installed
)))
899 (guix-list--mark 'delete t
)
900 (user-error "This output is not installed"))))
902 (defun guix-output-list-mark-upgrade ()
903 "Mark the current output for upgrading and move to the next line."
905 (guix-package-list-marking-check)
906 (let* ((entry (guix-list-current-entry))
907 (installed (guix-entry-value entry
'installed
)))
909 (user-error "This output is not installed"))
910 (when (or (guix-entry-value entry
'obsolete
)
911 (y-or-n-p "This output is not obsolete. Try to upgrade it anyway? "))
912 (guix-list--mark 'upgrade t
))))
914 (defun guix-output-list-mark-upgrades ()
915 "Mark all obsolete package outputs for upgrading."
917 (guix-package-mark-upgrades
918 (lambda (_) (guix-list--mark 'upgrade
))))
920 (defun guix-output-list-execute ()
921 "Perform actions on the marked outputs."
923 (guix-package-execute-actions #'guix-output-list-make-action
))
925 (defun guix-output-list-make-action (action-type)
926 "Return action specification for the outputs marked with ACTION-TYPE.
927 Return nil, if there are no outputs marked with ACTION-TYPE.
928 The specification is suitable for `guix-process-output-actions'."
929 (let ((ids (guix-list-get-marked-id-list action-type
)))
930 (and ids
(cons action-type
931 (mapcar #'guix-package-id-and-output-by-output-id
934 (defun guix-output-list-describe (ids)
935 "Describe outputs with IDS (list of output identifiers).
936 See `guix-package-info-type'."
937 (if (eq guix-package-info-type
'output
)
938 (guix-buffer-get-display-entries
940 (cl-list* (guix-ui-current-profile) 'id ids
)
942 (let ((pids (mapcar (lambda (oid)
943 (car (guix-package-id-and-output-by-output-id
946 (guix-buffer-get-display-entries
948 (cl-list* (guix-ui-current-profile)
949 'id
(cl-remove-duplicates pids
))
952 (defun guix-output-list-edit (&optional directory
)
953 "Go to the location of the current package.
954 See `guix-find-location' for the meaning of DIRECTORY."
955 (interactive (list (guix-read-directory)))
956 (guix-edit (guix-entry-value (guix-list-current-entry)
961 ;;; Interactive commands
963 (defvar guix-package-search-params
'(name synopsis description
)
964 "Default list of package parameters for searching by regexp.")
966 (defvar guix-package-search-history nil
967 "A history of minibuffer prompts.")
970 (defun guix-packages-by-name (name &optional profile
)
971 "Display Guix packages with NAME.
972 NAME is a string with name specification. It may optionally contain
973 a version number. Examples: \"guile\", \"guile@2.0.11\".
975 If PROFILE is nil, use `guix-current-profile'.
976 Interactively with prefix, prompt for PROFILE."
978 (list (guix-read-package-name)
979 (guix-ui-read-profile)))
980 (guix-package-get-display profile
'name name
))
983 (defun guix-packages-by-license (license &optional profile
)
984 "Display Guix packages with LICENSE.
985 LICENSE is a license name string.
986 If PROFILE is nil, use `guix-current-profile'.
987 Interactively with prefix, prompt for PROFILE."
989 (list (guix-read-license-name)
990 (guix-ui-read-profile)))
991 (guix-package-get-display profile
'license license
))
994 (defun guix-packages-by-location (location &optional profile
)
995 "Display Guix packages placed in LOCATION file.
996 If PROFILE is nil, use `guix-current-profile'.
997 Interactively with prefix, prompt for PROFILE."
999 (list (guix-read-package-location)
1000 (guix-ui-read-profile)))
1001 (guix-package-get-display profile
'location location
))
1004 (defun guix-search-by-regexp (regexp &optional params profile
)
1005 "Search for Guix packages by REGEXP.
1006 PARAMS are package parameters that should be searched.
1007 If PARAMS are not specified, use `guix-package-search-params'.
1009 If PROFILE is nil, use `guix-current-profile'.
1010 Interactively with prefix, prompt for PROFILE."
1012 (list (read-regexp "Regexp: " nil
'guix-package-search-history
)
1013 nil
(guix-ui-read-profile)))
1014 (guix-package-get-display profile
'regexp regexp
1015 (or params guix-package-search-params
)))
1018 (defun guix-search-by-name (regexp &optional profile
)
1019 "Search for Guix packages matching REGEXP in a package name.
1020 If PROFILE is nil, use `guix-current-profile'.
1021 Interactively with prefix, prompt for PROFILE."
1023 (list (read-string "Package name by regexp: "
1024 nil
'guix-package-search-history
)
1025 (guix-ui-read-profile)))
1026 (guix-search-by-regexp regexp
'(name) profile
))
1029 (defun guix-installed-packages (&optional profile
)
1030 "Display information about installed Guix packages.
1031 If PROFILE is nil, use `guix-current-profile'.
1032 Interactively with prefix, prompt for PROFILE."
1033 (interactive (list (guix-ui-read-profile)))
1034 (guix-package-get-display profile
'installed
))
1037 (defun guix-installed-user-packages ()
1038 "Display information about Guix packages installed in a user profile."
1040 (guix-installed-packages guix-user-profile
))
1043 (defun guix-installed-system-packages ()
1044 "Display information about Guix packages installed in a system profile."
1046 (guix-installed-packages
1047 (guix-packages-profile guix-system-profile nil t
)))
1050 (defun guix-obsolete-packages (&optional profile
)
1051 "Display information about obsolete Guix packages.
1052 If PROFILE is nil, use `guix-current-profile'.
1053 Interactively with prefix, prompt for PROFILE."
1054 (interactive (list (guix-ui-read-profile)))
1055 (guix-package-get-display profile
'obsolete
))
1058 (defun guix-all-available-packages (&optional profile
)
1059 "Display information about all available Guix packages.
1060 If PROFILE is nil, use `guix-current-profile'.
1061 Interactively with prefix, prompt for PROFILE."
1062 (interactive (list (guix-ui-read-profile)))
1063 (guix-package-get-display profile
'all-available
))
1066 (defun guix-newest-available-packages (&optional profile
)
1067 "Display information about the newest available Guix packages.
1068 If PROFILE is nil, use `guix-current-profile'.
1069 Interactively with prefix, prompt for PROFILE."
1070 (interactive (list (guix-ui-read-profile)))
1071 (guix-package-get-display profile
'newest-available
))
1073 (provide 'guix-ui-package
)
1075 ;;; guix-ui-package.el ends here