guix.el 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. (with-eval-after-load 'guix-repl
  2. (setq guix-load-path (expand-file-name "/home/oleg/src/git.savannah.gnu.org/git/guix")))
  3. (setq guix-find-file-function #'org-open-file)
  4. ;;;
  5. ;;; Graphs
  6. ;;;
  7. (setq guix-dot-default-arguments '())
  8. (defun guix-dot-file-name ()
  9. "Return '.dot' file name in the `guix-temporary-directory'."
  10. (guix-temporary-file-name "graph-" ".dot"))
  11. ;;;
  12. ;;; Debbugs
  13. ;;;
  14. (defun wi-debbugs-gnu-guix ()
  15. "List Guix bugs on debbugs.gnu.org."
  16. (interactive)
  17. (debbugs-gnu '("serious" "important" "normal") '("guix")))
  18. (defun wi-debbugs-gnu-guix-patches ()
  19. "List Guix patches on debbugs.gnu.org."
  20. (interactive)
  21. (debbugs-gnu '("serious" "important" "normal") '("guix-patches")))
  22. ;;;
  23. ;;; IRC
  24. ;;;
  25. (defcustom guix-irc-log-url "https://gnunet.org/bot/log/guix"
  26. "URL to IRC #guix channel log."
  27. :type 'string
  28. :group 'guix)
  29. (defun guix-irc-open-log ()
  30. "Open IRC #guix channel log."
  31. (interactive)
  32. (browse-url guix-irc-log-url))
  33. ;;;
  34. ;;; Version control
  35. ;;;
  36. (defvar wi-guix-git-directory (expand-file-name "/home/oleg/src/git.savannah.gnu.org/git/guix"))
  37. (defun wi-magit-show-commit-guix (commit)
  38. "Show a Git `commit' from the Guix checkout.
  39. If no commit hash provides, show a commit from hash at current point."
  40. (interactive (list (read-string "Commit: " nil nil (word-at-point))))
  41. (let ((default-directory wi-guix-git-directory))
  42. (magit-show-commit commit)))
  43. (defun wi-magit-find-file-guix (commit file)
  44. "Show a `file' from Git `commit' in the Guix checkout."
  45. (interactive "sCommit: \nsFile: ")
  46. (let ((default-directory wi-guix-git-directory))
  47. (magit-find-file commit file)))
  48. (defun wi-set-guix-directory (directory)
  49. "Set a `GUIX-DIRECTORY' path."
  50. (interactive "DDirectory: ")
  51. (setq guix-directory directory))
  52. ;;;
  53. ;;; CI
  54. ;;;
  55. (defcustom guix-hydra-script "~/src/hello-guile/package.scm"
  56. "Script to get package names appropriate for Guix Hydra."
  57. :group 'guix-hydra)
  58. (defun guix-hydra-packages (packages)
  59. "Return a list of PACKAGES appropriate for Guix Hydra."
  60. (remove ""
  61. (split-string (shell-command-to-string
  62. (mapconcat 'identity
  63. (append (list (expand-file-name guix-hydra-script))
  64. packages)
  65. " "))
  66. "\n")))
  67. (defun guix-hydra-packages-browse (packages)
  68. "Open a WEB browser at Guix Hydra for PACKAGES."
  69. (interactive "sPackages (space separated): ")
  70. (mapc (lambda (package)
  71. (engine/search-guix-hydra-job package))
  72. (guix-hydra-packages (split-string packages " "))))
  73. (setq guix-read-package-name-function
  74. #'guix-read-package-name-at-point)
  75. (defun wi-guix-hydra-latest-builds (number)
  76. "Return a NUMBER of latest builds on Hydra."
  77. (interactive
  78. (list (read-number "Number of latest builds: " 64)))
  79. (flet ((guix-hydra-latest-builds-custom ()
  80. (guix-hydra-latest-builds number :project 'gnu :system "x86_64-linux")))
  81. (if current-prefix-arg
  82. (let ((guix-hydra-url "https://berlin.guixsd.org"))
  83. (funcall #'guix-hydra-latest-builds-custom))
  84. (funcall #'guix-hydra-latest-builds-custom))))
  85. (defcustom guix-substitute-servers
  86. '("https://berlin.guixsd.org/" "https://hydra.gnu.org/")
  87. "List of Guix substitute servers."
  88. :type '(repeat string)
  89. :group 'guix)
  90. (defun guix-substitute-servers-narinfo (hash)
  91. "Download a narinfo for HASH from Guix servers."
  92. (mapcar (lambda (server)
  93. (mapconcat 'identity
  94. (list "wget" "-q" "-O" "-"
  95. (concat server hash ".narinfo"))
  96. " "))
  97. guix-substitute-servers))
  98. (with-eval-after-load 'build-farm-url
  99. (add-to-list 'build-farm-url-alist
  100. '("http://cuirass.tld" . cuirass)))
  101. (defvar bui-rgrep-directory
  102. "~/.local/share/chezmoi/dotfiles/fiore/manifests/"
  103. "Directory to search for a package in `bui-rgrep-manifests' procedure.")
  104. (defun bui-rgrep-manifests ()
  105. "Invoke rgrep in `bui-rgrep-directory'."
  106. (interactive)
  107. (rgrep (substring-no-properties (aref (tabulated-list-get-entry) 0))
  108. "*.scm"
  109. (expand-file-name bui-rgrep-directory)))
  110. (with-eval-after-load 'build-farm
  111. (defun wi-build-farm (job)
  112. "Wrapper for `build-farm' procedure.
  113. Produces URL as https://ci.guix.info/api/latestbuilds?nr=10&jobset=guix-master&job=opam-2.0.1&system=x86_64-linux"
  114. (interactive (list (guix-read-package-name)))
  115. (let ((build-farm-url "https://ci.guix.info")
  116. (number 3)
  117. (job (if current-prefix-arg
  118. (string-trim-right (shell-command-to-string (format "guix-package-version %s" job)))
  119. job)))
  120. (apply #'build-farm-get-display
  121. build-farm-url 'build 'latest number (list :project nil
  122. :jobset (if current-prefix-arg nil "guix-master")
  123. :job (concat job ".x86_64-linux")
  124. :system nil)))))
  125. (defun wi-guix-download (url)
  126. "Download URL with a \"guix download\" shell command."
  127. (interactive "sDownload URL: ")
  128. (insert
  129. (shell-command-to-string
  130. (concat "guix download " url
  131. " 2>/dev/null" "| tail -n 1" "| tr -d '\n'"))))
  132. ;;;
  133. ;;; Project
  134. ;;;
  135. (defun wi-compile-guix (directory)
  136. ""
  137. (interactive "DDirectory: ")
  138. (require 'compile)
  139. (mapc 'kill-process compilation-in-progress)
  140. (compile
  141. (format
  142. "cd %s; guix environment --pure guix --ad-hoc help2man guile-sqlite3 guile-gcrypt -- make -j4 -k"
  143. directory)))
  144. (defun wi-copy-cgit-guix-path (path)
  145. "Copy cgit guix path to kill ring"
  146. (interactive "sPath: ")
  147. (kill-new (concat "https://git.savannah.gnu.org/cgit/guix.git/tree/"
  148. path)))
  149. (defun projectile-run-shell-guix ()
  150. (interactive)
  151. (projectile-run-shell)
  152. (font-lock-mode)
  153. (guix-build-log-minor-mode))
  154. ;;;
  155. ;;; Snippets
  156. ;;;
  157. (defun guix-insert-copyright ()
  158. (interactive)
  159. (insert (format ";;; Copyright © %s %s\n"
  160. (format-time-string "%Y")
  161. (wi-fullname-and-email))))
  162. (define-auto-insert
  163. (rx "package" (one-or-more (or alphanumeric "-")) ".scm" line-end)
  164. ["guix/gnu/packages/package" yas-expand-current-buffer])
  165. (define-auto-insert
  166. (rx "gnu/services/" (one-or-more (or alphanumeric "-")) ".scm" line-end)
  167. ["guix/gnu/services/service" yas-expand-current-buffer])
  168. (define-auto-insert
  169. (rx "gnu/tests/" (one-or-more (or alphanumeric "-")) ".scm" line-end)
  170. ["guix/gnu/tests/test" yas-expand-current-buffer])
  171. (define-auto-insert
  172. (rx "vm" (one-or-more (or alphanumeric "-")) ".scm" line-end)
  173. ["guix/gnu/system/examples/vm-inherit-image" yas-expand-current-buffer])
  174. (define-auto-insert
  175. (rx "modules/services/" (one-or-more (or alphanumeric "-")) ".scm" line-end)
  176. ["dotfiles/modules/services/service" yas-expand-current-buffer])