Subject: Re: [bug#78378] [PATCH 2/2] home: services: Build "files" union allowing dangling symlinks.

From: Ludovic Courtès <[email-masked]>
Date: Sun, 18 May 2025 22:28:30 +0200

Hi Sergey,

Sergey Trofimov <[email-masked]> writes:

> * gnu/home/services.scm (files->files-directory): Build file union
> without checking for existence of included items.
>
> * tests/guix-home.sh: Verify symlinking files out of store works.
>
> Change-Id: I94054003f4a6be944252ce7a397cf56f0b979554

[...]

> @@ -343,7 +343,21 @@ (define (files->files-directory files)
>    ;; leading to a build failure of "files.drv".
>    (assert-no-duplicates files)
>  
> -  (file-union "files" files))
> +  ;; Compute the file-union allowing dangling symlinks
> +  ;; This enables creating symlinks to locations out of store
> +  (computed-file
> +   "files"
> +   (with-imported-modules '((guix build utils))
> +     #~(begin
> +         (use-modules (guix build utils)
> +                      (ice-9 match))
> +         (mkdir #$output)
> +         (chdir #$output)
> +         (for-each (match-lambda
> +                     ((target source)
> +                      (mkdir-p (dirname target))
> +                      (symlink source target)))
> +                   '#$files)))))

Instead of more or less duplicating ‘file-union’, how about adding a
#:dangling-symlinks? argument to ‘file-union’ that would default to #f?

When set to #t, the ‘stat’ call would not be emitted.

That would reduce code duplication and make the intent clearer IMO.

Ludo’.