Subject: [PATCH v3 5/7] gnu: nss: Clean up.

From: Ian Eure <[email-masked]>
Date: Wed, 7 May 2025 17:06:07 -0700

Platform-specific build conditionals currently use ungexp to inject code into
the build phase: #$@(if ... #~(...) #~(...)).  Change these to use unless/when
where appropriate, and ungexp the test value instead of the whole form.

* gnu/packages/nss.scm (nss): Clean up gexps.
* gnu/packages/nss.scm (nss): Extract URI code into `nss-uri'.
* gnu/packages/nss.scm (nss-uri): New variable.

Change-Id: I5843eb5bf80f01650e0e87a9c479d5d1ab187f9e
---
 gnu/packages/nss.scm | 46 ++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/gnu/packages/nss.scm b/gnu/packages/nss.scm
index abaee7e980..1deb92c00f 100644
--- a/gnu/packages/nss.scm
+++ b/gnu/packages/nss.scm
@@ -95,8 +95,16 @@ (define-public nspr
 in the Mozilla clients.")
     (license license:mpl2.0)))
 
-
-;; nss should track ESRs, but currently doesn't.  3.102.1 is the current ESR.
+(define (nss-uri version)
+  (let* ((versions (string-split version #\.))
+         (directory-version (string-join versions "_"))
+         ;; 3.101.3 release has a typo in the filename.
+         (filename-version
+          (if (string=? "3.101.3" version) "3.101_3" version)))
+    (string-append
+     "https://ftp.mozilla.org/pub/mozilla.org/security/nss/"
+     "releases/NSS_" directory-version "_RTM/src/"
+     "nss-" filename-version ".tar.gz")))
 
 (define-public nss
   (package
@@ -107,12 +115,7 @@ (define-public nss
     (version "3.99")
     (source (origin
               (method url-fetch)
-              (uri (let ((version-with-underscores
-                          (string-join (string-split version #\.) "_")))
-                     (string-append
-                      "https://ftp.mozilla.org/pub/mozilla.org/security/nss/"
-                      "releases/NSS_" version-with-underscores "_RTM/src/"
-                      "nss-" version ".tar.gz")))
+              (uri (nss-uri version))
               (sha256
                (base32
                 "1g89ig40gfi1sp02gybvl2z818lawcnrqjzsws36cdva834c5maw"))
@@ -185,13 +188,12 @@ (define-public nss
               (setenv "CCC" #$(cxx-for-target))
               (setenv "NATIVE_CC" "gcc")
               ;; No VSX on powerpc-linux.
-              #$@(if (target-ppc32?)
-                     #~((setenv "NSS_DISABLE_CRYPTO_VSX" "1"))
-                     #~())
+              (when #$(target-ppc32?)
+                (setenv "NSS_DISABLE_CRYPTO_VSX" "1"))
+
               ;; Tells NSS to build for the 64-bit ABI if we are 64-bit system.
-              #$@(if (target-64bit?)
-                     #~((setenv "USE_64" "1"))
-                     #~())))
+              (when #$(target-64bit?)
+                (setenv "USE_64" "1"))))
           (replace 'check
             (lambda* (#:key tests? #:allow-other-keys)
               (if tests?
@@ -210,15 +212,13 @@ (define-public nss
                     (substitute* "nss/tests/dbtests/dbtests.sh"
                       ((" -lt 5") " -lt 50"))
 
-                    #$@(if (target-64bit?)
-                           '()
-                           ;; The script fails to determine the source
-                           ;; directory when running under 'datefudge' (see
-                           ;; <https://issues.guix.gnu.org/72239>).  Help it.
-                           #~((substitute* "nss/tests/gtests/gtests.sh"
-                                (("SOURCE_DIR=.*")
-                                 (string-append "SOURCE_DIR=" (getcwd) "/nss\n")))))
-
+                    (unless #$(target-64bit?)
+                      ;; The script fails to determine the source
+                      ;; directory when running under 'datefudge' (see
+                      ;; <https://issues.guix.gnu.org/72239>).  Help it.
+                      ((substitute* "nss/tests/gtests/gtests.sh"
+                         (("SOURCE_DIR=.*")
+                          (string-append "SOURCE_DIR=" (getcwd) "/nss\n")))))
 
                     (let ((release-date (getenv "GUIX_NSS_RELEASE_DATE")))
                       (when (string=? "" release-date)
-- 
2.49.0