From d87c76525a614e6e6a6a17cf2752517ff9060b88 Mon Sep 17 00:00:00 2001 From: Hilton Chain Date: Thu, 3 Apr 2025 00:51:14 +0800 Subject: [PATCH] utils: Add go-vendored-fetch. * rosenthal/utils/download.scm: New file. --- rosenthal/utils/download.scm | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 rosenthal/utils/download.scm diff --git a/rosenthal/utils/download.scm b/rosenthal/utils/download.scm new file mode 100644 index 0000000..f871023 --- /dev/null +++ b/rosenthal/utils/download.scm @@ -0,0 +1,50 @@ +;; SPDX-FileCopyrightText: 2025 Hilton Chain +;; +;; SPDX-License-Identifier: GPL-3.0-or-later + +(define-module (rosenthal utils download) + #:use-module (guix gexp) + #:use-module (guix packages) + #:use-module (guix build-system gnu) + #:use-module (guix build-system go) + #:export (go-vendored-fetch)) + +;; 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") + + ((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))