guix-ui-system.el 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ;;; guix-ui-system.el --- Interface for 'operating-system' declaration -*- lexical-binding: t -*-
  2. ;; Copyright © 2018 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 System as published by
  6. ;; the Free Software Foundation, either version 3 of the System, 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 System for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU General Public System
  15. ;; along with Emacs-Guix. If not, see <http://www.gnu.org/systems/>.
  16. ;;; Commentary:
  17. ;; This file provides 'info' interface for Guix System configuration
  18. ;; files – i.e., for 'operating-system' declaration.
  19. ;;; Code:
  20. (require 'cl-lib)
  21. (require 'bui)
  22. (require 'guix nil t)
  23. (require 'guix-repl)
  24. (require 'guix-guile)
  25. (require 'guix-profiles)
  26. (require 'guix-utils)
  27. (require 'guix-ui-package)
  28. (guix-define-groups system)
  29. (bui-define-entry-type guix-system
  30. :titles '((number-of-packages . "Packages")
  31. (number-of-services . "Services")))
  32. (defun guix-system-get-entries (search-type search-values params)
  33. "Receive 'system' entries.
  34. SEARCH-TYPE may be one of the following symbols: `from-file'."
  35. (let ((sexps (guix-eval-read
  36. (guix-make-guile-expression
  37. 'system-sexps search-type search-values params))))
  38. (if (eq search-type 'from-file)
  39. (mapcar (lambda (alist)
  40. (cons `(file . ,(car search-values))
  41. alist))
  42. sexps)
  43. sexps)))
  44. (defun guix-system-get-display (search-type &rest search-values)
  45. "Search for systems and show results."
  46. (bui-get-display-entries
  47. 'guix-system 'info (cl-list* search-type search-values)))
  48. ;;; System 'info'
  49. (bui-define-interface guix-system info
  50. :mode-name "System-Info"
  51. :buffer-name "*Guix System Info*"
  52. :get-entries-function 'guix-system-info-get-entries
  53. :format '((file nil (simple bui-file))
  54. nil
  55. (number-of-packages format
  56. guix-system-info-insert-number-of-packages)
  57. (number-of-services format
  58. guix-system-info-insert-number-of-services)
  59. (kernel format (guix-package-info-insert-name-button))
  60. (bootloader format (guix-package-info-insert-name-button))
  61. (firmware format (guix-package-info-insert-name-buttons))
  62. (initrd-modules format (format))))
  63. (defun guix-system-info-get-entries (search-type &rest search-values)
  64. "Return 'system' entries for displaying them in 'info' buffer."
  65. (guix-system-get-entries
  66. search-type search-values
  67. (bui-info-displayed-params 'guix-system)))
  68. (defun guix-system-info-insert-number-of-packages (number entry)
  69. "Insert the NUMBER of packages and button to display packages."
  70. (bui-format-insert number)
  71. (bui-insert-indent)
  72. (bui-insert-action-button
  73. "Show"
  74. (lambda (btn)
  75. (guix-packages-from-system-config-file (button-get btn 'file)))
  76. "Show packages from this system"
  77. 'file (bui-entry-non-void-value entry 'file)))
  78. (declare-function guix-services-from-system-config-file
  79. "guix-ui-service" t)
  80. (defun guix-system-info-insert-number-of-services (number entry)
  81. "Insert the NUMBER of services and button to display services."
  82. (bui-format-insert number)
  83. (bui-insert-indent)
  84. (bui-insert-action-button
  85. "Show"
  86. (lambda (btn)
  87. (guix-services-from-system-config-file (button-get btn 'file)))
  88. "Show services from this system"
  89. 'file (bui-entry-non-void-value entry 'file)))
  90. ;;; Interactive commands
  91. ;;;###autoload
  92. (defun guix-system-from-file (file)
  93. "Display info on 'operating-system' declaration from FILE.
  94. See `guix-packages-from-system-config-file' for more details on FILE.
  95. Interactively, prompt for FILE (see also `guix-support-dired')."
  96. (interactive (list (guix-read-os-file-name)))
  97. (guix-system-get-display 'from-file file))
  98. (provide 'guix-ui-system)
  99. ;;; guix-ui-system.el ends here