From 520e3d267ecc3964af301ab9341462e905f234c6 Mon Sep 17 00:00:00 2001
From: Jean-Pierre De Jesus DIAZ <jean@foundationdevices.com>
Date: Tue, 28 Nov 2023 12:34:47 +0100
Subject: guix: Add target-avr?.

* guix/utils.scm (target-avr?): New procedure.
* tests/utils.scm: Add tests for target-avr? procedure.

Change-Id: Iaa0fa97a2b6bc45d45f907f43157f1548a0ba3fa
Signed-off-by: Efraim Flashner <efraim@flashner.co.il>
---
 tests/utils.scm | 12 ++++++++++++
 1 file changed, 12 insertions(+)

(limited to 'tests')

diff --git a/tests/utils.scm b/tests/utils.scm
index 648e91f242..5664165c85 100644
--- a/tests/utils.scm
+++ b/tests/utils.scm
@@ -4,6 +4,7 @@
 ;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
 ;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
 ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
+;;; Copyright © 2023 Foundation Devices, Inc. <hello@foundationdevices.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -329,6 +330,17 @@ skip these tests."
          ;; However, it isn't 32-bit.
          ,(format #f "x86_~a-linux-gnu" (expt 2 109)))))
 
+(test-equal "target-avr?"
+  '(#t #t #t #f #f)
+  (map target-avr?
+       '("avr" "avr-unknown-none"
+         ;; In addition LLVM also uses this form.
+         "avr-unknown-unknown"
+         ;; The AVR32 architecture also was made by Atmel/Microchip but it
+         ;; does not resemble the AVR family, they aren't compatible in any
+         ;; way.
+         "avr32" "avr32-unknown-none")))
+
 (test-end)
 
 (false-if-exception (delete-file temp-file))
-- 
cgit 1.4.1


From 1e47148f46e31eb99ce8ec7bc12232cf50d0ebec Mon Sep 17 00:00:00 2001
From: Ludovic Courtès <ludo@gnu.org>
Date: Fri, 10 Nov 2023 21:37:28 +0100
Subject: daemon: Implement ‘substitute-urls’ RPC.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* nix/libstore/worker-protocol.hh (PROTOCOL_VERSION): Bump.
(WorkerOp): Add ‘wopSubstituteURLs’.
* nix/nix-daemon/nix-daemon.cc (performOp): Implement it.
* guix/store.scm (%protocol-version): Bump.
(operation-id): Add ‘substitute-urls’.
(substitute-urls): New procedure.
* tests/store.scm ("substitute-urls, default")
("substitute-urls, client-specified URLs")
("substitute-urls, disabled"): New tests.

Change-Id: I2c0119500c3a1eecfa5ebf32463ffb0f173161de
---
 guix/store.scm                  | 18 +++++++++++++++---
 nix/libstore/worker-protocol.hh |  5 +++--
 nix/nix-daemon/nix-daemon.cc    | 17 +++++++++++++++++
 tests/store.scm                 | 25 +++++++++++++++++++++++--
 4 files changed, 58 insertions(+), 7 deletions(-)

(limited to 'tests')

diff --git a/guix/store.scm b/guix/store.scm
index f8e77b2cd9..97c4f32a5b 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012-2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012-2023 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2018 Jan Nieuwenhuizen <janneke@gnu.org>
 ;;; Copyright © 2019, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de>
@@ -145,6 +145,7 @@
             path-info-nar-size
 
             built-in-builders
+            substitute-urls
             references
             references/cached
             references*
@@ -199,7 +200,7 @@
             derivation-log-file
             log-file))
 
