Mirror of GNU Guix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
5.2 KiB

  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2015 Joshua S. Grant <jgrant@parenthetical.io>
  4. ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (gnu)
  21. #:use-module (guix i18n)
  22. #:use-module (guix utils)
  23. #:use-module (srfi srfi-34)
  24. #:use-module (srfi srfi-35)
  25. #:use-module (ice-9 match)
  26. #:use-module (guix packages)
  27. #:use-module (gnu packages)
  28. #:use-module (gnu services)
  29. #:export (use-package-modules
  30. use-service-modules
  31. use-system-modules))
  32. ;;; Commentary:
  33. ;;;
  34. ;;; This composite module re-exports core parts the (gnu …) public modules.
  35. ;;;
  36. ;;; Code:
  37. (eval-when (eval load compile)
  38. (begin
  39. (define %public-modules
  40. '((gnu system)
  41. (gnu system mapped-devices)
  42. (gnu system file-systems)
  43. (gnu bootloader)
  44. (gnu bootloader grub)
  45. (gnu system pam)
  46. (gnu system shadow) ; 'user-account'
  47. (gnu system linux-initrd)
  48. (gnu system nss)
  49. (gnu services)
  50. (gnu services base)
  51. (gnu packages)
  52. (gnu packages base)
  53. (guix gexp))) ; so gexps can be used
  54. (for-each (let ((i (module-public-interface (current-module))))
  55. (lambda (m)
  56. (module-use! i (resolve-interface m))))
  57. %public-modules)))
  58. (define (%try-use-modules modules location make-hint)
  59. "Attempt to load all of MODULES. Report errors as coming from LOCATION, a
  60. <location> record, and use MAKE-HINT to produce a fix hint."
  61. (define (location->string loc)
  62. (match loc
  63. (#f "")
  64. (($ <location> file line column)
  65. (format #f "~a:~a:~a: " file line column))))
  66. (for-each (lambda (module)
  67. (catch 'misc-error
  68. (lambda ()
  69. (process-use-modules `((,module))))
  70. (lambda _
  71. (raise
  72. (apply
  73. make-compound-condition
  74. (condition
  75. (&message
  76. (message (format #f (G_ "module ~a not found")
  77. module))))
  78. (condition
  79. (&error-location (location location)))
  80. (or (and=> (make-hint module) list)
  81. '()))))))
  82. modules))
  83. (define (package-module-hint module)
  84. (define last-name
  85. (match module
  86. ((_ ... last)
  87. (symbol->string last))))
  88. (match (find-packages-by-name last-name)
  89. (()
  90. (condition
  91. (&fix-hint
  92. (hint (G_ "\
  93. You may use @command{guix package --show=foo | grep location} to search
  94. for the location of package @code{foo}.
  95. If you get the line @code{location: gnu/packages/bar.scm:174:2},
  96. add @code{bar} to the @code{use-package-modules} form.")))))
  97. ((package _ ...)
  98. (condition
  99. (&fix-hint
  100. (hint (format #f (G_ "\
  101. Try adding @code{(use-package-modules ~a)}.")
  102. (basename (location-file (package-location package))
  103. ".scm"))))))))
  104. (define (service-module-hint module)
  105. (define last-name
  106. (match module
  107. ((_ ... last)
  108. last)))
  109. (match (lookup-service-types last-name)
  110. (()
  111. (condition
  112. (&fix-hint
  113. (hint (format #f (G_ "\
  114. You may use @command{guix system search ~a} to search for a service
  115. matching @code{~a}.
  116. If you get the line @code{location: gnu/services/foo.scm:188:2},
  117. add @code{foo} to the @code{use-service-modules} form.")
  118. last-name last-name)))))
  119. ((package _ ...)
  120. (condition
  121. (&fix-hint
  122. (hint (format #f (G_ "\
  123. Try adding @code{(use-service-modules ~a)}.")
  124. (basename (location-file (service-type-location package))
  125. ".scm"))))))))
  126. (define-syntax-rule (try-use-modules hint modules ...)
  127. (eval-when (expand load eval)
  128. (%try-use-modules '(modules ...)
  129. (source-properties->location
  130. (current-source-location))
  131. hint)))
  132. (define-syntax-rule (use-package-modules module ...)
  133. (try-use-modules package-module-hint
  134. (gnu packages module) ...))
  135. (define-syntax-rule (use-service-modules module ...)
  136. (try-use-modules service-module-hint
  137. (gnu services module) ...))
  138. (define-syntax-rule (use-system-modules module ...)
  139. (try-use-modules (const #f) ;no hint
  140. (gnu system module) ...))
  141. ;;; gnu.scm ends here