[bug#78378,1/2] gexp: Add symlink-to procedure.

Message ID 043c83e23cd42da9c61d0e4f5bf5fb7299332a49.1746978699.git.sarg@sarg.org.ru
State New
Headers
Series home: services: Build "files" union allowing dangling symlinks. |

Commit Message

Sergey Trofimov May 11, 2025, 4:08 p.m. UTC
  * guix/gexp.scm (symlink-to): New procedure.
* doc/guix.texi (G-Expressions): Document it.

Change-Id: I7c1ba3a29a4e5350cb4f196185b7171c4750b6b8
---
 doc/guix.texi | 11 +++++++++++
 guix/gexp.scm |  5 +++++
 2 files changed, 16 insertions(+)
  

Comments

Maxim Cournoyer May 12, 2025, 7:49 a.m. UTC | #1
Sergey Trofimov <sarg@sarg.org.ru> writes:

> * guix/gexp.scm (symlink-to): New procedure.
> * doc/guix.texi (G-Expressions): Document it.
>
> Change-Id: I7c1ba3a29a4e5350cb4f196185b7171c4750b6b8

Reviewed-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
  

Patch

diff --git a/doc/guix.texi b/doc/guix.texi
index cbc4dd0fc9..ebc8a5e5d3 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -12689,6 +12689,17 @@  G-Expressions
 This yields an @code{etc} directory containing these two files.
 @end deffn
 
+@deffn {Procedure} symlink-to target
+Return a @code{<computed-file>} that is a symbolic link to target.
+Note, that the target does not need to exist at the build time.  One of
+uses is to put arbitrary symlinks into user's home:
+
+@lisp
+(service home-files-service-type
+  `(("Sync" ,(symlink-to "/storage/Sync"))))
+@end lisp
+@end deffn
+
 @deffn {Procedure} directory-union name things
 Return a directory that is the union of @var{things}, where @var{things} is a list of
 file-like objects denoting directories.  For example:
diff --git a/guix/gexp.scm b/guix/gexp.scm
index 8dd746eee0..ef83c671ec 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -119,6 +119,7 @@  (define-module (guix gexp)
             file-union
             directory-union
             references-file
+            symlink-to
 
             imported-files
             imported-modules
@@ -2181,6 +2182,10 @@  (define* (file-union name files #:key guile)
                             files)))))
                  #:guile guile))
 
+(define (symlink-to target)
+  "Return an object that is a symlink to TARGET."
+  (computed-file "link" (gexp (symlink (ungexp target) (ungexp output)))))
+
 (define* (directory-union name things
                           #:key (copy? #f) (quiet? #f)
                           (resolve-collision 'resolve-collision/default))