Subject: [bug#76376] [PATCH] guix: gexp: canonicalize file paths for import

From: Ludovic Courtès <[email-masked]>
Date: Fri, 21 Feb 2025 11:56:48 +0100

Hi,

Ryan Sundberg <[email-masked]> skribis:

> When we intern a file from the store during `imported-modules`, if the
> file is a symlink (e.g., from a Guix profile), a dangling symlink can be
> created in the module-import builder.
>
> Follow any symlinks before interning the files to the store, so that the
> file itself is imported and not the dangling link.
>
> See also: https://issues.guix.gnu.org/73275
>
> * guix/gexp.scm (imported-files/derivation): canonicalize-path
>
> Change-Id: Ic0af90cda7c5c5819526e455cf62300e18408dbd

[...]

>       ((final-path . (? string? file-name))
> -      (mlet %store-monad ((file (interned-file file-name
> +      (mlet %store-monad ((file (interned-file (canonicalize-path file-name)
>                                                 (basename final-path))))

Instead of calling ‘canonicalize-path’, which leads to many syscalls,
I’d suggest:

   (interned-file file-name (basename final-path)
                  #:recursive? #f)

I believe that would have the desired effect.

Could you also add a test that reproduces the problem?

Thanks,
Ludo’.