unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: Leo Prikler <leo.prikler@edu.uni-graz.at>
Cc: 42688@debbugs.gnu.org
Subject: bug#42688: Running a script with `guix repl` doesn't "see" additional channels using (%package-module-path)
Date: Thu, 17 Sep 2020 17:31:05 +0200	[thread overview]
Message-ID: <874knws9mu.fsf@gnu.org> (raw)
In-Reply-To: <dd34fe61016d7c2d9e7f9f0043927f94760f52b9.camel@edu.uni-graz.at> (Leo Prikler's message of "Wed, 16 Sep 2020 17:16:52 +0200")

[-- Attachment #1: Type: text/plain, Size: 1999 bytes --]

Hi Leo,

Leo Prikler <leo.prikler@edu.uni-graz.at> skribis:

> I've finally figured out, what causes this issue.
>
> Guix repl uses the following code to call scripts:
> ```
>     (unless (null? script)
>       ;; Run script
>       (save-module-excursion
>        (lambda ()
>          (set-program-arguments script)
>          (set-user-module)
>          (load-in-vicinity "." (car script)))))
> ```
>
> But `guix describe` (which is used to initialize %package-module-path)
> has the following:
>
> ```
> (define current-profile
>   (mlambda ()
>     "Return the profile (created by 'guix pull') the calling process
> lives in,
> or #f if this is not applicable."
>     (match (command-line)
>       ((program . _)
>        (and (string-suffix? "/bin/guix" program)
>            [...])))))
>
> (define current-profile-entries [...])
> (define current-channel-entries [...])
> (define package-path-entries [...])
> ```
>
> Each of these procedures depends on the previous, building up a chain
> that fails exactly in the case where we (set-program-arguments [...])
> with a script other than the current channel's guix (which is probably
> the way you'd want to use `guix repl`).  

Good catch!

> There are some ways of resolving this.  One would be to access earlier
> versions of "command-line" – it does resolve to a fluid, but that fluid
> itself is not exposed to Guile.  Perhaps there might be some FFI magic
> to access it.

‘scm_program_arguments_fluid’ is marked as SCM_INTERNAL, so it’s really
inaccessible.

However, perhaps we could save the initial value of (program-arguments)
in (guix ui) and use that in (guix describe)?

> On the other hand, we could patch `guix repl` to initialize %package-
> module-path earlier (still leaving `guix describe` broken) or somehow
> try to work around that issue in `guix describe`.

Initializing (%package-module-path) earlier sounds like a good idea too,
maybe like this:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 743 bytes --]

diff --git a/guix/scripts/repl.scm b/guix/scripts/repl.scm
index 7d4e474e92..b672489ed6 100644
--- a/guix/scripts/repl.scm
+++ b/guix/scripts/repl.scm
@@ -22,6 +22,7 @@
   #:use-module (guix ui)
   #:use-module (guix scripts)
   #:use-module (guix repl)
+  #:autoload   (gnu packages) (%package-module-path)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-37)
@@ -173,6 +174,10 @@ call THUNK."
   (with-error-handling
 
     (unless (null? script)
+      ;; Before running SCRIPT, initialize %PACKAGE-MODULE-PATH so that it
+      ;; contains the user's channels (the statement triggers an autoload).
+      (%package-module-path)
+
       ;; Run script
       (save-module-excursion
        (lambda ()

[-- Attachment #3: Type: text/plain, Size: 28 bytes --]


?

Thanks!

Ludo’.

  reply	other threads:[~2020-09-17 15:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-03  3:33 bug#42688: Running a script with `guix repl` doesn't "see" additional channels using (%package-module-path) pkill9
2020-09-16 14:15 ` zimoun
2020-09-16 15:16 ` Leo Prikler
2020-09-17 15:31   ` Ludovic Courtès [this message]
2020-09-17 16:15     ` Leo Prikler
2020-09-17 19:10       ` Ludovic Courtès
2020-09-17 19:56         ` Leo Prikler
2020-09-19 21:03           ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874knws9mu.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=42688@debbugs.gnu.org \
    --cc=leo.prikler@edu.uni-graz.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).