-(define %protocol-version #x163)
+(define %protocol-version #x164)
 
 (define %worker-magic-1 #x6e697863)               ; "nixc"
 (define %worker-magic-2 #x6478696f)               ; "dxio"
@@ -253,7 +254,8 @@
   (query-valid-derivers 33)
   (optimize-store 34)
   (verify-store 35)
-  (built-in-builders 80))
+  (built-in-builders 80)
+  (substitute-urls 81))
 
 (define-enumerate-type hash-algo
   ;; hash.hh
@@ -1780,6 +1782,16 @@ The result is always the empty list unless the daemon was started with
 This makes sense only when the daemon was started with '--cache-failures'."
   boolean)
 
+(define substitute-urls
+  (let ((urls (operation (substitute-urls)
+                         #f
+                         string-list)))
+    (lambda (store)
+      "Return the list of currently configured substitutes URLs for STORE, or
+#f if the daemon is too old and does not implement this RPC."
+      (and (>= (store-connection-version store) #x164)
+           (urls store)))))
+
 
 ;;;
 ;;; Per-connection caches.
diff --git a/nix/libstore/worker-protocol.hh b/nix/libstore/worker-protocol.hh
index ea67b10a5b..ef259db2a0 100644
--- a/nix/libstore/worker-protocol.hh
+++ b/nix/libstore/worker-protocol.hh
@@ -6,7 +6,7 @@ namespace nix {
 #define WORKER_MAGIC_1 0x6e697863
 #define WORKER_MAGIC_2 0x6478696f
 
-#define PROTOCOL_VERSION 0x163
+#define PROTOCOL_VERSION 0x164
 #define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
 #define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
 
@@ -44,7 +44,8 @@ typedef enum {
     wopQueryValidDerivers = 33,
     wopOptimiseStore = 34,
     wopVerifyStore = 35,
-    wopBuiltinBuilders = 80
+    wopBuiltinBuilders = 80,
+    wopSubstituteURLs = 81
 } WorkerOp;
 
 
diff --git a/nix/nix-daemon/nix-daemon.cc b/nix/nix-daemon/nix-daemon.cc
index 497de11a04..4cb05c802e 100644
--- a/nix/nix-daemon/nix-daemon.cc
+++ b/nix/nix-daemon/nix-daemon.cc
@@ -736,6 +736,23 @@ static void performOp(bool trusted, unsigned int clientVersion,
 	break;
     }
 
+    case wopSubstituteURLs: {
+	startWork();
+	Strings urls;
+	if (settings.get("build-use-substitutes", std::string("false")) == "true") {
+	    /* First check the client-provided substitute URLs, then those
+	       passed to the daemon.  */
+	    auto str = settings.get("untrusted-substitute-urls",  std::string(""));
+	    if (str.empty()) {
+		str = settings.get("substitute-urls",  std::string(""));
+	    }
+	    urls = tokenizeString<Strings>(str);
+	}
+	stopWork();
+	writeStrings(urls, to);
+	break;
+    }
+
     default:
         throw Error(format("invalid operation %1%") % op);
     }
diff --git a/tests/store.scm b/tests/store.scm
index 5df28adf0d..45948f4f43 100644
--- a/tests/store.scm
+++ b/tests/store.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012-2021, 2023 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -105,7 +105,28 @@
               "/283gqy39v3g9dxjy26rynl0zls82fmcg-guile-2.0.7/bin/guile")))
        (not (direct-store-path? (%store-prefix)))))
 
