Subject: [bug#76581] [PATCH 1/2] gnu: age, age-keygen: Fix --version.

From: Nicolas Graves <[email-masked]>
Date: Wed, 26 Feb 2025 10:35:32 +0100

* gnu/packages/golang-crypto.scm (go-filippo-io-age)[source]: Add
snippet to hardcode the version.
---
 gnu/packages/golang-crypto.scm | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/golang-crypto.scm b/gnu/packages/golang-crypto.scm
index b1a114dd80..3ff3c39698 100644
--- a/gnu/packages/golang-crypto.scm
+++ b/gnu/packages/golang-crypto.scm
@@ -14,7 +14,7 @@
 ;;; Copyright © 2021 Vagrant Cascadian <[email-masked]>
 ;;; Copyright © 2022 (unmatched-parenthesis <[email-masked]>
 ;;; Copyright © 2022 Tobias Geerinckx-Rice <[email-masked]>
-;;; Copyright © 2022, 2023 Nicolas Graves <[email-masked]>
+;;; Copyright © 2022, 2023, 2025 Nicolas Graves <[email-masked]>
 ;;; Copyright © 2023 Benjamin <[email-masked]>
 ;;; Copyright © 2023 Clément Lassieur <[email-masked]>
 ;;; Copyright © 2023 Felix Lechner <[email-masked]>
@@ -135,7 +135,22 @@ (define-public go-filippo-io-age
              (commit (string-append "v" version))))
        (file-name (git-file-name name version))
        (sha256
-        (base32 "183iqzmdwk4b35vxrdg2gdzd4277yr5bgbgl9brqv3w1dap5v4pm"))))
+        (base32 "183iqzmdwk4b35vxrdg2gdzd4277yr5bgbgl9brqv3w1dap5v4pm"))
+       (modules '((guix build utils)))
+       (snippet
+        #~(begin
+            (substitute* '("cmd/age/age.go"
+                           "cmd/age-keygen/keygen.go")
+              (("var Version string")
+               (format #f "var Version = ~s" #$version))
+              ;; We can as well not require runtime/debug now,
+              ;; since it's only used to get the version.
+              (("\"runtime/debug\"")
+               "")
+              (("buildInfo, ok := debug\\.ReadBuildInfo\\(\\); ok")
+               "false")
+              (("buildInfo\\.Main\\.Version")
+               ""))))))
     (build-system go-build-system)
     (arguments
      (list
-- 
2.48.1

-- 
Best regards,
Nicolas Graves