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

This commit is contained in:
Hilton Chain 2025-05-13 20:50:07 +08:00
parent 975db02439
commit 3d4b11edc7
No known key found for this signature in database
GPG Key ID: ACC66D09CA528292
3 changed files with 151 additions and 83 deletions

View File

@ -9,8 +9,11 @@
#:use-module (guix git-download)
#:use-module (guix packages)
#:use-module (rosenthal utils download)
#:use-module (gnu packages base)
#:use-module (gnu packages dns)
#:use-module (gnu packages golang)
#:use-module (gnu packages golang-build))
#:use-module (gnu packages golang-build)
#:use-module (gnu packages linux))
(define-public cloudflared
(package
@ -92,10 +95,7 @@ a SOCKS5 proxy.")
(package
(name "tailscale")
(version "1.80.3")
(source
(origin
(method go-vendored-fetch)
(uri (origin
(source (origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/tailscale/tailscale")
@ -103,16 +103,17 @@ a SOCKS5 proxy.")
(file-name (git-file-name name version))
(sha256
(base32
"07s8kwksvd0f9r65zkrhp3sn4jrv0c8g5w0wbiv9qq950l8gdv2h"))))
(file-name (git-file-name name version))
(sha256
(base32
"0g2pzazrfl41s1gra2g3ni34ddgw32mb2rjlv8x17g3yc7axdbqa"))
(modules '((guix build utils)))
(snippet '(delete-file-recursively "tool"))))
"07s8kwksvd0f9r65zkrhp3sn4jrv0c8g5w0wbiv9qq950l8gdv2h"))
(modules '((guix build utils)))
(snippet
'(begin
(delete-file-recursively "tool")
(substitute* "net/tstun/tun_linux.go"
(("/sbin/(modprobe)" _ cmd) cmd))))))
(build-system go-build-system)
(arguments
(list
#:tests? (not (%current-target-system)) ;TODO: Run test suite.
#:go go-1.23
#:install-source? #f
#:import-path "."
@ -120,25 +121,26 @@ a SOCKS5 proxy.")
#~(list "-tags" "ts_include_cli"
(string-append
"-ldflags="
" -X tailscale.com/version.longStamp=v"
" -X tailscale.com/version.longStamp="
#$(package-version this-package)
" -X tailscale.com/version.shortStamp=v"
" -X tailscale.com/version.shortStamp="
#$(package-version this-package)))
#:test-flags ''("-skip=^TestPackageDocs$")
#:test-subdirs ''(".")
#:modules
'(((guix build gnu-build-system) #:prefix gnu:)
'((ice-9 match)
((guix build gnu-build-system) #:prefix gnu:)
(guix build go-build-system)
(guix build utils))
#:phases
#~(modify-phases %standard-phases
(replace 'unpack
(lambda args
(unsetenv "GO111MODULE")
(apply (assoc-ref gnu:%standard-phases 'unpack) args)
(unsetenv "GO111MODULE")))
(copy-recursively
#+(this-package-native-input "vendored-go-dependencies")
"vendor")))
(replace 'install-license-files
(assoc-ref gnu:%standard-phases 'install-license-files))
;; TODO: Fix command references.
(replace 'build
(lambda* (#:key build-flags parallel-build? #:allow-other-keys)
(let* ((njobs (if parallel-build? (parallel-job-count) 1)))
@ -151,12 +153,69 @@ a SOCKS5 proxy.")
,(string-append "tailscale.com/cmd/" pkg))))
'("derper"
"derpprobe"
"tailscale"
"tailscaled"
"tsidp")))))
(add-after 'install 'install-extras
(lambda _
(symlink (in-vicinity #$output "bin/tailscaled")
(in-vicinity #$output "bin/tailscale"))
(let ((tailscale
(or (which "tailscale")
(in-vicinity #$output "bin/tailscale"))))
(map
(match-lambda
((shell . path)
(let ((file (in-vicinity #$output path)))
(mkdir-p (dirname file))
(with-output-to-file file
(lambda ()
(invoke tailscale "completion" shell))))))
'(("bash" . "etc/bash_completion.d/tailscale")
("fish" . "share/fish/vendor_completions.d/tailscale.fish")
("zsh" . "share/zsh/site-functions/_tailscale"))))))
(add-after 'install 'wrap-binaries
(lambda* (#:key inputs #:allow-other-keys)
(wrap-program (in-vicinity #$output "bin/tailscaled")
`("PATH" ":" prefix
,(map (lambda (cmd)
(dirname (search-input-file inputs cmd)))
'("bin/find"
"bin/getent"
"bin/modprobe"
"sbin/ip"
"sbin/iptables"
"sbin/resolvconf"
"sbin/sysctl"))))))
(delete 'check)
(add-after 'install 'check
(lambda* (#:key tests? #:allow-other-keys)
(when tests?
(for-each
(lambda (cmd)
(invoke (string-append #$output "/bin/" cmd) "--help"))
'("derper"
"derpprobe"
"tailscaled"
"tsidp"))))))))
(native-inputs
(append
(list (origin
(method (go-mod-vendor #:go go-1.23))
(uri (package-source this-package))
(file-name "vendored-go-dependencies")
(sha256
(base32
"1lp5xqb9nmz1dqmmvdnnl0qla7zw6v25jbyf6shrl65rh270wmgk"))))
(if (%current-target-system)
(list this-package)
'())))
(inputs
(list findutils glibc iproute iptables-nft kmod openresolv procps))
(home-page "https://tailscale.com/")
(synopsis "Private WireGuard® networks made easy")
(synopsis "Mesh VPN service utilizing the WireGuard protocol and 2FA")
(description
"This package provides @command{tailscale}, which brings an easy and secure
way to use WireGuard and 2FA.")
"Tailscale is a mesh VPN service that simplifies the process of securely
connecting devices and services across various networks. It allows you to
create a private network with minimal configuration and aims to remove the
complexity of building a trusted and secure network.")
(license license:bsd-3)))

View File

@ -34,11 +34,8 @@
(define-public hugo
(package
(name "hugo")
(version "0.145.0")
(source
(origin
(method go-vendored-fetch)
(uri (origin
(version "0.147.2")
(source (origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/gohugoio/hugo")
@ -46,10 +43,7 @@
(file-name (git-file-name name version))
(sha256
(base32
"19kfij8c1ljfn8xr3mfm5c89fhp62bl0c7rx0i8726jn6dbpl9g5"))))
(sha256
(base32
"10fmva8p4hcbs2kyjggbanrmix1mf1fym549c5zdv80khpppzfnb"))))
"0j0grh8sxd6ma9g406cbcwhwgfdazc4lg3r7jmiyrw2287d218yz"))))
(build-system go-build-system)
(arguments
(list
@ -57,8 +51,10 @@
#:install-source? #f
#:import-path "."
#:build-flags
''("-tags" "extended withdeploy"
"-ldflags=-X github.com/gohugoio/hugo/common/hugo.vendorInfo=Nonguix")
#~(list "-tags" "extended withdeploy"
(string-append
"-ldflags="
" -X github.com/gohugoio/hugo/common/hugo.vendorInfo=Nonguix"))
#:test-flags ''("-skip=^TestCommands/mod|^TestCommands/server")
#:test-subdirs ''(".")
#:modules
@ -69,35 +65,52 @@
#~(modify-phases %standard-phases
(replace 'unpack
(lambda args
(unsetenv "GO111MODULE")
(apply (assoc-ref gnu:%standard-phases 'unpack) args)
(unsetenv "GO111MODULE")))
(copy-recursively
#+(this-package-native-input "vendored-go-dependencies")
"vendor")))
(replace 'install-license-files
(assoc-ref gnu:%standard-phases 'install-license-files))
(add-after 'unpack 'fix-paths
(lambda* (#:key inputs #:allow-other-keys)
(lambda* (#:key native-inputs inputs #:allow-other-keys)
(setenv "C_INCLUDE_PATH"
(string-append
(getenv "C_INCLUDE_PATH") ":"
(dirname
(dirname
(dirname
(search-input-file inputs "src/dec/alphai_dec.h"))))))
(search-input-file
(or native-inputs inputs)
"src/dec/alphai_dec.h"))))))
(with-directory-excursion "vendor/github.com/bep/gowebp"
(substitute* (find-files "internal/libwebp")
(("../../libwebp_src/(.*)\"" _ file)
(string-append (search-input-file inputs file) "\""))))
(format #f "~a\""
(search-input-file
(or native-inputs inputs) file)))))
(with-directory-excursion "vendor/github.com/bep/golibsass"
(substitute* (find-files "internal/libsass")
(("../../libsass_src/(.*)\"" _ file)
(string-append (search-input-file inputs file) "\"")))))))))
(inputs
(list (package-source libsass)
(format #f "~a\""
(search-input-file
(or native-inputs inputs) file))))))))))
(native-inputs
(list (origin
(method (go-mod-vendor #:go go-1.23))
(uri (package-source this-package))
(file-name "vendored-go-dependencies")
(sha256
(base32
"1pwq7i0y2gb4cw9nriy699wa6pqlhz42rjkzv39g355nyszwpyj8")))
(package-source libsass)
(package-source libwebp)))
(home-page "https://gohugo.io/")
(synopsis "Static site generator")
(synopsis "Static site generator written in Go")
(description
"Hugo is a static site generator written in Go, optimized for speed and
designed for flexibility.")
designed for flexibility. With its advanced templating system and fast asset
pipelines, Hugo renders a complete site in seconds, often less.")
(license license:asl2.0)))
;; TODO: Package Forgejo without vendored dependencies.

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)))