From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id QFPLNypg12SazgAASxT56A (envelope-from ) for ; Sat, 12 Aug 2023 12:34:18 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id QGC0Nypg12Ss/QAA9RJhRA (envelope-from ) for ; Sat, 12 Aug 2023 12:34:18 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 33A405CF50 for ; Sat, 12 Aug 2023 12:34:17 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=sZH4CNxP; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1691836458; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=NuR0WxxwZo01mV6bVgEQs5ITi7rEzNmSowaiasY6kgM=; b=ps8hhlor8kuMOnXcP/LERXl5zh1tlCMtF4t04Mv+U8Y/aGFOtZPWXkw2qA42/gTU7tGzOJ G591hhHTwbuzQZdVxv3S+eq/4OARm1pIqVSBBxqlOrm7JOMfb2zF363Zn3ddyzX48ecq3U UaCGjBHa7sHW2u2ShYMZif2mwXYnoPBPW54jxWdZLmkdvtCSXUl68RzajDrgVNuDlCpwAq nFYtYTfKBXaOwXc7DytQaUv4kDn0AOKqYKTAP3Gw2MUASpbP9npPlKpDemszVduynt7O8r 40Et6WUERJIYbTbVDxY1fDXiPKMC91TwAHcWrbD6oM+Dj7xnDCoTiqsn5FnosA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=jpoiret.xyz header.s=dkim header.b=sZH4CNxP; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1691836458; a=rsa-sha256; cv=none; b=qik63JTDQYHApGHjZUhb6zBki+Jj8DXjnqqJ6Ux1ufaVI8SUV236msVWYt/PJPSlpgZaoC zufX8QLYQH0xG45sRSaAn//SBxCRx9GQYzBun+4PwWDVewxcjw0lN1+QbYxSvx0QOXeUQl aZXqpVnSuJ0Bvx6tAlcE/JSTOWr7KvRFMTvtG/agTdUUCzgKZJXjHVSMiJY8qNNOBnVVto rMQ++RzXqOBSP6pBWcX6NZzj4gAbvOHXWUTncJUa/OuN1hM4ak03sKfrKlL+6Xkiyt5ZzR /fQJ5ijpfqNURGikilUTGZdHMVWY67Dm+0JAjW2r1J1VQPLW++7VJmsuUuj4HQ== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUlwZ-0007iA-7N; Sat, 12 Aug 2023 06:34:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qUlwY-0007i2-Aa for bug-guix@gnu.org; Sat, 12 Aug 2023 06:34:02 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qUlwY-0004C8-2f for bug-guix@gnu.org; Sat, 12 Aug 2023 06:34:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qUlwX-00051c-KF for bug-guix@gnu.org; Sat, 12 Aug 2023 06:34:01 -0400 X-Loop: help-debbugs@gnu.org Subject: bug#65225: [PATCH] environment: Build the profile for the requested system. Resent-From: Josselin Poiret Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Sat, 12 Aug 2023 10:34:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65225 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: Tobias Geerinckx-Rice , 65225@debbugs.gnu.org Cc: Tobias Geerinckx-Rice , Simon Tournier , Mathieu Othacehe , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Christopher Baines , Ricardo Wurmus Received: via spool by 65225-submit@debbugs.gnu.org id=B65225.169183643419294 (code B ref 65225); Sat, 12 Aug 2023 10:34:01 +0000 Received: (at 65225) by debbugs.gnu.org; 12 Aug 2023 10:33:54 +0000 Received: from localhost ([127.0.0.1]:48787 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUlwP-000514-LP for submit@debbugs.gnu.org; Sat, 12 Aug 2023 06:33:54 -0400 Received: from jpoiret.xyz ([206.189.101.64]:43828) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUlwN-00050u-9p for 65225@debbugs.gnu.org; Sat, 12 Aug 2023 06:33:52 -0400 Received: from authenticated-user (jpoiret.xyz [206.189.101.64]) by jpoiret.xyz (Postfix) with ESMTPA id E0CA6185313; Sat, 12 Aug 2023 10:33:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpoiret.xyz; s=dkim; t=1691836428; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=NuR0WxxwZo01mV6bVgEQs5ITi7rEzNmSowaiasY6kgM=; b=sZH4CNxPbDgCTjB2yK4jI28TR9AxVINJd0Z5cJmpdXkaIHNzThWfc1VpU4hLAxnLY4hzyZ ArwpqHHf313VRm1tg6sQXvEmrRmwFp/zhLLLmJxsjnZ4NcIHCVRv/4AFaO3MoXAvpcojqP KX+drKdPIHJC6bO5Tu0a3fYVoyRrodi+NtDGOfOS8EJuTtyPV683f+97xdpz02xna2Te4b ihJZ0X+eBRFtQZb8X6BKxlNZWbTAIKzOsZ4S+63ic8SIuENlmv/nlIeQcqalJPlMNxyayT 8BuzZ+SGzfz4cYIodampC6Bd0c4UJvmiCEAq7Vo0DYPB3ER2GpSiAkJhodPgJA== In-Reply-To: <2f29e4cbc33a82509a5980bc5ddd5f8ae53cf113.1691280000.git.me@tobias.gr> References: <2f29e4cbc33a82509a5980bc5ddd5f8ae53cf113.1691280000.git.me@tobias.gr> Date: Sat, 12 Aug 2023 12:33:45 +0200 Message-ID: <871qg8o8hi.fsf@jpoiret.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Spamd-Bar: / X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Josselin Poiret From: Josselin Poiret via Bug reports for GNU Guix Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: bug-guix-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Queue-Id: 33A405CF50 X-Migadu-Scanner: mx1.migadu.com X-Spam-Score: -7.29 X-Migadu-Spam-Score: -7.29 X-TUID: /ipSn7mHMKfQ --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Tobias, Tobias Geerinckx-Rice writes: > Previously, =E2=80=98--system=3D=E2=80=99 did not affect profile hooks, m= eaning that all > packages would be built for both the host and requested systems. > > * guix/scripts/environment.scm (guix-environment*): Parameterize > %current-system to match the requested =E2=80=98--system=3D=E2=80=99. > > Reported by ekaitz in #guix. > --- > guix/scripts/environment.scm | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm > index 9712389842..27f7e53549 100644 > --- a/guix/scripts/environment.scm > +++ b/guix/scripts/environment.scm > @@ -1146,7 +1146,8 @@ (define (guix-environment* opts) > (warning (G_ "no packages specified; creating an empty environ= ment~%"))) >=20=20 > ;; Use the bootstrap Guile when requested. > - (parameterize ((%graft? (assoc-ref opts 'graft?)) > + (parameterize ((%current-system system) > + (%graft? (assoc-ref opts 'graft?)) > (%guile-for-build > (and store-needed? > (package-derivation > > base-commit: 9e71d4fd6b3893ae87cb079b57d7a8fe6e9e7914 > --=20 > 2.41.0 So, I've looked into this deeper because this fix didn't seem satisfying to me: it suggests that the implementation of profile-derivation itself is wrong, and I wanted to fix it instead. Here's what I uncovered: %current-system (applies mutatis mutandis to %current-target-system) is a Guile parameter. That means that it is accessed through a function call, and its values really depends on where that function call occurs. Now, this interacts with the store monad in a cumbersome way: monadic values in this case are functions (lambda (store) ...) returning two values, the actual output and the store. These functions are run only at the run-with-store call. Now, there are two non-equivalent ways of getting the current system in a monadic context. You can either do (mlet ((system -> (%current-system)) ...) or (mlet ((system (current-system)) ...) The former directly evaluates (%current-system), while the latter only evaluates (%current-system) when the monadic value is run! What does this mean for our case here? Well, the problem lies with how the hooks are lowered: they use (gexp->derivation ...) without the optional #:system keyword. This looks up the current system at call time with the mlet -> construct, so everything should be okay, right? Well, the hooks are run through a mapm/accumulate-builds call, which puts everything in a monadic value, effectively delaying the look-up until monadic run time. =2D-8<---------------cut here---------------start------------->8--- (mlet* %store-monad (... (extras (if (null? (manifest-entries manifest)) (return '()) (mapm/accumulate-builds (lambda (hook) (hook manifest)) hooks)))) ...) =2D-8<---------------cut here---------------end--------------->8--- At this point, I thought: =E2=80=9CWell, I could just parameterize %current-system inside the (lambda (hook) ...), and all would be well, right? Well, it didn't seem to work and I was pretty confused by it. I tested a bit and noticed that actually, contrary to what was intended (there even is a comment in gexp-derivation about it), gexp-derivation looks up the system at monadic run time! It looks like this: =2D-8<---------------cut here---------------start------------->8--- (mlet* %store-monad ( ;; The following binding forces '%current-system' and ;; '%current-target-system' to be looked up at >>=3D ;; time. (graft? (set-grafting graft?)) (system -> (or system (%current-system))) (target -> (if (eq? target 'current) (%current-target-system) target)) ...) ...) =2D-8<---------------cut here---------------end--------------->8--- Well, the issue here is that such an mlet starts by translating the graft? binding into a >>=3D call, which ends up putting the rest of the translation into a function call that will *not* be called until the monadic value is run. That means that the system and target bindings afterwards are *not* looked up at call time but at monadic run time! And sure enough, moving the (graft? ...) binding after the (target -> ...) one does solve this! IMO, this is way too complicated to keep in mind at all times, and there are bugs lurking under the surface absolutely everywhere, waiting for a corner case to be uncovered. I'll send a new patch once I've fixed and tested this further. Best, =2D-=20 Josselin Poiret --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQHEBAEBCgAuFiEEOSSM2EHGPMM23K8vUF5AuRYXGooFAmTXYAkQHGRldkBqcG9p cmV0Lnh5egAKCRBQXkC5Fhcaiq8hC/4iwT9zjVCkDNJDNsquu50m9LI5fg4myT6y ZI+1qCQp+a7Is1YEO2GlnqldFFu+jVQVUVUXGXnrK4T/IAzlKXd7yAnrthVTXd9G 8IuYJSYOchB5fOLSsa8QDkngRF7dUKk5sXOUPvsl8ZUklyBthANBxEKAUe0Qyma6 ldk1C81Ql9sUu4vyiqw0AaulHxxFJ2yJJMk3FR4qRXzFWOYhz0/a81/fO/6rtfBX +/bfr+E/j7iLjpQydTaLLzSpbNgEm5TAa6BQDm8oAbBoAN/FuC0KW3kQEQeUzrGK kONT135zQUeWzLXOoojaOxDMWgqmq+7YXg7Y8wk950ngC2//ykSU2MByLJo1em1Q prRAcHI/ITKSVDqDmfHL4HE1JkZDWTXRjx5/9CTNdMsLvopi0ng+icXqbLRx55SJ y3tgZajzhdPNURMVG4YGUslFkEYSWZv9E0VKFuJjfhEGluPPrCzpki/Xt5Y9XthC hvZQ9ZlEcGdeNTr2NI24U0x/zImDO+Q= =Za4s -----END PGP SIGNATURE----- --=-=-=--