go.scm 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2020 Katherine Cox-Buday <cox.katherine.e@gmail.com>
  3. ;;; Copyright © 2020 Helio Machado <0x2b3bfa0+guix@googlemail.com>
  4. ;;; Copyright © 2021 François Joulaud <francois.joulaud@radiofrance.com>
  5. ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  6. ;;; Copyright © 2021 Ludovic Courtès <ludo@gnu.org>
  7. ;;;
  8. ;;; This file is part of GNU Guix.
  9. ;;;
  10. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  11. ;;; under the terms of the GNU General Public License as published by
  12. ;;; the Free Software Foundation; either version 3 of the License, or (at
  13. ;;; your option) any later version.
  14. ;;;
  15. ;;; GNU Guix is distributed in the hope that it will be useful, but
  16. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;;; GNU General Public License for more details.
  19. ;;;
  20. ;;; You should have received a copy of the GNU General Public License
  21. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  22. (define-module (guix import go)
  23. #:use-module (guix build-system go)
  24. #:use-module (guix git)
  25. #:use-module (guix i18n)
  26. #:use-module (guix diagnostics)
  27. #:use-module (guix import utils)
  28. #:use-module (guix import json)
  29. #:use-module (guix packages)
  30. #:use-module ((guix utils) #:select (string-replace-substring))
  31. #:use-module (guix http-client)
  32. #:use-module ((guix licenses) #:prefix license:)
  33. #:use-module (guix memoization)
  34. #:autoload (htmlprag) (html->sxml) ;from Guile-Lib
  35. #:autoload (guix git) (update-cached-checkout)
  36. #:autoload (gcrypt hash) (open-hash-port hash-algorithm sha256)
  37. #:autoload (guix serialization) (write-file)
  38. #:autoload (guix base32) (bytevector->nix-base32-string)
  39. #:autoload (guix build utils) (mkdir-p)
  40. #:use-module (ice-9 match)
  41. #:use-module (ice-9 rdelim)
  42. #:use-module (ice-9 receive)
  43. #:use-module (ice-9 regex)
  44. #:use-module ((rnrs io ports) #:select (call-with-port))
  45. #:use-module (srfi srfi-1)
  46. #:use-module (srfi srfi-9)
  47. #:use-module (srfi srfi-11)
  48. #:use-module (srfi srfi-26)
  49. #:use-module (sxml xpath)
  50. #:use-module (web client)
  51. #:use-module (web response)
  52. #:use-module (web uri)
  53. #:export (go-path-escape
  54. go-module->guix-package
  55. go-module-recursive-import))
  56. ;;; Commentary:
  57. ;;;
  58. ;;; (guix import go) attempts to make it easier to create Guix package
  59. ;;; declarations for Go modules.
  60. ;;;
  61. ;;; Modules in Go are a "collection of related Go packages" which are "the
  62. ;;; unit of source code interchange and versioning". Modules are generally
  63. ;;; hosted in a repository.
  64. ;;;
  65. ;;; At this point it should handle correctly modules which have only Go
  66. ;;; dependencies and are accessible from proxy.golang.org (or configured via
  67. ;;; GOPROXY).
  68. ;;;
  69. ;;; We want it to work more or less this way:
  70. ;;; - get latest version for the module from GOPROXY
  71. ;;; - infer VCS root repo from which we will check-out source by
  72. ;;; + recognising known patterns (like github.com)
  73. ;;; + or recognizing .vcs suffix
  74. ;;; + or parsing meta tag in HTML served at the URL
  75. ;;; + or (TODO) if nothing else works by using zip file served by GOPROXY
  76. ;;; - get go.mod from GOPROXY (which is able to synthetize one if needed)
  77. ;;; - extract list of dependencies from this go.mod
  78. ;;;
  79. ;;; The Go module paths are translated to a Guix package name under the
  80. ;;; assumption that there will be no collision.
  81. ;;; TODO list
  82. ;;; - get correct hash in vcs->origin
  83. ;;; - print partial result during recursive imports (need to catch
  84. ;;; exceptions)
  85. ;;; Code:
  86. (define (go-path-escape path)
  87. "Escape a module path by replacing every uppercase letter with an
  88. exclamation mark followed with its lowercase equivalent, as per the module
  89. Escaped Paths specification (see:
  90. https://godoc.org/golang.org/x/mod/module#hdr-Escaped_Paths)."
  91. (define (escape occurrence)
  92. (string-append "!" (string-downcase (match:substring occurrence))))
  93. (regexp-substitute/global #f "[A-Z]" path 'pre escape 'post))
  94. (define (go-module-latest-version goproxy-url module-path)
  95. "Fetch the version number of the latest version for MODULE-PATH from the
  96. given GOPROXY-URL server."
  97. (assoc-ref (json-fetch (format #f "~a/~a/@latest" goproxy-url
  98. (go-path-escape module-path)))
  99. "Version"))
  100. (define (go-package-licenses name)
  101. "Retrieve the list of licenses that apply to NAME, a Go package or module
  102. name (e.g. \"github.com/golang/protobuf/proto\"). The data is scraped from
  103. the https://pkg.go.dev/ web site."
  104. (let*-values (((url) (string-append "https://pkg.go.dev/" name
  105. "?tab=licenses"))
  106. ((response body) (http-get url))
  107. ;; Extract the text contained in a h2 child node of any
  108. ;; element marked with a "License" class attribute.
  109. ((select) (sxpath `(// (* (@ (equal? (class "License"))))
  110. h2 // *text*))))
  111. (and (eq? (response-code response) 200)
  112. (match (select (html->sxml body))
  113. (() #f) ;nothing selected
  114. (licenses licenses)))))
  115. (define (go.pkg.dev-info name)
  116. (http-get (string-append "https://pkg.go.dev/" name)))
  117. (define go.pkg.dev-info*
  118. (memoize go.pkg.dev-info))
  119. (define (go-package-description name)
  120. "Retrieve a short description for NAME, a Go package name,
  121. e.g. \"google.golang.org/protobuf/proto\". The data is scraped from the
  122. https://pkg.go.dev/ web site."
  123. (let*-values (((response body) (go.pkg.dev-info* name))
  124. ;; Extract the text contained in a h2 child node of any
  125. ;; element marked with a "License" class attribute.
  126. ((select) (sxpath
  127. `(// (section
  128. (@ (equal? (class "Documentation-overview"))))
  129. (p 1)))))
  130. (and (eq? (response-code response) 200)
  131. (match (select (html->sxml body))
  132. (() #f) ;nothing selected
  133. (((p . strings))
  134. ;; The paragraph text is returned as a list of strings embedding
  135. ;; newline characters. Join them and strip the newline
  136. ;; characters.
  137. (string-delete #\newline (string-join strings)))))))
  138. (define (go-package-synopsis module-name)
  139. "Retrieve a short synopsis for a Go module named MODULE-NAME,
  140. e.g. \"google.golang.org/protobuf\". The data is scraped from
  141. the https://pkg.go.dev/ web site."
  142. ;; Note: Only the *module* (rather than package) page has the README title
  143. ;; used as a synopsis on the https://pkg.go.dev web site.
  144. (let*-values (((response body) (go.pkg.dev-info* module-name))
  145. ;; Extract the text contained in a h2 child node of any
  146. ;; element marked with a "License" class attribute.
  147. ((select) (sxpath
  148. `(// (div (@ (equal? (class "UnitReadme-content"))))
  149. // h3 *text*))))
  150. (and (eq? (response-code response) 200)
  151. (match (select (html->sxml body))
  152. (() #f) ;nothing selected
  153. ((title more ...) ;title is the first string of the list
  154. (string-trim-both title))))))
  155. (define (list->licenses licenses)
  156. "Given a list of LICENSES mostly following the SPDX conventions, return the
  157. corresponding Guix license or 'unknown-license!"
  158. (filter-map (lambda (license)
  159. (and (not (string-null? license))
  160. (not (any (cut string=? <> license)
  161. '("AND" "OR" "WITH")))
  162. ;; Adjust the license names scraped from
  163. ;; https://pkg.go.dev to an equivalent SPDX identifier,
  164. ;; if they differ (see: https://github.com/golang/pkgsite
  165. ;; /internal/licenses/licenses.go#L174).
  166. (or (spdx-string->license
  167. (match license
  168. ("BlueOak-1.0" "BlueOak-1.0.0")
  169. ("BSD-0-Clause" "0BSD")
  170. ("BSD-2-Clause" "BSD-2-Clause-FreeBSD")
  171. ("GPL2" "GPL-2.0")
  172. ("GPL3" "GPL-3.0")
  173. ("NIST" "NIST-PD")
  174. (_ license)))
  175. 'unknown-license!)))
  176. licenses))
  177. (define (fetch-go.mod goproxy-url module-path version)
  178. "Fetches go.mod from the given GOPROXY-URL server for the given MODULE-PATH
  179. and VERSION."
  180. (let ((url (format #f "~a/~a/@v/~a.mod" goproxy-url
  181. (go-path-escape module-path)
  182. (go-path-escape version))))
  183. (http-fetch url)))
  184. (define %go.mod-require-directive-rx
  185. ;; A line in a require directive is composed of a module path and
  186. ;; a version separated by whitespace and an optionnal '//' comment at
  187. ;; the end.
  188. (make-regexp
  189. (string-append
  190. "^[[:blank:]]*"
  191. "([^[:blank:]]+)[[:blank:]]+([^[:blank:]]+)"
  192. "([[:blank:]]+//.*)?")))
  193. (define %go.mod-replace-directive-rx
  194. ;; ReplaceSpec = ModulePath [ Version ] "=>" FilePath newline
  195. ;; | ModulePath [ Version ] "=>" ModulePath Version newline .
  196. (make-regexp
  197. (string-append
  198. "([^[:blank:]]+)([[:blank:]]+([^[:blank:]]+))?"
  199. "[[:blank:]]+" "=>" "[[:blank:]]+"
  200. "([^[:blank:]]+)([[:blank:]]+([^[:blank:]]+))?")))
  201. (define (parse-go.mod port)
  202. "Parse the go.mod file accessible via the input PORT, returning a list of
  203. requirements."
  204. (define-record-type <results>
  205. (make-results requirements replacements)
  206. results?
  207. (requirements results-requirements)
  208. (replacements results-replacements))
  209. ;; We parse only a subset of https://golang.org/ref/mod#go-mod-file-grammar
  210. ;; which we think necessary for our use case.
  211. (define (toplevel results)
  212. "Main parser, RESULTS is a pair of alist serving as accumulator for
  213. all encountered requirements and replacements."
  214. (let ((line (read-line port)))
  215. (cond
  216. ((eof-object? line)
  217. ;; parsing ended, give back the result
  218. results)
  219. ((string=? line "require (")
  220. ;; a require block begins, delegate parsing to IN-REQUIRE
  221. (in-require results))
  222. ((string=? line "replace (")
  223. ;; a replace block begins, delegate parsing to IN-REPLACE
  224. (in-replace results))
  225. ((string-prefix? "require " line)
  226. ;; a standalone require directive
  227. (let* ((stripped-line (string-drop line 8))
  228. (new-results (require-directive results stripped-line)))
  229. (toplevel new-results)))
  230. ((string-prefix? "replace " line)
  231. ;; a standalone replace directive
  232. (let* ((stripped-line (string-drop line 8))
  233. (new-results (replace-directive results stripped-line)))
  234. (toplevel new-results)))
  235. (#t
  236. ;; unrecognised line, ignore silently
  237. (toplevel results)))))
  238. (define (in-require results)
  239. (let ((line (read-line port)))
  240. (cond
  241. ((eof-object? line)
  242. ;; this should never happen here but we ignore silently
  243. results)
  244. ((string=? line ")")
  245. ;; end of block, coming back to toplevel
  246. (toplevel results))
  247. (#t
  248. (in-require (require-directive results line))))))
  249. (define (in-replace results)
  250. (let ((line (read-line port)))
  251. (cond
  252. ((eof-object? line)
  253. ;; this should never happen here but we ignore silently
  254. results)
  255. ((string=? line ")")
  256. ;; end of block, coming back to toplevel
  257. (toplevel results))
  258. (#t
  259. (in-replace (replace-directive results line))))))
  260. (define (replace-directive results line)
  261. "Extract replaced modules and new requirements from replace directive
  262. in LINE and add to RESULTS."
  263. (match results
  264. (($ <results> requirements replaced)
  265. (let* ((rx-match (regexp-exec %go.mod-replace-directive-rx line))
  266. (module-path (match:substring rx-match 1))
  267. (version (match:substring rx-match 3))
  268. (new-module-path (match:substring rx-match 4))
  269. (new-version (match:substring rx-match 6))
  270. (new-replaced (alist-cons module-path version replaced))
  271. (new-requirements
  272. (if (string-match "^\\.?\\./" new-module-path)
  273. requirements
  274. (alist-cons new-module-path new-version requirements))))
  275. (make-results new-requirements new-replaced)))))
  276. (define (require-directive results line)
  277. "Extract requirement from LINE and add it to RESULTS."
  278. (let* ((rx-match (regexp-exec %go.mod-require-directive-rx line))
  279. (module-path (match:substring rx-match 1))
  280. ;; we saw double-quoted string in the wild without escape
  281. ;; sequences so we just trim the quotes
  282. (module-path (string-trim-both module-path #\"))
  283. (version (match:substring rx-match 2)))
  284. (match results
  285. (($ <results> requirements replaced)
  286. (make-results (alist-cons module-path version requirements) replaced)))))
  287. (let ((results (toplevel (make-results '() '()))))
  288. (match results
  289. (($ <results> requirements replaced)
  290. ;; At last we remove replaced modules from the requirements list
  291. (fold
  292. (lambda (replacedelem requirements)
  293. (alist-delete! (car replacedelem) requirements))
  294. requirements
  295. replaced)))))
  296. ;; Prevent inlining of this procedure, which is accessed by unit tests.
  297. (set! parse-go.mod parse-go.mod)
  298. (define-record-type <vcs>
  299. (%make-vcs url-prefix root-regex type)
  300. vcs?
  301. (url-prefix vcs-url-prefix)
  302. (root-regex vcs-root-regex)
  303. (type vcs-type))
  304. (define (make-vcs prefix regexp type)
  305. (%make-vcs prefix (make-regexp regexp) type))
  306. (define known-vcs
  307. ;; See the following URL for the official Go equivalent:
  308. ;; https://github.com/golang/go/blob/846dce9d05f19a1f53465e62a304dea21b99f910/src/cmd/go/internal/vcs/vcs.go#L1026-L1087
  309. (list
  310. (make-vcs
  311. "github.com"
  312. "^(github\\.com/[A-Za-z0-9_.\\-]+/[A-Za-z0-9_.\\-]+)(/[A-Za-z0-9_.\\-]+)*$"
  313. 'git)
  314. (make-vcs
  315. "bitbucket.org"
  316. "^(bitbucket\\.org/([A-Za-z0-9_.\\-]+/[A-Za-z0-9_.\\-]+))(/[A-Za-z0-9_.\\-]+)*$"
  317. 'unknown)
  318. (make-vcs
  319. "hub.jazz.net/git/"
  320. "^(hub\\.jazz\\.net/git/[a-z0-9]+/[A-Za-z0-9_.\\-]+)(/[A-Za-z0-9_.\\-]+)*$"
  321. 'git)
  322. (make-vcs
  323. "git.apache.org"
  324. "^(git\\.apache\\.org/[a-z0-9_.\\-]+\\.git)(/[A-Za-z0-9_.\\-]+)*$"
  325. 'git)
  326. (make-vcs
  327. "git.openstack.org"
  328. "^(git\\.openstack\\.org/[A-Za-z0-9_.\\-]+/[A-Za-z0-9_.\\-]+)(\\.git)?\
  329. (/[A-Za-z0-9_.\\-]+)*$"
  330. 'git)))
  331. (define (module-path->repository-root module-path)
  332. "Infer the repository root from a module path. Go modules can be
  333. defined at any level of a repository tree, but querying for the meta tag
  334. usually can only be done from the web page at the root of the repository,
  335. hence the need to derive this information."
  336. ;; For reference, see: https://golang.org/ref/mod#vcs-find.
  337. (define vcs-qualifiers '(".bzr" ".fossil" ".git" ".hg" ".svn"))
  338. (define (vcs-qualified-module-path->root-repo-url module-path)
  339. (let* ((vcs-qualifiers-group (string-join vcs-qualifiers "|"))
  340. (pattern (format #f "^(.*(~a))(/|$)" vcs-qualifiers-group))
  341. (m (string-match pattern module-path)))
  342. (and=> m (cut match:substring <> 1))))
  343. (or (and=> (find (lambda (vcs)
  344. (string-prefix? (vcs-url-prefix vcs) module-path))
  345. known-vcs)
  346. (lambda (vcs)
  347. (match:substring (regexp-exec (vcs-root-regex vcs)
  348. module-path) 1)))
  349. (vcs-qualified-module-path->root-repo-url module-path)
  350. module-path))
  351. (define (go-module->guix-package-name module-path)
  352. "Converts a module's path to the canonical Guix format for Go packages."
  353. (string-downcase (string-append "go-" (string-replace-substring
  354. (string-replace-substring
  355. module-path
  356. "." "-")
  357. "/" "-"))))
  358. (define-record-type <module-meta>
  359. (make-module-meta import-prefix vcs repo-root)
  360. module-meta?
  361. (import-prefix module-meta-import-prefix)
  362. (vcs module-meta-vcs) ;a symbol
  363. (repo-root module-meta-repo-root))
  364. (define (fetch-module-meta-data module-path)
  365. "Retrieve the module meta-data from its landing page. This is necessary
  366. because goproxy servers don't currently provide all the information needed to
  367. build a package."
  368. ;; <meta name="go-import" content="import-prefix vcs repo-root">
  369. (let* ((port (http-fetch (format #f "https://~a?go-get=1" module-path)))
  370. (select (sxpath `(// head (meta (@ (equal? (name "go-import"))))
  371. // content))))
  372. (match (select (call-with-port port html->sxml))
  373. (() #f) ;nothing selected
  374. (((content content-text))
  375. (match (string-split content-text #\space)
  376. ((root-path vcs repo-url)
  377. (make-module-meta root-path (string->symbol vcs) repo-url)))))))
  378. (define (module-meta-data-repo-url meta-data goproxy-url)
  379. "Return the URL where the fetcher which will be used can download the
  380. source."
  381. (if (member (module-meta-vcs meta-data) '(fossil mod))
  382. goproxy-url
  383. (module-meta-repo-root meta-data)))
  384. ;; XXX: Copied from (guix scripts hash).
  385. (define (vcs-file? file stat)
  386. (case (stat:type stat)
  387. ((directory)
  388. (member (basename file) '(".bzr" ".git" ".hg" ".svn" "CVS")))
  389. ((regular)
  390. ;; Git sub-modules have a '.git' file that is a regular text file.
  391. (string=? (basename file) ".git"))
  392. (else
  393. #f)))
  394. ;; XXX: Adapted from 'file-hash' in (guix scripts hash).
  395. (define* (file-hash file #:optional (algorithm (hash-algorithm sha256)))
  396. ;; Compute the hash of FILE.
  397. (let-values (((port get-hash) (open-hash-port algorithm)))
  398. (write-file file port #:select? (negate vcs-file?))
  399. (force-output port)
  400. (get-hash)))
  401. (define* (git-checkout-hash url reference algorithm)
  402. "Return the ALGORITHM hash of the checkout of URL at REFERENCE, a commit or
  403. tag."
  404. (define cache
  405. (string-append (or (getenv "TMPDIR") "/tmp")
  406. "/guix-import-go-"
  407. (passwd:name (getpwuid (getuid)))))
  408. ;; Use a custom cache to avoid cluttering the default one under
  409. ;; ~/.cache/guix, but choose one under /tmp so that it's persistent across
  410. ;; subsequent "guix import" invocations.
  411. (mkdir-p cache)
  412. (chmod cache #o700)
  413. (let-values (((checkout commit _)
  414. (parameterize ((%repository-cache-directory cache))
  415. (update-cached-checkout url
  416. #:ref
  417. `(tag-or-commit . ,reference)))))
  418. (file-hash checkout algorithm)))
  419. (define (vcs->origin vcs-type vcs-repo-url version)
  420. "Generate the `origin' block of a package depending on what type of source
  421. control system is being used."
  422. (case vcs-type
  423. ((git)
  424. (let ((plain-version? (string=? version (go-version->git-ref version)))
  425. (v-prefixed? (string-prefix? "v" version)))
  426. `(origin
  427. (method git-fetch)
  428. (uri (git-reference
  429. (url ,vcs-repo-url)
  430. (commit ,(if (and plain-version? v-prefixed?)
  431. '(string-append "v" version)
  432. '(go-version->git-ref version)))))
  433. (file-name (git-file-name name version))
  434. (sha256
  435. (base32
  436. ,(bytevector->nix-base32-string
  437. (git-checkout-hash vcs-repo-url (go-version->git-ref version)
  438. (hash-algorithm sha256))))))))
  439. ((hg)
  440. `(origin
  441. (method hg-fetch)
  442. (uri (hg-reference
  443. (url ,vcs-repo-url)
  444. (changeset ,version)))
  445. (file-name (string-append name "-" version "-checkout"))
  446. (sha256
  447. (base32
  448. ;; FIXME: populate hash for hg repo checkout
  449. "0000000000000000000000000000000000000000000000000000"))))
  450. ((svn)
  451. `(origin
  452. (method svn-fetch)
  453. (uri (svn-reference
  454. (url ,vcs-repo-url)
  455. (revision (string->number version))))
  456. (file-name (string-append name "-" version "-checkout"))
  457. (sha256
  458. (base32
  459. ;; FIXME: populate hash for svn repo checkout
  460. "0000000000000000000000000000000000000000000000000000"))))
  461. (else
  462. (raise
  463. (formatted-message (G_ "unsupported vcs type '~a' for package '~a'")
  464. vcs-type vcs-repo-url)))))
  465. (define* (go-module->guix-package module-path #:key
  466. (goproxy-url "https://proxy.golang.org"))
  467. (let* ((latest-version (go-module-latest-version goproxy-url module-path))
  468. (port (fetch-go.mod goproxy-url module-path latest-version))
  469. (dependencies (map car (call-with-port port parse-go.mod)))
  470. (guix-name (go-module->guix-package-name module-path))
  471. (root-module-path (module-path->repository-root module-path))
  472. ;; The VCS type and URL are not included in goproxy information. For
  473. ;; this we need to fetch it from the official module page.
  474. (meta-data (fetch-module-meta-data root-module-path))
  475. (vcs-type (module-meta-vcs meta-data))
  476. (vcs-repo-url (module-meta-data-repo-url meta-data goproxy-url))
  477. (synopsis (go-package-synopsis root-module-path))
  478. (description (go-package-description module-path))
  479. (licenses (go-package-licenses module-path)))
  480. (values
  481. `(package
  482. (name ,guix-name)
  483. ;; Elide the "v" prefix Go uses
  484. (version ,(string-trim latest-version #\v))
  485. (source
  486. ,(vcs->origin vcs-type vcs-repo-url latest-version))
  487. (build-system go-build-system)
  488. (arguments
  489. '(#:import-path ,root-module-path))
  490. ,@(maybe-inputs (map go-module->guix-package-name dependencies))
  491. (home-page ,(format #f "https://~a" root-module-path))
  492. (synopsis ,synopsis)
  493. (description ,description)
  494. (license ,(match (and=> licenses list->licenses)
  495. ((license) license)
  496. ((licenses ...) `(list ,@licenses))
  497. (x x))))
  498. dependencies)))
  499. (define go-module->guix-package* (memoize go-module->guix-package))
  500. (define* (go-module-recursive-import package-name
  501. #:key (goproxy-url "https://proxy.golang.org"))
  502. (recursive-import
  503. package-name
  504. #:repo->guix-package (lambda* (name . _)
  505. (go-module->guix-package*
  506. name
  507. #:goproxy-url goproxy-url))
  508. #:guix-name go-module->guix-package-name))