utils: Update ‘go mod vendor’ based fetch implementation.

This commit is contained in:
Hilton Chain committed 2025-05-15 02:03:24 +08:00
1 parent 975db02439
commit 3d4b11edc7
3 files changed
+151 -83

No files matched your search

+36 -40
View File
@@ -6,45 +6,41 @@
#:use-module (guix gexp)
#:use-module (guix packages)
#:use-module (guix build-system gnu)
#:use-module (guix build-system go)
#:export (go-vendored-fetch))
#:export (go-mod-vendor))
;; NOTE: This approach shouldn't be upstreamed.
(define* (go-vendored-fetch src hash-algo hash
#:optional name
#:key (system (%current-system))
(go
(module-ref
(resolve-interface '(gnu packages golang))
;; Use latest Go in Guix.
'go-1.23))
(nss-certs
(module-ref
(resolve-interface '(gnu packages certs))
'nss-certs)))
(gexp->derivation
(or name
(string-append (origin-file-name src) "-vendored"))
(with-imported-modules %default-gnu-imported-modules
#~(begin
(use-modules (guix build gnu-build-system)
(guix build utils))
(setenv "GOCACHE" "/tmp/go")
(setenv "GOMODCACHE" "/tmp/gomod")
(setenv "SSL_CERT_DIR" #+(file-append nss-certs "/etc/ssl/certs"))
;; Support Unicode in file name.
(setlocale LC_ALL "C.UTF-8")
;;;
;;; ‘go mod vendor’ based fetcher
;;;
((assoc-ref %standard-phases 'unpack) #:source #+src)
(invoke #+(file-append go "/bin/go") "mod" "vendor")
(copy-recursively "." #$output)))
#:system system
#:hash-algo hash-algo
#:hash hash
;; Is a directory.
#:recursive? #t
;; Honor the user's proxy and locale settings.
#:leaked-env-vars '("http_proxy" "https_proxy"
"LC_ALL" "LC_MESSAGES" "LANG"
"COLUMNS")
#:local-build? #t))
(define* (go-mod-vendor #:key go)
(lambda* (src hash-algo hash #:optional name #:key (system (%current-system)))
(define nss-certs
(module-ref (resolve-interface '(gnu packages certs)) 'nss-certs))
(gexp->derivation
(or name "vendored-go-dependencies")
(with-imported-modules %default-gnu-imported-modules
#~(begin
(use-modules (guix build gnu-build-system)
(guix build utils))
;; Support Unicode in file name.
(setlocale LC_ALL "C.UTF-8")
;; For HTTPS support.
(setenv "SSL_CERT_DIR" #+(file-append nss-certs "/etc/ssl/certs"))
((assoc-ref %standard-phases 'unpack) #:source #+src)
(invoke #+(file-append go "/bin/go") "mod" "vendor")
(copy-recursively "vendor" #$output)))
#:system system
#:hash-algo hash-algo
#:hash hash
;; Is a directory.
#:recursive? #t
#:env-vars '(("GOCACHE" . "/tmp/go-cache")
("GOPATH" . "/tmp/go"))
;; Honor the user's proxy and locale settings.
#:leaked-env-vars '("GOPROXY"
"http_proxy" "https_proxy"
"LC_ALL" "LC_MESSAGES" "LANG"
"COLUMNS")
#:local-build? #t)))