-(test-skip (if %store 0 15))
+(test-skip (if %store 0 18))
+
+(test-equal "substitute-urls, default"
+  (list (getenv "GUIX_BINARY_SUBSTITUTE_URL"))
+  (with-store store
+    (set-build-options store #:use-substitutes? #t)
+    (substitute-urls store)))
+
+(test-equal "substitute-urls, client-specified URLs"
+  '("http://substitutes.example.org"
+    "http://other.example.org")
+  (with-store store
+    (set-build-options store #:use-substitutes? #t
+                       #:substitute-urls '("http://substitutes.example.org"
+                                           "http://other.example.org"))
+    (substitute-urls store)))
+
+(test-equal "substitute-urls, disabled"
+  '()
+  (with-store store
+    (set-build-options store #:use-substitutes? #f)
+    (substitute-urls store)))
 
 (test-equal "profiles/per-user exists and is not writable"
   #o755
-- 
cgit 1.4.1


From 6aade039e1007b5fece031d80aade43e108768a4 Mon Sep 17 00:00:00 2001
From: Efraim Flashner <efraim@flashner.co.il>
Date: Tue, 28 Nov 2023 12:04:27 +0200
Subject: guix: import: Report go version for go importer.

* guix/import/go.scm (go-package, go.mod-go-version): New procedures.
(go-module->guix-package): Add the #:go keyword in the generated package
definition if the required go is newer than the default go.
* tests/go.scm (mock-http-get): Use gexps for package arguments.

Change-Id: I8d005740a442330ac307a40a53764c803ceffc4f
---
 guix/import/go.scm | 31 ++++++++++++++++++++++++++-----
 tests/go.scm       |  6 +++---
 2 files changed, 29 insertions(+), 8 deletions(-)

(limited to 'tests')

diff --git a/guix/import/go.scm b/guix/import/go.scm
index 940cdac4b0..dd9298808d 100644
--- a/guix/import/go.scm
+++ b/guix/import/go.scm
@@ -29,6 +29,7 @@
   #:use-module (guix git)
   #:use-module (guix hash)
   #:use-module (guix i18n)
+  #:use-module ((guix utils) #:select (version>?))
   #:use-module (guix diagnostics)
   #:use-module (guix import utils)
   #:use-module (guix import json)
@@ -93,6 +94,11 @@
 
 ;;; Code:
 
+(define (go-package)
+  "Return the 'go' package.  This is a lazy reference so that we don't
+depend on (gnu packages golang)."
+  (module-ref (resolve-interface '(gnu packages golang)) 'go))
+
 (define http-fetch*
   ;; Like http-fetch, but memoized and returning the body as a string.
   (memoize (lambda args
@@ -314,7 +320,7 @@ comment, or unknown) and is followed by the indicated data."
   (define-peg-pattern with all (or (and module-path version) file-path))
   (define-peg-pattern replace all (and original => with EOL))
   (define-peg-pattern replace-top body
-    (and (ignore "replace") 
+    (and (ignore "replace")
          (or (and block-start (* (or replace block-line)) block-end) replace)))
 
   ;; RetractSpec = ( Version | "[" Version "," Version "]" ) newline .
@@ -378,6 +384,17 @@ DIRECTIVE."
 ;; Prevent inlining of this procedure, which is accessed by unit tests.
 (set! go.mod-requirements go.mod-requirements)
 
+(define (go.mod-go-version go.mod)
+  "Return the minimum version of go required to specified by GO.MOD."
+  (let ((go-version (go.mod-directives go.mod 'go)))
+    (if (null? go-version)
+      ;; If the go directive is missing, go 1.16 is assumed.
+      '(version "1.16")
+      (flatten go-version))))
+
+;; Prevent inlining of this procedure, which is accessed by unit tests.
+(set! go.mod-go-version go.mod-go-version)
+
 (define-record-type <vcs>
   (%make-vcs url-prefix root-regex type)
   vcs?
@@ -610,6 +627,7 @@ When VERSION is unspecified, the latest version available is used."
                     available-versions
                     module-path))
          (content (fetch-go.mod goproxy module-path version*))
+         (min-go-version (second (go.mod-go-version (parse-go.mod content))))
          (dependencies+versions (go.mod-requirements (parse-go.mod content)))
          (dependencies (if pin-versions?
                            dependencies+versions
@@ -634,10 +652,13 @@ When VERSION is unspecified, the latest version available is used."
          ,(vcs->origin vcs-type vcs-repo-url version*))
         (build-system go-build-system)
         (arguments
-         '(#:import-path ,module-path
-           ,@(if (string=? module-path-sans-suffix root-module-path)
-                 '()
-                 `(#:unpack-path ,root-module-path))))
+         (list ,@(if (version>? min-go-version (package-version (go-package)))
+                     `(#:go ,(string->number min-go-version))
+                     '())
+               #:import-path ,module-path
+               ,@(if (string=? module-path-sans-suffix root-module-path)
+                     '()
+                     `(#:unpack-path ,root-module-path))))
         ,@(maybe-propagated-inputs
            (map (match-lambda
                   ((name version)
diff --git a/tests/go.scm b/tests/go.scm
index a70a0ddbf5..d2e8846b30 100644
--- a/tests/go.scm
+++ b/tests/go.scm
@@ -1,6 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright � 2021 Fran�ois Joulaud <francois.joulaud@radiofrance.com>
-;;; Copyright � 2021 Sarah Morgensen <iskarian@mgsn.dev>
+;;; Copyright © 2021 François Joulaud <francois.joulaud@radiofrance.com>
+;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -387,7 +387,7 @@ require github.com/kr/pretty v0.2.1
           "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5"))))
      (build-system go-build-system)
      (arguments
-      '(#:import-path "github.com/go-check/check"))
+      (list #:import-path "github.com/go-check/check"))
      (propagated-inputs
       `(("go-github-com-kr-pretty" ,go-github-com-kr-pretty)))
      (home-page "https://github.com/go-check/check")
-- 
cgit 1.4.1