From a8afb9aed320d3d3ce026936cd5fc2bdd65b331b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Tue, 7 Jul 2015 22:57:54 +0200
Subject: [PATCH] store: 'run-with-store' initializes %CURRENT-TARGET-SYSTEM to
 #f.

* guix/store.scm (run-with-store): Set %CURRENT-TARGET-SYSTEM to #f.
* tests/gexp.scm ("gexp->derivation vs. %current-target-system"): New test.
---
 guix/store.scm |  6 +++++-
 tests/gexp.scm | 11 +++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/guix/store.scm b/guix/store.scm
index 7b13334952c..39e5faf6c85 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -996,8 +996,12 @@ (define* (run-with-store store mval
                          (system (%current-system)))
   "Run MVAL, a monadic value in the store monad, in STORE, an open store
 connection, and return the result."
+  ;; Initialize the dynamic bindings here to avoid bad surprises.  The
+  ;; difficulty lies in the fact that dynamic bindings are resolved at
+  ;; bind-time and not at call time, which can be disconcerting.
   (parameterize ((%guile-for-build guile-for-build)
-                 (%current-system system))
+                 (%current-system system)
+                 (%current-target-system #f))
     (call-with-values (lambda ()
                         (run-with-state mval store))
       (lambda (result store)
diff --git a/tests/gexp.scm b/tests/gexp.scm
index 32031663f55..5c9a4fc031a 100644
--- a/tests/gexp.scm
+++ b/tests/gexp.scm
@@ -636,6 +636,17 @@ (define shebang
                                             file)))))
       #:guile-for-build (package-derivation %store %bootstrap-guile))))
 
+(test-assert "gexp->derivation vs. %current-target-system"
+  (let ((mval (gexp->derivation "foo"
+                                #~(begin
+                                    (mkdir #$output)
+                                    (foo #+gnu-make))
+                                #:target #f)))
+    ;; The value of %CURRENT-TARGET-SYSTEM at bind-time should have no
+    ;; influence.
+    (parameterize ((%current-target-system "fooooo"))
+      (derivation? (run-with-store %store mval)))))
+
 (test-assert "printer"
   (string-match "^#<gexp \\(string-append .*#<package coreutils.*\
  \"/bin/uname\"\\) [[:xdigit:]]+>$"
-- 
GitLab