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

To reply to this bug, email your comments to 78378 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to andrew <at> trop.in, hako <at> ultrarare.space, janneke <at> gnu.org, ludo <at> gnu.org, tanguy <at> bioneland.org, guix-patches <at> gnu.org:
bug#78378; Package guix-patches. (Sun, 11 May 2025 16:02:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Sergey Trofimov <sarg <at> sarg.org.ru>:
New bug report received and forwarded. Copy sent to andrew <at> trop.in, hako <at> ultrarare.space, janneke <at> gnu.org, ludo <at> gnu.org, tanguy <at> bioneland.org, guix-patches <at> gnu.org. (Sun, 11 May 2025 16:02:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Sergey Trofimov <sarg <at> sarg.org.ru>
To: guix-patches <at> gnu.org
Cc: Sergey Trofimov <sarg <at> sarg.org.ru>
Subject: [PATCH 0/2] home: services: Build "files" union allowing dangling
 symlinks.
Date: Sun, 11 May 2025 18:00:50 +0200
This patch enables guix home users to create arbitrary symlinks in their home
environment. I.e. a user having "/storage" directory (probably residing on
another disk partition) could symlink e.g. "~/.mail" from
"/storage/data/mail". 

Sergey Trofimov (2):
  gexp: Add symlink-to procedure.
  home: services: Build "files" union allowing dangling symlinks.

 doc/guix.texi         | 11 +++++++++++
 gnu/home/services.scm | 16 +++++++++++++++-
 guix/gexp.scm         |  5 +++++
 tests/guix-home.sh    |  8 +++++++-
 4 files changed, 38 insertions(+), 2 deletions(-)


base-commit: f6363db18636172f959e2709982bbe09b411c3d8
-- 
2.49.0





Information forwarded to guix <at> cbaines.net, gabriel <at> erlikon.ch, dev <at> jpoiret.xyz, ludo <at> gnu.org, othacehe <at> gnu.org, maxim.cournoyer <at> gmail.com, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org:
bug#78378; Package guix-patches. (Sun, 11 May 2025 16:10:02 GMT) Full text and rfc822 format available.

Message #8 received at 78378 <at> debbugs.gnu.org (full text, mbox):

From: Sergey Trofimov <sarg <at> sarg.org.ru>
To: 78378 <at> debbugs.gnu.org
Cc: Sergey Trofimov <sarg <at> sarg.org.ru>
Subject: [PATCH 1/2] gexp: Add symlink-to procedure.
Date: Sun, 11 May 2025 18:08:02 +0200
* 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(+)

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))
-- 
2.49.0





Information forwarded to andrew <at> trop.in, hako <at> ultrarare.space, janneke <at> gnu.org, ludo <at> gnu.org, tanguy <at> bioneland.org, guix-patches <at> gnu.org:
bug#78378; Package guix-patches. (Sun, 11 May 2025 16:10:02 GMT) Full text and rfc822 format available.

Message #11 received at 78378 <at> debbugs.gnu.org (full text, mbox):

From: Sergey Trofimov <sarg <at> sarg.org.ru>
To: 78378 <at> debbugs.gnu.org
Cc: Sergey Trofimov <sarg <at> sarg.org.ru>
Subject: [PATCH 2/2] home: services: Build "files" union allowing dangling
 symlinks.
Date: Sun, 11 May 2025 18:08:03 +0200
* 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
---
 gnu/home/services.scm | 16 +++++++++++++++-
 tests/guix-home.sh    |  8 +++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/gnu/home/services.scm b/gnu/home/services.scm
index 2342dc5e07..55f9365922 100644
--- a/gnu/home/services.scm
+++ b/gnu/home/services.scm
@@ -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)))))
 
 ;; Used by symlink-manager
 (define home-files-directory "files")
diff --git a/tests/guix-home.sh b/tests/guix-home.sh
index dbfe7dbd48..b8d90196f1 100644
--- a/tests/guix-home.sh
+++ b/tests/guix-home.sh
@@ -73,7 +73,9 @@ trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
                    (list `(".config/test.conf"
                            ,(plain-file
                              "tmp-file.txt"
-                             "the content of ~/.config/test.conf"))))
+                             "the content of ~/.config/test.conf"))
+
+                         `("symlink" ,(symlink-to "<test_directory>"))))
 
    (service home-bash-service-type
             (home-bash-configuration
@@ -104,6 +106,7 @@ trap 'chmod -Rf +w "$test_directory"; rm -rf "$test_directory"' EXIT
                        "# the content of bashrc-test-config.sh"))))))))
 EOF
 
+    sed -i "s,<test_directory>,$test_directory," home.scm
     echo -n "# dot-bashrc test file for guix home" > "dot-bashrc"
 
     # Check whether the graph commands work as expected.
@@ -126,6 +129,7 @@ EOF
 	guix home container home.scm -- cat '~/.config/test.conf' | \
 	    grep "the content of"
 	guix home container home.scm -- test -h '~/.bashrc'
+	guix home container home.scm -- test -h '~/symlink'
 	test "$(guix home container home.scm -- id -u)" = 1000
 	guix home container home.scm -- test -f '$HOME/sample/home.scm' && false
 	guix home container home.scm --expose="$PWD=$HOME/sample" -- \
@@ -153,6 +157,8 @@ EOF
     test -d "${HOME}/.guix-home"
     test -h "${HOME}/.bash_profile"
     test -h "${HOME}/.bashrc"
+    test -h "${HOME}/symlink"
+    test "$(readlink -f $HOME/symlink)" == "$test_directory"
     grep 'alias run="guix shell"' "$HOME/.bashrc"
     grep "alias path='echo \$PATH'" "$HOME/.bashrc"
     test "$(tail -n 2 "${HOME}/.bashrc")" == "\
-- 
2.49.0





Information forwarded to guix-patches <at> gnu.org:
bug#78378; Package guix-patches. (Mon, 12 May 2025 07:50:02 GMT) Full text and rfc822 format available.

Message #14 received at 78378 <at> debbugs.gnu.org (full text, mbox):

From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
To: Sergey Trofimov <sarg <at> sarg.org.ru>
Cc: Josselin Poiret <dev <at> jpoiret.xyz>, Tobias Geerinckx-Rice <me <at> tobias.gr>,
 Simon Tournier <zimon.toutoune <at> gmail.com>, Mathieu Othacehe <othacehe <at> gnu.org>,
 Ludovic Courtès <ludo <at> gnu.org>,
 Gabriel Wicki <gabriel <at> erlikon.ch>, 78378 <at> debbugs.gnu.org,
 Christopher Baines <guix <at> cbaines.net>
Subject: Re: [bug#78378] [PATCH 1/2] gexp: Add symlink-to procedure.
Date: Mon, 12 May 2025 16:49:08 +0900
Sergey Trofimov <sarg <at> 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 <at> gmail.com>

-- 
Thanks,
Maxim




This bug report was last modified 3 days ago.

Previous Next


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