GNU bug report logs - #78378
[PATCH 0/2] home: services: Build "files" union allowing dangling symlinks.

Previous Next

Package: guix-patches;

Reported by: Sergey Trofimov <sarg <at> sarg.org.ru>

Date: Sun, 11 May 2025 16:02:02 UTC

Severity: normal

Tags: patch

Done: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Sergey Trofimov <sarg <at> sarg.org.ru>
To: 78378 <at> debbugs.gnu.org
Cc: Sergey Trofimov <sarg <at> sarg.org.ru>, Sergey Trofimov <sarg <at> sarg.org.ru>, Maxim Cournoyer <maxim.cournoyer <at> gmail.com>, Ludovic Courtès <ludo <at> gnu.org>, Christopher Baines <guix <at> cbaines.net>, Gabriel Wicki <gabriel <at> erlikon.ch>, Josselin Poiret <dev <at> jpoiret.xyz>, Mathieu Othacehe <othacehe <at> gnu.org>, Simon Tournier <zimon.toutoune <at> gmail.com>, Tobias Geerinckx-Rice <me <at> tobias.gr>
Subject: [bug#78378] [PATCH v1 1/3] gexp: Allow file-unions with dangling symlinks.
Date: Mon, 19 May 2025 11:50:08 +0200
* guix/gexp.scm (file-union): Add #:dangling-symlinks? parameter.

Change-Id: I09d44ec785fd7141b02dee2d8dc23ccc499aa933
---
 doc/guix.texi | 12 +++++++-----
 guix/gexp.scm | 19 ++++++++++---------
 2 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index fd86551787..ef8504bb3e 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -12673,11 +12673,13 @@ G-Expressions
 This is the declarative counterpart of @code{text-file*}.
 @end deffn
 
-@deffn {Procedure} file-union name files
-Return a @code{<computed-file>} that builds a directory containing all of @var{files}.
-Each item in @var{files} must be a two-element list where the first element is the
-file name to use in the new directory, and the second element is a gexp
-denoting the target file.  Here's an example:
+@deffn {Procedure} file-union name files [#:dangling-symlinks? #f]
+Return a @code{<computed-file>} that builds a directory containing all
+of @var{files}.  Each item in @var{files} must be a two-element list
+where the first element is the file name to use in the new directory,
+and the second element is a gexp denoting the target file.
+@code{#:dangling-symlinks?} controls if gexps must lower to an existing
+file.  Here's an example:
 
 @lisp
 (file-union "etc"
diff --git a/guix/gexp.scm b/guix/gexp.scm
index 8dd746eee0..85d049e26a 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -2144,7 +2144,7 @@ (define* (mixed-text-file name #:key guile #:rest text)
 
   (computed-file name build #:guile guile))
 
-(define* (file-union name files #:key guile)
+(define* (file-union name files #:key guile (dangling-symlinks? #f))
   "Return a <computed-file> that builds a directory containing all of FILES.
 Each item in FILES must be a two-element list where the first element is the
 file name to use in the new directory, and the second element is a gexp
@@ -2170,14 +2170,15 @@ (define* (file-union name files #:key guile)
                        (map (match-lambda
                               ((target source)
                                (gexp
-                                (begin
-                                  ;; Stat the source to abort early if it does
-                                  ;; not exist.
-                                  (stat (ungexp source))
-
-                                  (mkdir-p (dirname (ungexp target)))
-                                  (symlink (ungexp source)
-                                           (ungexp target))))))
+                                (let ((source (ungexp source))
+                                      (target (ungexp target)))
+                                  (unless (or (ungexp dangling-symlinks?)
+                                              (stat source #f))
+                                    (error (format #f "~a points to inexistent file or dangling symlink ~a"
+                                                   target source)))
+
+                                  (mkdir-p (dirname target))
+                                  (symlink source target)))))
                             files)))))
                  #:guile guile))
 

base-commit: 450a361532573a02389530a6a80b7821683ed41b
-- 
2.49.0





This bug report was last modified 57 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.