guix-ui-service.el 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. ;;; guix-ui-service.el --- Interface for displaying services -*- lexical-binding: t -*-
  2. ;; Copyright © 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 Service as published by
  6. ;; the Free Software Foundation, either version 3 of the Service, 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 Service for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU General Public Service
  15. ;; along with Emacs-Guix. If not, see <http://www.gnu.org/services/>.
  16. ;;; Commentary:
  17. ;; This file provides 'list' interface to display Guix services.
  18. ;; XXX Currently this interface does not provide anything useful :-)
  19. ;;; Code:
  20. (require 'bui)
  21. (require 'guix nil t)
  22. (require 'guix-repl)
  23. (require 'guix-guile)
  24. (require 'guix-utils)
  25. (guix-define-groups service)
  26. (bui-define-entry-type guix-service
  27. :message-function 'guix-service-message
  28. :titles '((type-name . "Name")))
  29. (defun guix-service-get-entries (search-type search-values params)
  30. "Receive 'service' entries.
  31. SEARCH-TYPE may be one of the following symbols: `id', `from-os-file'."
  32. (guix-eval-read
  33. (guix-make-guile-expression
  34. 'service-sexps search-type search-values params)))
  35. (defun guix-service-get-display (search-type &rest search-values)
  36. "Search for services and show results."
  37. (apply #'bui-list-get-display-entries
  38. 'guix-service search-type search-values))
  39. (defun guix-service-message (entries search-type &rest search-values)
  40. "Display a message after showing service ENTRIES."
  41. (if (null entries)
  42. (message "Couldn't find services")
  43. (when (eq search-type 'from-os-file)
  44. (message "Services from OS file '%s'."
  45. (car search-values)))))
  46. ;;; Service 'list'
  47. (bui-define-interface guix-service list
  48. :mode-name "Service-List"
  49. :buffer-name "*Guix Services*"
  50. :get-entries-function 'guix-service-list-get-entries
  51. :describe-function 'guix-service-list-describe
  52. :format '((type-name nil 40 t)))
  53. (defvar guix-service-list-required-params
  54. '(id)
  55. "List of the required 'service' parameters.
  56. These parameters are received from the Scheme side
  57. along with the displayed parameters.
  58. Do not remove `id' from this list as it is required for
  59. identifying an entry.")
  60. (defun guix-service-list-get-entries (search-type &rest search-values)
  61. "Return 'service' entries for displaying them in 'list' buffer."
  62. (guix-service-get-entries
  63. search-type search-values
  64. (cl-union guix-service-list-required-params
  65. (bui-list-displayed-params 'guix-service))))
  66. ;;; Interactive commands
  67. ;;;###autoload
  68. (defun guix-services-from-system-config-file (file)
  69. "Display Guix services from the operating system configuration FILE.
  70. See `guix-packages-from-system-config-file' for more details on FILE."
  71. (interactive
  72. (list (guix-read-file-name "System configuration file: ")))
  73. (guix-service-get-display 'from-os-file file))
  74. (provide 'guix-ui-service)
  75. ;;; guix-ui-service.el ends here