Subject: Re: [bug#76143] [PATCH] gnu: Canonicalize paths before comparing.

From: Noé Lopez <[email-masked]>
Date: Fri, 21 Feb 2025 16:42:07 +0100

Ludovic Courtès <[email-masked]> writes:

> Hi,
>
> Noé Lopez <[email-masked]> skribis:
>
>> The problem I faced was that I needed to create environment variables by
>> hand so that I could load guile code (including guix’s) in a C program
>> with no external environment (the packagekit daemon).  It would fail
>> because of not finding patches since I had a trailing slash in my path.
>
> I don’t fully understand the situation.  My suggestion (but perhaps
> you’re already doing that) would be for PackageKit to invoke ‘guix
> repl’, not ‘guile’.  The raison d’être of ‘guix repl’ was precisely to
> have the load path for Guix and all its dependencies properly set up.
>

Let me try to explain the situation better:

The Guix channel has a special case for where it stores its patches, so
guix needs to detect whether a directory is the Guix source to append
"/gnu/packages/patches" to it:

gnu/packages.scm(166)
(define %patch-path
  (make-parameter
   (map (lambda (directory)
          (if (string=? directory %distro-root-directory)
              (string-append directory "/gnu/packages/patches")
              directory))
        %load-path)))

The comparison is done with string=?, which is a very weak way of
comparing directories, as you know.  But the directory list is supplied
by the environment, so its up to the user to set the path exactly equal
to %distro-root-directory.

Obviously, this can fail in many ways if the user is not using guix
through pre-inst-env or guix repl.  My patch fixes that by comparing
with stat, making sure all paths to the guix source work.

For PackageKit specifically, I am using guix through guile’s C api and
needed to set the environment by hand, I fixed it by removing the
trailing slash.

Is that clearer?

All the best,
Noé