GNU bug report logs - #68857
gnu: home: dotfiles: Avoid creating extra directory in $HOME.

Previous Next

Package: guix-patches;

Reported by: paul <goodoldpaul <at> autistici.org>

Date: Wed, 31 Jan 2024 22:17:02 UTC

Severity: normal

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 68857 in the body.
You can then email your comments to 68857 AT debbugs.gnu.org in the normal way.

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

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


Report forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Wed, 31 Jan 2024 22:17:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to paul <goodoldpaul <at> autistici.org>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Wed, 31 Jan 2024 22:17:02 GMT) Full text and rfc822 format available.

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

From: paul <goodoldpaul <at> autistici.org>
To: guix-patches <at> gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>,
 Sergey Trofimov <sarg <at> sarg.org.ru>, 68848 <at> debbugs.gnu.org, janneke <at> gnu.org
Subject: gnu: home: dotfiles: Avoid creating extra directory in $HOME.
Date: Wed, 31 Jan 2024 23:15:47 +0100
Hello,

I'm sending a patch supposed to fix https://issues.guix.gnu.org/68848  . 
Please let me know if this is ok for you and fixes your issues.


Thank you,


giacomo





Information forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Wed, 31 Jan 2024 22:19:01 GMT) Full text and rfc822 format available.

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

From: Giacomo Leidi <goodoldpaul <at> autistici.org>
To: 68857 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul <at> autistici.org>
Subject: [PATCH] gnu: home: dotfiles: Avoid creating extra directory in $HOME.
Date: Wed, 31 Jan 2024 23:17:48 +0100
This patch applies the fix from https://issues.guix.gnu.org/60521#43 ,
it is supposed to fix https://issues.guix.gnu.org/68848 .

* gnu/home/services/dotfiles.scm (import-dotfiles)[strip]: Drop extra
directory.

Change-Id: I98b747396e1fc8a8925204cde2bb705019ce2c1d
---
 gnu/home/services/dotfiles.scm | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gnu/home/services/dotfiles.scm b/gnu/home/services/dotfiles.scm
index 6a740c42ce..fc842f1fb3 100644
--- a/gnu/home/services/dotfiles.scm
+++ b/gnu/home/services/dotfiles.scm
@@ -58,7 +58,11 @@ (define (import-dotfiles directory files)
 generated by recursively visiting DIRECTORY and mapping its contents to the
 user's home directory, excluding files that match any of the patterns in EXCLUDED."
   (define (strip file)
-    (string-drop file (+ 1 (string-length directory))))
+    (string-join
+     (cdr
+      (string-split (string-drop file (+ 1 (string-length directory)))
+                    #\/))
+     "/"))
 
   (define (format file)
     ;; Remove from FILE characters that cannot be used in the store.

base-commit: bf7991a8c767abd32cfb2c92e3d57665a7cabf00
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Wed, 07 Feb 2024 00:55:02 GMT) Full text and rfc822 format available.

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

From: paul <goodoldpaul <at> autistici.org>
To: 68857 <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>,
 Sergey Trofimov <sarg <at> sarg.org.ru>, andrew <at> trop.in, janneke <at> gnu.org
Subject: Re: [bug#68857] [PATCH] gnu: home: dotfiles: Avoid creating extra
 directory in $HOME.
Date: Wed, 7 Feb 2024 01:54:27 +0100
Hi Janneke,

could you try whether this patch solves 
https://issues.guix.gnu.org/68848 for you?

Thank you for your time,

giacomo





Information forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Wed, 07 Feb 2024 08:07:01 GMT) Full text and rfc822 format available.

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

From: Janneke Nieuwenhuizen <janneke <at> gnu.org>
To: paul <goodoldpaul <at> autistici.org>
Cc: Ludovic Courtès <ludo <at> gnu.org>,
 Sergey Trofimov <sarg <at> sarg.org.ru>, 68857 <at> debbugs.gnu.org, andrew <at> trop.in
Subject: Re: [bug#68857] [PATCH] gnu: home: dotfiles: Avoid creating extra
 directory in $HOME.
Date: Wed, 07 Feb 2024 09:05:33 +0100
paul writes:

Hi Paul,

> could you try whether this patch solves
> https://issues.guix.gnu.org/68848 for you?

Yes, that fixes it.  Although I would rather write it something like

--8<---------------cut here---------------start------------->8---
(define (strip file-name)
  (let ((dotfile-name (string-drop file-name (+1 (string-length directory)))))
    (match (string-split dotfile-name #\/)
      ((package parts ...)
       (string-join parts "/")))))
--8<---------------cut here---------------end--------------->8---

> Thank you for your time,

No problem, somehow I looked for a patch and didn't see it before.

Thanks for the ping and for fixing this.

Greetings,
Janneke

-- 
Janneke Nieuwenhuizen <janneke <at> gnu.org>  | GNU LilyPond https://LilyPond.org
Freelance IT https://www.JoyOfSource.com | Avatar® https://AvatarAcademy.com




Information forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Wed, 07 Feb 2024 08:38:02 GMT) Full text and rfc822 format available.

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

From: Janneke Nieuwenhuizen <janneke <at> gnu.org>
To: paul <goodoldpaul <at> autistici.org>
Cc: Ludovic Courtès <ludo <at> gnu.org>,
 Sergey Trofimov <sarg <at> sarg.org.ru>, 68857 <at> debbugs.gnu.org, andrew <at> trop.in
Subject: Re: [bug#68857] [PATCH] gnu: home: dotfiles: Avoid creating extra
 directory in $HOME.
Date: Wed, 07 Feb 2024 09:37:30 +0100
Janneke Nieuwenhuizen writes:

> paul writes:
>
> Hi Paul,
>
>> could you try whether this patch solves
>> https://issues.guix.gnu.org/68848 for you?
>
> Yes, that fixes it.  Although I would rather write it something like
>
> (define (strip file-name)
>   (let ((dotfile-name (string-drop file-name (+1 (string-length directory)))))

Err that should have been 1+, of course, so

--8<---------------cut here---------------start------------->8---
(define (strip file-name)
  (let ((dotfile-name (string-drop file-name (1+ (string-length directory)))))
    (match (string-split dotfile-name #\/)
      ((package parts ...)
       (string-join parts "/")))))
--8<---------------cut here---------------end--------------->8---

-- 
Janneke Nieuwenhuizen <janneke <at> gnu.org>  | GNU LilyPond https://LilyPond.org
Freelance IT https://www.JoyOfSource.com | Avatar® https://AvatarAcademy.com




Information forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Fri, 16 Feb 2024 17:18:02 GMT) Full text and rfc822 format available.

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

From: paul <goodoldpaul <at> autistici.org>
To: 68857 <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>,
 Sergey Trofimov <sarg <at> sarg.org.ru>, janneke <at> gnu.org
Subject: Re: [bug#68857] [PATCH] gnu: home: dotfiles: Avoid creating extra
 directory in $HOME.
Date: Fri, 16 Feb 2024 18:16:31 +0100
Hi everyone,

thank you for your help and comments so far. I have a proposal that should:

- solve https://issues.guix.gnu.org/68848

- allow for both plain and GNU Stow's layouts

- for GNU Stow layouts, allows to select a subset of application 
dotfiles to be provisioned in the user's home directory. Please Sergey 
let me know if this covers your use case .


Ludo' , Janneke, let me know your thoughts on this v2 and if it works 
for your directory layouts. Thank you again everyone for your efforts.


giacomo





Information forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Fri, 16 Feb 2024 17:19:01 GMT) Full text and rfc822 format available.

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

From: Giacomo Leidi <goodoldpaul <at> autistici.org>
To: 68857 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul <at> autistici.org>
Subject: [PATCH v2] gnu: home: dotfiles: Properly support both plain and Stow
 directory layouts.
Date: Fri, 16 Feb 2024 18:17:19 +0100
The current implementation of the home-dotfiles-service-type contradicts
the Guix manual (see https://issues.guix.gnu.org/68848 ). This patch
properly implements both the plain and Stow dotfiles directory layouts.

It does so by creating a new record type for each directory layout. This
approach, compared to having a single field in
home-dotfiles-configuration,
allows for having different layouts for different directories and to
carry additional information that might be required for some layouts.

Implementing a new layout should just be a matter of creating a new
record type, defining a strip-*-dotfile procedure and plugging them into
the home-dotfiles-service-type.

* gnu/home/services/dotfiles (home-dotfiles-stow-directory): New
variable;
(home-dotfiles-plain-directory): new variable;
(home-dotfiles-configuration): migrate to (gnu services configuration);
(strip-stow-dotfile): new variable;
(strip-plain-dotfile): new variable;
(home-dotfiles-configuration->files): use the new record types;
[directory-contents]: allow for
selecting a subset of application dotfile directories;
* doc/guix.texi: document the new layouts.

Change-Id: I2e96037608353e360828290f055ec5271cfdfd48
---
 doc/guix.texi                  | 147 ++++++++++++++++++++++++++++-----
 gnu/home/services/dotfiles.scm | 143 ++++++++++++++++++++++++++------
 2 files changed, 244 insertions(+), 46 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 04119a5955..21adfb1fc0 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -44368,17 +44368,39 @@ directory, and some way of automatically deploy changes to their user home.
 @cindex Stow-like dot file management
 The @code{home-dotfiles-service-type} from @code{(gnu home services dotfiles)}
 is designed to ease the way into using Guix Home for this kind of users,
-allowing them to point the service to their dotfiles directory, which must
-follow the layout suggested by
-@uref{https://www.gnu.org/software/stow/, GNU Stow},
-and have their dotfiles automatically deployed to their user home, without
+allowing them to point the service to their dotfiles directory without
 migrating them to Guix native configurations.
 
-The dotfiles directory layout is expected to be structured as follows. Please
-keep in mind that it is advisable to keep your dotfiles directories under
+Please keep in mind that it is advisable to keep your dotfiles directories under
 version control, for example in the same repository where you'd track your
 Guix Home configuration.
 
+There are two supported dotfiles directory layouts, for now. The
+@code{home-dotfiles-plain-directory} layout, which is structured as follows:
+
+@example
+~$ tree -a ./dotfiles/
+dotfiles/
+├── .gitconfig
+├── .gnupg
+│   ├── gpg-agent.conf
+│   └── gpg.conf
+├── .guile
+├── .config
+│   ├── guix
+│   │   └── channels.scm
+│   └── nixpkgs
+│       └── config.nix
+├── .nix-channels
+├── .tmux.conf
+└── .vimrc
+@end example
+
+and the @code{home-dotfiles-stow-directory} layout, which must
+follow the layout suggested by
+@uref{https://www.gnu.org/software/stow/, GNU Stow} and presents and additional
+application specific directory layer, just like:
+
 @example
 ~$ tree -a ./dotfiles/
 dotfiles/
@@ -44408,8 +44430,9 @@ dotfiles/
 @end example
 
 For an informal specification please refer to the Stow manual
-(@pxref{Top,,, stow, Introduction}). A suitable configuration would then
-be:
+(@pxref{Top,,, stow, Introduction}).
+
+A suitable configuration with a @emph{plain} layout could be:
 
 @lisp
 (home-environment
@@ -44417,7 +44440,10 @@ be:
   (services
     (service home-dotfiles-service-type
              (home-dotfiles-configuration
-               (directories (list "./dotfiles"))))))
+               (directories
+                 (list
+                   (home-dotfiles-plain-directory
+                     (name "./dotfiles"))))))))
 @end lisp
 
 The expected home directory state would then be:
@@ -44444,32 +44470,113 @@ Return a service which is very similiar to @code{home-files-service-type}
 (and actually extends it), but designed to ease the way into using Guix
 Home for users that already track their dotfiles under some kind of version
 control.  This service allows users to point Guix Home to their dotfiles
-directory and have their files automatically deployed to their home directory
-just like Stow would, without migrating all of their dotfiles to Guix native
+directory and have their files automatically provisioned to their home
+directory, without migrating all of their dotfiles to Guix native
 configurations.
 @end defvar
 
+@c %start of fragment
+
 @deftp {Data Type} home-dotfiles-configuration
 Available @code{home-dotfiles-configuration} fields are:
 
 @table @asis
-@item @code{source-directory} (default: @code{(current-source-directory)})
-The path where dotfile directories are resolved. By default dotfile directories
-are resolved relative the source location where
+@item @code{source-directory} (default: @code{(current-source-directory)}) (type: string)
+The path where dotfile directories are resolved.  By default dotfile
+directories are resolved relative the source location where
 @code{home-dotfiles-configuration} appears.
 
-@item @code{directories} (type: list-of-strings)
-The list of dotfiles directories where @code{home-dotfiles-service-type} will
-look for application dotfiles.
+@item @code{directories} (default: @code{'()}) (type: list-of-plain-or-stow-directories)
+The list of dotfiles directories where @code{home-dotfiles-service-type}
+will look for application dotfiles.  Each element of the list is supposed to be
+either a @code{home-dotfiles-plain-directory} or a
+@code{home-dotfiles-stow-directory} record.
+
+@item @code{excluded} (default: @code{'(".*~" ".*\\.swp" "\\.git" "\\.gitignore")}) (type: list-of-strings)
+The list of file patterns @code{home-dotfiles-service-type} will exclude
+while visiting each one of the @code{directories}.
+
+@end table
+
+@end deftp
+
+
+@c %end of fragment
+
+@c %start of fragment
+
+@deftp {Data Type} home-dotfiles-plain-directory
+
+This record represents the simplest layout supported.  In this layout the
+dotfiles directory contains a tree of files which will be directly mapped into
+the user directory:
+
+@example
+~$ tree -a ./dotfiles/
+dotfiles/
+├── .guile
+├── .config
+│   └── guix
+│       └── channels.scm
+├── .tmux.conf
+└── .vimrc
+@end example
+
+Available @code{home-dotfiles-plain-directory} fields are:
 
-@item @code{exclude} (default: @code{'(".*~" ".*\\.swp" "\\.git" "\\.gitignore")})
-The list of file patterns @code{home-dotfiles-service-type} will exclude while
-visiting each one of the @code{directories}.
+@table @asis
+@item @code{name} (type: string)
+The name of the dotfile directory where
+@code{home-dotfiles-service-type} will look for plain dotfiles.
 
 @end table
 
 @end deftp
 
+@c %start of fragment
+
+@deftp {Data Type} home-dotfiles-stow-directory
+
+This record represents GNU Stow's usual layout.  In this layout the
+dotfiles directory contains a layer of application directories, each one
+containing a home file tree.  The @code{home-dotfiles-service-type} will
+take care of provisioning dotfiles just like Stow would.
+
+@example
+~$ tree -a ./dotfiles/
+dotfiles/
+├── guile
+│   └── .guile
+├── guix
+│   └── .config
+│       └── guix
+│           └── channels.scm
+├── tmux
+│   └── .tmux.conf
+└── vim
+    └── .vimrc
+
+@end example
+
+Available @code{home-dotfiles-stow-directory} fields are:
+
+@table @asis
+@item @code{name} (type: string)
+The name of the dotfile directory where
+@code{home-dotfiles-service-type} will look for application dotfiles.
+
+@item @code{applications} (type: maybe-list-of-strings)
+A subset of the names of the application layer directories.  When
+provided the @code{home-dotfiles-service-type} will only provision
+dotfiles from this subset of applications.
+
+@end table
+
+@end deftp
+
+
+@c %end of fragment
+
 @defvar home-xdg-configuration-files-service-type
 The service is very similar to @code{home-files-service-type} (and
 actually extends it), but used for defining files, which will go to
diff --git a/gnu/home/services/dotfiles.scm b/gnu/home/services/dotfiles.scm
index 6a740c42ce..ebe9600585 100644
--- a/gnu/home/services/dotfiles.scm
+++ b/gnu/home/services/dotfiles.scm
@@ -20,16 +20,33 @@
 (define-module (gnu home services dotfiles)
   #:use-module (gnu home services)
   #:use-module (gnu services)
+  #:use-module (gnu services configuration)
   #:autoload   (guix build utils) (find-files)
+  #:use-module (guix diagnostics)
   #:use-module (guix gexp)
-  #:use-module (guix records)
+  #:use-module (guix i18n)
   #:use-module ((guix utils) #:select (current-source-directory))
   #:use-module (srfi srfi-1)
   #:use-module (ice-9 ftw)
+  #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
   #:export (home-dotfiles-service-type
+            home-dotfiles-configuration->files
+
+            home-dotfiles-stow-directory
+            home-dotfiles-stow-directory?
+            home-dotfiles-stow-directory-fields
+            home-dotfiles-stow-directory-name
+            home-dotfiles-stow-directory-applications
+
+            home-dotfiles-plain-directory
+            home-dotfiles-plain-directory?
+            home-dotfiles-plain-directory-fields
+            home-dotfiles-plain-directory-name
+
             home-dotfiles-configuration
             home-dotfiles-configuration?
+            home-dotfiles-configuration-fields
             home-dotfiles-configuration-source-directory
             home-dotfiles-configuration-directories
             home-dotfiles-configuration-excluded))
@@ -40,26 +57,79 @@ (define %home-dotfiles-excluded
     "\\.git"
     "\\.gitignore"))
 
-(define-record-type* <home-dotfiles-configuration>
-  home-dotfiles-configuration make-home-dotfiles-configuration
-  home-dotfiles-configuration?
-  (source-directory  home-dotfiles-configuration-source-directory
-                     (default (current-source-directory))
-                     (innate))
-  (directories       home-dotfiles-configuration-directories       ;list of strings
-                     (default '()))
-  (excluded          home-dotfiles-configuration-excluded       ;list of strings
-                     (default %home-dotfiles-excluded)))
-
-(define (import-dotfiles directory files)
+(define list-of-strings?
+  (list-of string?))
+
+(define-maybe list-of-strings)
+
+(define-configuration/no-serialization home-dotfiles-stow-directory
+  (name
+   (string)
+   "The name of the dotfile directory where @code{home-dotfiles-service-type}
+will look for application dotfiles.")
+  (applications
+   (maybe-list-of-strings)
+   "A subset of the names of the application layer directories. When provided
+the @code{home-dotfiles-service-type} will only provision dotfiles from this
+subset of applications."))
+
+(define-configuration/no-serialization home-dotfiles-plain-directory
+  (name
+   (string)
+   "The name of the dotfile directory where @code{home-dotfiles-service-type}
+will look for plain dotfiles."))
+
+(define (list-of-plain-or-stow-directories? value)
+  (unless (list? value)
+    (raise
+     (formatted-message
+      (G_ "directories field of home-dotfiles-configuration should be a list but
+~a was found.")
+      value)))
+  (for-each
+   (lambda (d)
+     (unless (or (home-dotfiles-plain-directory? d)
+                 (home-dotfiles-stow-directory? d))
+       (raise
+        (formatted-message
+         (G_ "directories field of home-dotfiles-configuration should contain
+only home-dotfiles-plain-directory or home-dotfiles-stow-directory records, but
+~a was found.")
+         d))))
+   value))
+
+(define-configuration/no-serialization home-dotfiles-configuration
+  (source-directory
+   (string (current-source-directory))
+   "The path where dotfile directories are resolved.  By default dotfile
+directories are resolved relative the source location where
+@code{home-dotfiles-configuration} appears.")
+  (directories
+   (list-of-plain-or-stow-directories '())
+   "The list of dotfiles directories where @code{home-dotfiles-service-type}
+will look for application dotfiles.  Each element of the list is supposed to be
+either a @code{home-dotfiles-plain-directory} or a
+@code{home-dotfiles-stow-directory} record.")
+  (excluded
+   (list-of-strings %home-dotfiles-excluded)
+   "The list of file patterns @code{home-dotfiles-service-type} will exclude
+while visiting each one of the @code{directories}."))
+
+(define (strip-stow-dotfile file-name directory)
+  (let ((dotfile-name (string-drop file-name (1+ (string-length directory)))))
+    (match (string-split dotfile-name #\/)
+      ((package parts ...)
+       (string-join parts "/")))))
+
+(define (strip-plain-dotfile file-name directory)
+  (string-drop file-name (+ 1 (string-length directory))))
+
+(define (import-dotfiles directory files strip)
   "Return a list of objects compatible with @code{home-files-service-type}'s
 value.  Each object is a pair where the first element is the relative path
 of a file and the second is a gexp representing the file content.  Objects are
 generated by recursively visiting DIRECTORY and mapping its contents to the
 user's home directory, excluding files that match any of the patterns in EXCLUDED."
-  (define (strip file)
-    (string-drop file (+ 1 (string-length directory))))
-
   (define (format file)
     ;; Remove from FILE characters that cannot be used in the store.
     (string-append
@@ -73,7 +143,7 @@ (define (format file)
                  file)))
 
   (map (lambda (file)
-         (let ((stripped (strip file)))
+         (let ((stripped (strip file directory)))
            (list stripped
                  (local-file file (format stripped)
                              #:recursive? #t))))
@@ -88,11 +158,18 @@ (define excluded
   (define exclusion-rx
     (make-regexp (string-append "^.*(" (string-join excluded "|") ")$")))
 
-  (define (directory-contents directory)
-    (find-files directory
-                (lambda (file stat)
-                  (not (regexp-exec exclusion-rx
-                                    (basename file))))))
+  (define* (directory-contents directory #:key (applications #f))
+    (define (filter-files directory)
+      (find-files directory
+                  (lambda (file stat)
+                    (not (regexp-exec exclusion-rx
+                                      (basename file))))))
+    (if applications
+        (append-map filter-files
+                    (map (lambda (app)
+                           (string-append directory "/" app))
+                         applications))
+        (filter-files directory)))
 
   (define (resolve directory)
     ;; Resolve DIRECTORY relative to the 'source-directory' field of CONFIG.
@@ -101,10 +178,24 @@ (define (resolve directory)
         (in-vicinity (home-dotfiles-configuration-source-directory config)
                      directory)))
 
-  (append-map (lambda (directory)
-                (let* ((directory (resolve directory))
-                       (contents  (directory-contents directory)))
-                  (import-dotfiles directory contents)))
+  (append-map (lambda (record)
+                (let* ((name (if (home-dotfiles-plain-directory? record)
+                                 (home-dotfiles-plain-directory-name record)
+                                 (home-dotfiles-stow-directory-name record)))
+                       (strip (if (home-dotfiles-plain-directory? record)
+                                  strip-plain-dotfile
+                                  strip-stow-dotfile))
+                       (applications
+                        (and (home-dotfiles-stow-directory? record)
+                             (let ((apps
+                                    (home-dotfiles-stow-directory-applications
+                                     record)))
+                               (and (maybe-value-set? apps) apps))))
+                       (directory (resolve name))
+                       (contents
+                        (directory-contents directory
+                                            #:applications applications)))
+                  (import-dotfiles directory contents strip)))
               (home-dotfiles-configuration-directories config)))
 
 (define-public home-dotfiles-service-type

base-commit: bd87416648929f38c0173f047776d7675ea8a10d
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Fri, 16 Feb 2024 19:08:02 GMT) Full text and rfc822 format available.

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

From: Sergey Trofimov <sarg <at> sarg.org.ru>
To: paul <goodoldpaul <at> autistici.org>
Cc: Ludovic Courtès <ludo <at> gnu.org>, 68857 <at> debbugs.gnu.org,
 janneke <at> gnu.org
Subject: Re: [bug#68857] [PATCH] gnu: home: dotfiles: Avoid creating extra
 directory in $HOME.
Date: Fri, 16 Feb 2024 19:57:24 +0100
Hi Paul,

paul <goodoldpaul <at> autistici.org> writes:

> Hi everyone,
>
> thank you for your help and comments so far. I have a proposal 
> that should:
>
> - solve https://issues.guix.gnu.org/68848
>
> - allow for both plain and GNU Stow's layouts
>
> - for GNU Stow layouts, allows to select a subset of application 
> dotfiles to be
>   provisioned in the user's home directory. Please Sergey let me 
>   know if this
>  covers your use case .
>


My dotfiles tree is (relative to ~/.dotfiles):
./guix/home.scm
./backup/.config/..
./android/.config/..
...

It works with such config:

--8<---------------cut here---------------start------------->8---
(service home-dotfiles-service-type
   (home-dotfiles-configuration
     (directories
       (list
         (home-dotfiles-stow-directory
           (name "..")
           (applications
           '("backup"
             "android"
             "email"
             "xsession"
             "git"
             "qutebrowser"
             "desktop")))))))
--8<---------------cut here---------------end--------------->8---

`name` is in fact a relative path, so this field should be 
renamed.
`applications` are called `PACKAGES` in `stow` man page, so I'd 
rename it to match.




Information forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Tue, 20 Feb 2024 09:38:02 GMT) Full text and rfc822 format available.

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

From: Ludovic Courtès <ludo <at> gnu.org>
To: Giacomo Leidi <goodoldpaul <at> autistici.org>
Cc: 68857 <at> debbugs.gnu.org
Subject: Re: bug#68857: gnu: home: dotfiles: Avoid creating extra directory
 in $HOME.
Date: Tue, 20 Feb 2024 10:37:08 +0100
Hello Giacomo!

Giacomo Leidi <goodoldpaul <at> autistici.org> skribis:

> The current implementation of the home-dotfiles-service-type contradicts
> the Guix manual (see https://issues.guix.gnu.org/68848 ). This patch
> properly implements both the plain and Stow dotfiles directory layouts.
>
> It does so by creating a new record type for each directory layout. This
> approach, compared to having a single field in
> home-dotfiles-configuration,
> allows for having different layouts for different directories and to
> carry additional information that might be required for some layouts.
>
> Implementing a new layout should just be a matter of creating a new
> record type, defining a strip-*-dotfile procedure and plugging them into
> the home-dotfiles-service-type.
>
> * gnu/home/services/dotfiles (home-dotfiles-stow-directory): New
> variable;
> (home-dotfiles-plain-directory): new variable;
> (home-dotfiles-configuration): migrate to (gnu services configuration);
> (strip-stow-dotfile): new variable;
> (strip-plain-dotfile): new variable;
> (home-dotfiles-configuration->files): use the new record types;
> [directory-contents]: allow for
> selecting a subset of application dotfile directories;
> * doc/guix.texi: document the new layouts.
>
> Change-Id: I2e96037608353e360828290f055ec5271cfdfd48

Thanks for working on it!

> +There are two supported dotfiles directory layouts, for now. The
> +@code{home-dotfiles-plain-directory} layout, which is structured as follows:
> +
> +@example
> +~$ tree -a ./dotfiles/
> +dotfiles/
> +├── .gitconfig
> +├── .gnupg
> +│   ├── gpg-agent.conf
> +│   └── gpg.conf
> +├── .guile
> +├── .config
> +│   ├── guix
> +│   │   └── channels.scm
> +│   └── nixpkgs
> +│       └── config.nix
> +├── .nix-channels
> +├── .tmux.conf
> +└── .vimrc
> +@end example

I’d add a sentence like: “This tree structure is installed as is to the
home directory upon @command{guix home reconfigure}.”

> -(define-record-type* <home-dotfiles-configuration>
> -  home-dotfiles-configuration make-home-dotfiles-configuration
> -  home-dotfiles-configuration?
> -  (source-directory  home-dotfiles-configuration-source-directory
> -                     (default (current-source-directory))
> -                     (innate))
> -  (directories       home-dotfiles-configuration-directories       ;list of strings
> -                     (default '()))
> -  (excluded          home-dotfiles-configuration-excluded       ;list of strings
> -                     (default %home-dotfiles-excluded)))
> -
> -(define (import-dotfiles directory files)
> +(define list-of-strings?
> +  (list-of string?))
> +
> +(define-maybe list-of-strings)
> +
> +(define-configuration/no-serialization home-dotfiles-stow-directory

[...]

> +(define-configuration/no-serialization home-dotfiles-configuration

I think we should keep ‘home-dotfiles-configuration’ for compatibility
(this patch keeps the exports but removes the actual
<home-dotfiles-configuration> definition IIUC).

Also, as a rule of thumb, the configuration of a given service type is
usually monomorphic (always the same configuration record type), which I
find clearer.

Instead of having these two record types, would it be an option to add a
‘type’ field (or similar) to <home-dotfiles-configuration>, as discussed
earlier?

Thanks,
Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Tue, 20 Feb 2024 18:39:01 GMT) Full text and rfc822 format available.

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

From: paul <goodoldpaul <at> autistici.org>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 68857 <at> debbugs.gnu.org
Subject: Re: bug#68857: gnu: home: dotfiles: Avoid creating extra directory in
 $HOME.
Date: Tue, 20 Feb 2024 19:38:00 +0100
Hi Ludo’ ,

On 2/20/24 10:37, Ludovic Courtès wrote:
> Hello Giacomo!
>
> Giacomo Leidi <goodoldpaul <at> autistici.org> skribis:
>
>> The current implementation of the home-dotfiles-service-type contradicts
>> the Guix manual (see https://issues.guix.gnu.org/68848 ). This patch
>> properly implements both the plain and Stow dotfiles directory layouts.
>>
>> It does so by creating a new record type for each directory layout. This
>> approach, compared to having a single field in
>> home-dotfiles-configuration,
>> allows for having different layouts for different directories and to
>> carry additional information that might be required for some layouts.
>>
>> Implementing a new layout should just be a matter of creating a new
>> record type, defining a strip-*-dotfile procedure and plugging them into
>> the home-dotfiles-service-type.
>>
>> * gnu/home/services/dotfiles (home-dotfiles-stow-directory): New
>> variable;
>> (home-dotfiles-plain-directory): new variable;
>> (home-dotfiles-configuration): migrate to (gnu services configuration);
>> (strip-stow-dotfile): new variable;
>> (strip-plain-dotfile): new variable;
>> (home-dotfiles-configuration->files): use the new record types;
>> [directory-contents]: allow for
>> selecting a subset of application dotfile directories;
>> * doc/guix.texi: document the new layouts.
>>
>> Change-Id: I2e96037608353e360828290f055ec5271cfdfd48
> Thanks for working on it!
>
>> +There are two supported dotfiles directory layouts, for now. The
>> +@code{home-dotfiles-plain-directory} layout, which is structured as follows:
>> +
>> +@example
>> +~$ tree -a ./dotfiles/
>> +dotfiles/
>> +├── .gitconfig
>> +├── .gnupg
>> +│   ├── gpg-agent.conf
>> +│   └── gpg.conf
>> +├── .guile
>> +├── .config
>> +│   ├── guix
>> +│   │   └── channels.scm
>> +│   └── nixpkgs
>> +│       └── config.nix
>> +├── .nix-channels
>> +├── .tmux.conf
>> +└── .vimrc
>> +@end example
> I’d add a sentence like: “This tree structure is installed as is to the
> home directory upon @command{guix home reconfigure}.”
I'm adding this to the manual, thanks!
>> +(define-configuration/no-serialization home-dotfiles-configuration
> I think we should keep ‘home-dotfiles-configuration’ for compatibility
> (this patch keeps the exports but removes the actual
> <home-dotfiles-configuration> definition IIUC).
We are keeping home-dotfiles-configuration , it's just now it is 
implemented with validation from (gnu services configuration) . The only 
thing changing is that home-dotfiles-configuration's directories field 
is now a list of either home-dotfiles-plain-directory or 
home-dotfiles-stow-directory records.
> Also, as a rule of thumb, the configuration of a given service type is
> usually monomorphic (always the same configuration record type), which I
> find clearer.
>
> Instead of having these two record types, would it be an option to add a
> ‘type’ field (or similar) to <home-dotfiles-configuration>, as discussed
> earlier?

As I tried explaining in the commit message, this approach, compared to 
having a single field in home-dotfiles-configuration , allows for having 
different layouts for different directories and to carry additional 
information that might be needed for a given layout type. Such as the 
application field required to support some Stow's users workflows. What 
do you think about this approach? It should be general enough to support 
any kind of layout.

Thank you for your time,

giacomo





Information forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Tue, 27 Feb 2024 10:21:02 GMT) Full text and rfc822 format available.

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

From: Ludovic Courtès <ludo <at> gnu.org>
To: paul <goodoldpaul <at> autistici.org>
Cc: 68857 <at> debbugs.gnu.org
Subject: Re: bug#68857: gnu: home: dotfiles: Avoid creating extra directory
 in $HOME.
Date: Tue, 27 Feb 2024 11:17:07 +0100
Hi,

paul <goodoldpaul <at> autistici.org> skribis:

> As I tried explaining in the commit message, this approach, compared
> to having a single field in home-dotfiles-configuration , allows for
> having different layouts for different directories and to carry
> additional information that might be needed for a given layout
> type. Such as the application field required to support some Stow's
> users workflows. What do you think about this approach? It should be
> general enough to support any kind of layout.

I think we’ll only want to support two layouts: Stow and “plain”; we
should avoid overengineering that.  That’s why a simple (layout 'stow)
field seems good enough for me.

WDYT?

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Tue, 27 Feb 2024 11:34:02 GMT) Full text and rfc822 format available.

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

From: paul <goodoldpaul <at> autistici.org>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 68857 <at> debbugs.gnu.org
Subject: Re: bug#68857: gnu: home: dotfiles: Avoid creating extra directory in
 $HOME.
Date: Tue, 27 Feb 2024 12:32:43 +0100
Ah obviously I replied to you with the wrong address 
(leidigiacomo <at> outlook.com) thanks to Thunderbird :( apologies for the 
confusion.


giacomo





Information forwarded to , guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Tue, 27 Feb 2024 12:37:02 GMT) Full text and rfc822 format available.

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

From: Giacomo Leidi <goodoldpaul <at> autistici.org>
To: 68857 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul <at> autistici.org>
Subject: [PATCH v3] gnu: home: dotfiles: Properly support both plain and Stow
 directory layouts.
Date: Tue, 27 Feb 2024 13:35:08 +0100
The current implementation of the home-dotfiles-service-type contradicts
the Guix manual (see https://issues.guix.gnu.org/68848 ). This patch
properly implements both the plain and Stow dotfiles directory layouts.

It does so by refactoring home-dotfiles-configuration, renaming the
directories field to a single directory, adding a new packages field to
support GNU Stow's users workflow and introducing a new layout field to
switch between the two directory layouts.

* gnu/home/services/dotfiles (home-dotfiles-configuration): Migrate to
(gnu services configuration);
[directories]: rename to...;
[directory]: ...this, new field;
[packages]: new field;
[layout]: new field;
(strip-stow-dotfile): new variable;
(strip-plain-dotfile): new variable;
(home-dotfiles-configuration->files): use the new fields;
[directory-contents]: allow for
selecting a subset of application dotfile directories;
* doc/guix.texi: document the new layouts.

Change-Id: I2e96037608353e360828290f055ec5271cfdfd48
---
 doc/guix.texi                  |  84 ++++++++++++++++------
 gnu/home/services/dotfiles.scm | 123 ++++++++++++++++++++++++---------
 2 files changed, 154 insertions(+), 53 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index f6476e0d81..89f9887fe3 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -111,7 +111,7 @@
 Copyright @copyright{} 2022 John Kehayias@*
 Copyright @copyright{} 2022⁠–⁠2023 Bruno Victal@*
 Copyright @copyright{} 2022 Ivan Vilata-i-Balaguer@*
-Copyright @copyright{} 2023 Giacomo Leidi@*
+Copyright @copyright{} 2023-2024 Giacomo Leidi@*
 Copyright @copyright{} 2022 Antero Mejr@*
 Copyright @copyright{} 2023 Karl Hallsby@*
 Copyright @copyright{} 2023 Nathaniel Nicandro@*
@@ -44444,17 +44444,42 @@ Essential Home Services
 @cindex Stow-like dot file management
 The @code{home-dotfiles-service-type} from @code{(gnu home services dotfiles)}
 is designed to ease the way into using Guix Home for this kind of users,
-allowing them to point the service to their dotfiles directory, which must
-follow the layout suggested by
-@uref{https://www.gnu.org/software/stow/, GNU Stow},
-and have their dotfiles automatically deployed to their user home, without
+allowing them to point the service to their dotfiles directory without
 migrating them to Guix native configurations.
 
-The dotfiles directory layout is expected to be structured as follows. Please
-keep in mind that it is advisable to keep your dotfiles directories under
+Please keep in mind that it is advisable to keep your dotfiles directories under
 version control, for example in the same repository where you'd track your
 Guix Home configuration.
 
+There are two supported dotfiles directory layouts, for now. The
+@code{'plain} layout, which is structured as follows:
+
+@example
+~$ tree -a ./dotfiles/
+dotfiles/
+├── .gitconfig
+├── .gnupg
+│   ├── gpg-agent.conf
+│   └── gpg.conf
+├── .guile
+├── .config
+│   ├── guix
+│   │   └── channels.scm
+│   └── nixpkgs
+│       └── config.nix
+├── .nix-channels
+├── .tmux.conf
+└── .vimrc
+@end example
+
+This tree structure is installed as is to the
+home directory upon @command{guix home reconfigure}.
+
+The @code{'stow} layout, which must
+follow the layout suggested by
+@uref{https://www.gnu.org/software/stow/, GNU Stow} presents an additional
+application specific directory layer, just like:
+
 @example
 ~$ tree -a ./dotfiles/
 dotfiles/
@@ -44484,8 +44509,10 @@ Essential Home Services
 @end example
 
 For an informal specification please refer to the Stow manual
-(@pxref{Top,,, stow, Introduction}). A suitable configuration would then
-be:
+(@pxref{Top,,, stow, Introduction}). This tree structure is installed following
+GNU Stow's logic to the home directory upon @command{guix home reconfigure}.
+
+A suitable configuration with a @code{'plain} layout could be:
 
 @lisp
 (home-environment
@@ -44493,7 +44520,7 @@ Essential Home Services
   (services
     (service home-dotfiles-service-type
              (home-dotfiles-configuration
-               (directories (list "./dotfiles"))))))
+               (directory "./dotfiles")))))
 @end lisp
 
 The expected home directory state would then be:
@@ -44520,32 +44547,47 @@ Essential Home Services
 (and actually extends it), but designed to ease the way into using Guix
 Home for users that already track their dotfiles under some kind of version
 control.  This service allows users to point Guix Home to their dotfiles
-directory and have their files automatically deployed to their home directory
-just like Stow would, without migrating all of their dotfiles to Guix native
+directory and have their files automatically provisioned to their home
+directory, without migrating all of their dotfiles to Guix native
 configurations.
 @end defvar
 
+@c %start of fragment
+
 @deftp {Data Type} home-dotfiles-configuration
 Available @code{home-dotfiles-configuration} fields are:
 
 @table @asis
-@item @code{source-directory} (default: @code{(current-source-directory)})
-The path where dotfile directories are resolved. By default dotfile directories
-are resolved relative the source location where
+@item @code{source-directory} (default: @code{(current-source-directory)}) (type: string)
+The path where dotfile directories are resolved.  By default dotfile
+directories are resolved relative the source location where
 @code{home-dotfiles-configuration} appears.
 
-@item @code{directories} (type: list-of-strings)
-The list of dotfiles directories where @code{home-dotfiles-service-type} will
-look for application dotfiles.
+@item @code{layout} (default: @code{'plain}) (type: symbol)
+The intended layout of the specified @code{directory}.  It can be either
+@code{'stow} or @code{'plain}.
+
+@item @code{directory} (type: string)
+The dotfiles directory where @code{home-dotfiles-service-type}
+will look for application dotfiles.
+
+@item @code{packages} (type: maybe-list-of-strings)
+The names of a subset of the GNU Stow package layer directories.  When provided
+the @code{home-dotfiles-service-type} will only provision dotfiles from this
+subset of applications.  This field will be ignored if @code{layout} is set
+to @code{'plain}.
 
-@item @code{exclude} (default: @code{'(".*~" ".*\\.swp" "\\.git" "\\.gitignore")})
-The list of file patterns @code{home-dotfiles-service-type} will exclude while
-visiting each one of the @code{directories}.
+@item @code{excluded} (default: @code{'(".*~" ".*\\.swp" "\\.git" "\\.gitignore")}) (type: list-of-strings)
+The list of file patterns @code{home-dotfiles-service-type} will exclude
+while visiting each one of the @code{directories}.
 
 @end table
 
 @end deftp
 
+
+@c %end of fragment
+
 @defvar home-xdg-configuration-files-service-type
 The service is very similar to @code{home-files-service-type} (and
 actually extends it), but used for defining files, which will go to
diff --git a/gnu/home/services/dotfiles.scm b/gnu/home/services/dotfiles.scm
index 6a740c42ce..c7886e3763 100644
--- a/gnu/home/services/dotfiles.scm
+++ b/gnu/home/services/dotfiles.scm
@@ -20,18 +20,26 @@
 (define-module (gnu home services dotfiles)
   #:use-module (gnu home services)
   #:use-module (gnu services)
+  #:use-module (gnu services configuration)
   #:autoload   (guix build utils) (find-files)
+  #:use-module (guix diagnostics)
   #:use-module (guix gexp)
-  #:use-module (guix records)
+  #:use-module (guix i18n)
   #:use-module ((guix utils) #:select (current-source-directory))
   #:use-module (srfi srfi-1)
   #:use-module (ice-9 ftw)
+  #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
   #:export (home-dotfiles-service-type
+            home-dotfiles-configuration->files
+
             home-dotfiles-configuration
             home-dotfiles-configuration?
+            home-dotfiles-configuration-fields
+            home-dotfiles-configuration-layout
             home-dotfiles-configuration-source-directory
-            home-dotfiles-configuration-directories
+            home-dotfiles-configuration-packages
+            home-dotfiles-configuration-directory
             home-dotfiles-configuration-excluded))
 
 (define %home-dotfiles-excluded
@@ -40,26 +48,64 @@ (define %home-dotfiles-excluded
     "\\.git"
     "\\.gitignore"))
 
-(define-record-type* <home-dotfiles-configuration>
-  home-dotfiles-configuration make-home-dotfiles-configuration
-  home-dotfiles-configuration?
-  (source-directory  home-dotfiles-configuration-source-directory
-                     (default (current-source-directory))
-                     (innate))
-  (directories       home-dotfiles-configuration-directories       ;list of strings
-                     (default '()))
-  (excluded          home-dotfiles-configuration-excluded       ;list of strings
-                     (default %home-dotfiles-excluded)))
-
-(define (import-dotfiles directory files)
+(define %home-dotfiles-layouts
+  '(plain stow))
+
+(define (sanitize-layout value)
+  (if (member value %home-dotfiles-layouts)
+      value
+      (raise
+       (formatted-message
+        (G_ "layout field of home-dotfiles-configuration should be either 'plain
+or 'stow, but ~a was found.")
+        value))))
+
+(define list-of-strings?
+  (list-of string?))
+
+(define-maybe list-of-strings)
+
+(define-configuration/no-serialization home-dotfiles-configuration
+  (source-directory
+   (string (current-source-directory))
+   "The path where dotfile directories are resolved.  By default dotfile
+directories are resolved relative the source location where
+@code{home-dotfiles-configuration} appears.")
+  (layout
+   (symbol 'plain)
+   "The intended layout of the specified @code{directory}.  It can be either
+@code{'stow} or @code{'plain}."
+   (sanitizer sanitize-layout))
+  (directory
+   (string)
+   "The dotfiles directory where @code{home-dotfiles-service-type}
+will look for application dotfiles.")
+  (packages
+   (maybe-list-of-strings)
+   "The names of a subset of the GNU Stow package layer directories.  When provided
+the @code{home-dotfiles-service-type} will only provision dotfiles from this
+subset of applications.  This field will be ignored if @code{layout} is set
+to @code{'plain}.")
+  (excluded
+   (list-of-strings %home-dotfiles-excluded)
+   "The list of file patterns @code{home-dotfiles-service-type} will exclude
+while visiting @code{directory}."))
+
+(define (strip-stow-dotfile file-name directory)
+  (let ((dotfile-name (string-drop file-name (1+ (string-length directory)))))
+    (match (string-split dotfile-name #\/)
+      ((package parts ...)
+       (string-join parts "/")))))
+
+(define (strip-plain-dotfile file-name directory)
+  (string-drop file-name (+ 1 (string-length directory))))
+
+(define (import-dotfiles directory files strip)
   "Return a list of objects compatible with @code{home-files-service-type}'s
 value.  Each object is a pair where the first element is the relative path
 of a file and the second is a gexp representing the file content.  Objects are
 generated by recursively visiting DIRECTORY and mapping its contents to the
 user's home directory, excluding files that match any of the patterns in EXCLUDED."
-  (define (strip file)
-    (string-drop file (+ 1 (string-length directory))))
-
   (define (format file)
     ;; Remove from FILE characters that cannot be used in the store.
     (string-append
@@ -73,7 +119,7 @@ (define (import-dotfiles directory files)
                  file)))
 
   (map (lambda (file)
-         (let ((stripped (strip file)))
+         (let ((stripped (strip file directory)))
            (list stripped
                  (local-file file (format stripped)
                              #:recursive? #t))))
@@ -81,18 +127,25 @@ (define (import-dotfiles directory files)
 
 (define (home-dotfiles-configuration->files config)
   "Return a list of objects compatible with @code{home-files-service-type}'s
-value, generated following GNU Stow's algorithm for each of the
-directories in CONFIG, excluding files that match any of the patterns configured."
+value, excluding files that match any of the patterns configured."
+  (define stow? (eq? (home-dotfiles-configuration-layout config) 'stow))
   (define excluded
     (home-dotfiles-configuration-excluded config))
   (define exclusion-rx
     (make-regexp (string-append "^.*(" (string-join excluded "|") ")$")))
 
-  (define (directory-contents directory)
-    (find-files directory
-                (lambda (file stat)
-                  (not (regexp-exec exclusion-rx
-                                    (basename file))))))
+  (define* (directory-contents directory #:key (packages #f))
+    (define (filter-files directory)
+      (find-files directory
+                  (lambda (file stat)
+                    (not (regexp-exec exclusion-rx
+                                      (basename file))))))
+    (if (and stow? packages (maybe-value-set? packages))
+        (append-map filter-files
+                    (map (lambda (pkg)
+                           (string-append directory "/" pkg))
+                         packages))
+        (filter-files directory)))
 
   (define (resolve directory)
     ;; Resolve DIRECTORY relative to the 'source-directory' field of CONFIG.
@@ -101,17 +154,23 @@ (define (home-dotfiles-configuration->files config)
         (in-vicinity (home-dotfiles-configuration-source-directory config)
                      directory)))
 
-  (append-map (lambda (directory)
-                (let* ((directory (resolve directory))
-                       (contents  (directory-contents directory)))
-                  (import-dotfiles directory contents)))
-              (home-dotfiles-configuration-directories config)))
+  (let* ((directory (resolve (home-dotfiles-configuration-directory config)))
+         (packages
+          (home-dotfiles-configuration-packages config))
+         (contents
+          (directory-contents directory
+                              #:packages packages))
+         (strip
+          (if stow? strip-stow-dotfile strip-plain-dotfile)))
+    (import-dotfiles directory contents strip)))
 
 (define-public home-dotfiles-service-type
   (service-type (name 'home-dotfiles)
                 (extensions
                  (list (service-extension home-files-service-type
-                                          home-dotfiles-configuration->files)))
-                (default-value (home-dotfiles-configuration))
+                                          (lambda (config)
+                                            (when config
+                                              (home-dotfiles-configuration->files config))))))
+                (default-value #f)
                 (description "Files that will be put in the user's home directory
 following GNU Stow's algorithm, and further processed during activation.")))

base-commit: 75bad75367fcf2c289fae3b40dbcc850f92177be
-- 
2.41.0





Information forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Tue, 27 Feb 2024 13:18:03 GMT) Full text and rfc822 format available.

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

From: Giacomo Leidi <leidigiacomo <at> outlook.com>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 68857 <at> debbugs.gnu.org
Subject: Re: [bug#68857] gnu: home: dotfiles: Avoid creating extra directory
 in $HOME.
Date: Tue, 27 Feb 2024 12:30:30 +0100
[Message part 1 (text/plain, inline)]
Hi Ludo' ,

First of all thank you for putting the time for working on this, I hope 
we are close to a solution :)

On 2/27/24 11:17, Ludovic Courtès wrote:
> I think we’ll only want to support two layouts: Stow and “plain”; we
> should avoid overengineering that.  That’s why a simple (layout 'stow)
> field seems good enough for me.
>
> WDYT?

I think it is important, if the effort is feasible, to not leave anyone 
behind (in terms of what the features of this service are) . Having a 
single field without further changes will introduce some ambiguity imo. 
We have these requirements in my understanding:

1. The service should support Stow's users workflows. This is a hard
   requirement in my opinion. Hence we need a way to select a subset
   the applications directories (the applications field of
   home-dotfiles-stow-directory in v2 of the patch).
2. The service should support Stow's users workflows. This is also a
   hard requirement. For this we just need the path of the dotfiles
   directory.
3. The service should support multiple dotfiles directories. This is
   not a hard requirement i believe, but we currently have this feature
   (the directories field of home-dotfiles-configuration is a list of
   strings not a string).

Introducing a single layout field makes it impossible to unambiguously 
implement requirement 1. If the user has more than directory it really 
makes no sense to select the same subset of applications for each one of 
them. This is to say that I believe it makes little sense to have 
multiple directories if the layout and applications information are not 
linked somehow with each directory. I wouldn't call this 
overengineering, just implementing the features users need from this 
service. I hope you agree.

Also since I first sent this service around Jan 2023 (when it was still 
the home-stow-migration-service), and it has been broken on master for 
some time I'd like to provide a fix for this situation as soon as 
possible (clearly the definition of brokennes and what changes to the 
API would be breaking user configs depends on the requirements one 
intends for the home-dotfiles-service-type, especially since the changes 
that broke master were introduced without consensus).

I'm changing the code to: use the layout field, support Stow's users 
workflow adding a new optional field called packages, which makes sense 
only if the layout is 'stow, and I'm making the directories field a 
string instead of a list of strings. Please let me know your thoughts on 
this v3.


Thank your for your work,


giacomo
[Message part 2 (text/html, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Mon, 04 Mar 2024 15:48:02 GMT) Full text and rfc822 format available.

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

From: Ludovic Courtès <ludo <at> gnu.org>
To: Giacomo Leidi <goodoldpaul <at> autistici.org>
Cc: paren <at> disroot.org, 68857 <at> debbugs.gnu.org, Andrew Tropin <andrew <at> trop.in>
Subject: Re: bug#68857: gnu: home: dotfiles: Avoid creating extra directory
 in $HOME.
Date: Mon, 04 Mar 2024 16:46:35 +0100
Hi,

Giacomo Leidi <goodoldpaul <at> autistici.org> skribis:

> The current implementation of the home-dotfiles-service-type contradicts
> the Guix manual (see https://issues.guix.gnu.org/68848 ). This patch
> properly implements both the plain and Stow dotfiles directory layouts.
>
> It does so by refactoring home-dotfiles-configuration, renaming the
> directories field to a single directory, adding a new packages field to
> support GNU Stow's users workflow and introducing a new layout field to
> switch between the two directory layouts.
>
> * gnu/home/services/dotfiles (home-dotfiles-configuration): Migrate to
> (gnu services configuration);
> [directories]: rename to...;
> [directory]: ...this, new field;
> [packages]: new field;
> [layout]: new field;
> (strip-stow-dotfile): new variable;
> (strip-plain-dotfile): new variable;
> (home-dotfiles-configuration->files): use the new fields;
> [directory-contents]: allow for
> selecting a subset of application dotfile directories;
> * doc/guix.texi: document the new layouts.
>
> Change-Id: I2e96037608353e360828290f055ec5271cfdfd48

LGTM, but…

> -  (directories       home-dotfiles-configuration-directories       ;list of strings
> -                     (default '()))

[...]

> +  (directory
> +   (string)
> +   "The dotfiles directory where @code{home-dotfiles-service-type}
> +will look for application dotfiles.")

This is an incompatible change.  Can we keep the old ‘directories’
field?

(Maybe this change is worthwhile, but it’s beyond the scope of this
patch series IMO, so I’d suggest discussing it separately.)

>  (define-public home-dotfiles-service-type
>    (service-type (name 'home-dotfiles)
>                  (extensions
>                   (list (service-extension home-files-service-type
> -                                          home-dotfiles-configuration->files)))
> -                (default-value (home-dotfiles-configuration))
> +                                          (lambda (config)
> +                                            (when config
> +                                              (home-dotfiles-configuration->files config))))))
> +                (default-value #f)

Better not provide a default value than provide one that is invalid.  My
suggestion would be to remove the ‘default-value’ field here.

Apologies for the delays and thanks for your work and for your patience!

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Wed, 06 Mar 2024 20:53:02 GMT) Full text and rfc822 format available.

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

From: paul <goodoldpaul <at> autistici.org>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: paren <at> disroot.org, 68857 <at> debbugs.gnu.org, Andrew Tropin <andrew <at> trop.in>
Subject: Re: bug#68857: gnu: home: dotfiles: Avoid creating extra directory in
 $HOME.
Date: Wed, 6 Mar 2024 21:51:58 +0100
Hi Ludo ,

I should have addressed everything, I hope. Thank you again for your 
time reviewing this.

I'm sending a  v4.


giacomo





Information forwarded to , guix-patches <at> gnu.org:
bug#68857; Package guix-patches. (Wed, 06 Mar 2024 20:54:01 GMT) Full text and rfc822 format available.

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

From: Giacomo Leidi <goodoldpaul <at> autistici.org>
To: 68857 <at> debbugs.gnu.org
Cc: Giacomo Leidi <goodoldpaul <at> autistici.org>
Subject: [PATCH v4] gnu: home: dotfiles: Properly support both plain and Stow
 directory layouts.
Date: Wed,  6 Mar 2024 21:52:42 +0100
The current implementation of the home-dotfiles-service-type contradicts
the Guix manual (see https://issues.guix.gnu.org/68848 ). This patch
properly implements both the plain and Stow dotfiles directory layouts.

It does so by refactoring home-dotfiles-configuration adding a new
packages field to support GNU Stow's users workflow and introducing
a new layout field to switch between the two directory layouts.

* gnu/home/services/dotfiles (home-dotfiles-configuration): Migrate to
(gnu services configuration);
[packages]: new field;
[layout]: new field;
(strip-stow-dotfile): new variable;
(strip-plain-dotfile): new variable;
(home-dotfiles-configuration->files): use the new fields;
[directory-contents]: allow for
selecting a subset of application dotfile directories;
* doc/guix.texi: document the new layouts.

Change-Id: I2e96037608353e360828290f055ec5271cfdfd48
---
 doc/guix.texi                  |  84 ++++++++++++++++++------
 gnu/home/services/dotfiles.scm | 115 +++++++++++++++++++++++++--------
 2 files changed, 151 insertions(+), 48 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 87fe9f803c..8a33c4aa55 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -111,7 +111,7 @@
 Copyright @copyright{} 2022 John Kehayias@*
 Copyright @copyright{} 2022⁠–⁠2023 Bruno Victal@*
 Copyright @copyright{} 2022 Ivan Vilata-i-Balaguer@*
-Copyright @copyright{} 2023 Giacomo Leidi@*
+Copyright @copyright{} 2023-2024 Giacomo Leidi@*
 Copyright @copyright{} 2022 Antero Mejr@*
 Copyright @copyright{} 2023 Karl Hallsby@*
 Copyright @copyright{} 2023 Nathaniel Nicandro@*
@@ -44667,17 +44667,42 @@ Essential Home Services
 @cindex Stow-like dot file management
 The @code{home-dotfiles-service-type} from @code{(gnu home services dotfiles)}
 is designed to ease the way into using Guix Home for this kind of users,
-allowing them to point the service to their dotfiles directory, which must
-follow the layout suggested by
-@uref{https://www.gnu.org/software/stow/, GNU Stow},
-and have their dotfiles automatically deployed to their user home, without
+allowing them to point the service to their dotfiles directory without
 migrating them to Guix native configurations.
 
-The dotfiles directory layout is expected to be structured as follows. Please
-keep in mind that it is advisable to keep your dotfiles directories under
+Please keep in mind that it is advisable to keep your dotfiles directories under
 version control, for example in the same repository where you'd track your
 Guix Home configuration.
 
+There are two supported dotfiles directory layouts, for now. The
+@code{'plain} layout, which is structured as follows:
+
+@example
+~$ tree -a ./dotfiles/
+dotfiles/
+├── .gitconfig
+├── .gnupg
+│   ├── gpg-agent.conf
+│   └── gpg.conf
+├── .guile
+├── .config
+│   ├── guix
+│   │   └── channels.scm
+│   └── nixpkgs
+│       └── config.nix
+├── .nix-channels
+├── .tmux.conf
+└── .vimrc
+@end example
+
+This tree structure is installed as is to the
+home directory upon @command{guix home reconfigure}.
+
+The @code{'stow} layout, which must
+follow the layout suggested by
+@uref{https://www.gnu.org/software/stow/, GNU Stow} presents an additional
+application specific directory layer, just like:
+
 @example
 ~$ tree -a ./dotfiles/
 dotfiles/
@@ -44707,8 +44732,10 @@ Essential Home Services
 @end example
 
 For an informal specification please refer to the Stow manual
-(@pxref{Top,,, stow, Introduction}). A suitable configuration would then
-be:
+(@pxref{Top,,, stow, Introduction}). This tree structure is installed following
+GNU Stow's logic to the home directory upon @command{guix home reconfigure}.
+
+A suitable configuration with a @code{'plain} layout could be:
 
 @lisp
 (home-environment
@@ -44716,7 +44743,7 @@ Essential Home Services
   (services
     (service home-dotfiles-service-type
              (home-dotfiles-configuration
-               (directories (list "./dotfiles"))))))
+               (directories '("./dotfiles"))))))
 @end lisp
 
 The expected home directory state would then be:
@@ -44743,32 +44770,47 @@ Essential Home Services
 (and actually extends it), but designed to ease the way into using Guix
 Home for users that already track their dotfiles under some kind of version
 control.  This service allows users to point Guix Home to their dotfiles
-directory and have their files automatically deployed to their home directory
-just like Stow would, without migrating all of their dotfiles to Guix native
+directory and have their files automatically provisioned to their home
+directory, without migrating all of their dotfiles to Guix native
 configurations.
 @end defvar
 
+@c %start of fragment
+
 @deftp {Data Type} home-dotfiles-configuration
 Available @code{home-dotfiles-configuration} fields are:
 
 @table @asis
-@item @code{source-directory} (default: @code{(current-source-directory)})
-The path where dotfile directories are resolved. By default dotfile directories
-are resolved relative the source location where
+@item @code{source-directory} (default: @code{(current-source-directory)}) (type: string)
+The path where dotfile directories are resolved.  By default dotfile
+directories are resolved relative the source location where
 @code{home-dotfiles-configuration} appears.
 
-@item @code{directories} (type: list-of-strings)
-The list of dotfiles directories where @code{home-dotfiles-service-type} will
-look for application dotfiles.
+@item @code{layout} (default: @code{'plain}) (type: symbol)
+The intended layout of the specified @code{directory}.  It can be either
+@code{'stow} or @code{'plain}.
+
+@item @code{directories} (default: @code{'()}) (type: list-of-strings)
+The list of dotfiles directories where @code{home-dotfiles-service-type}
+will look for application dotfiles.
+
+@item @code{packages} (type: maybe-list-of-strings)
+The names of a subset of the GNU Stow package layer directories.  When provided
+the @code{home-dotfiles-service-type} will only provision dotfiles from this
+subset of applications.  This field will be ignored if @code{layout} is set
+to @code{'plain}.
 
-@item @code{exclude} (default: @code{'(".*~" ".*\\.swp" "\\.git" "\\.gitignore")})
-The list of file patterns @code{home-dotfiles-service-type} will exclude while
-visiting each one of the @code{directories}.
+@item @code{excluded} (default: @code{'(".*~" ".*\\.swp" "\\.git" "\\.gitignore")}) (type: list-of-strings)
+The list of file patterns @code{home-dotfiles-service-type} will exclude
+while visiting each one of the @code{directories}.
 
 @end table
 
 @end deftp
 
+
+@c %end of fragment
+
 @defvar home-xdg-configuration-files-service-type
 The service is very similar to @code{home-files-service-type} (and
 actually extends it), but used for defining files, which will go to
diff --git a/gnu/home/services/dotfiles.scm b/gnu/home/services/dotfiles.scm
index 6a740c42ce..823bdb03fb 100644
--- a/gnu/home/services/dotfiles.scm
+++ b/gnu/home/services/dotfiles.scm
@@ -20,17 +20,25 @@
 (define-module (gnu home services dotfiles)
   #:use-module (gnu home services)
   #:use-module (gnu services)
+  #:use-module (gnu services configuration)
   #:autoload   (guix build utils) (find-files)
+  #:use-module (guix diagnostics)
   #:use-module (guix gexp)
-  #:use-module (guix records)
+  #:use-module (guix i18n)
   #:use-module ((guix utils) #:select (current-source-directory))
   #:use-module (srfi srfi-1)
   #:use-module (ice-9 ftw)
+  #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
   #:export (home-dotfiles-service-type
+            home-dotfiles-configuration->files
+
             home-dotfiles-configuration
             home-dotfiles-configuration?
+            home-dotfiles-configuration-fields
+            home-dotfiles-configuration-layout
             home-dotfiles-configuration-source-directory
+            home-dotfiles-configuration-packages
             home-dotfiles-configuration-directories
             home-dotfiles-configuration-excluded))
 
@@ -40,26 +48,64 @@ (define %home-dotfiles-excluded
     "\\.git"
     "\\.gitignore"))
 
-(define-record-type* <home-dotfiles-configuration>
-  home-dotfiles-configuration make-home-dotfiles-configuration
-  home-dotfiles-configuration?
-  (source-directory  home-dotfiles-configuration-source-directory
-                     (default (current-source-directory))
-                     (innate))
-  (directories       home-dotfiles-configuration-directories       ;list of strings
-                     (default '()))
-  (excluded          home-dotfiles-configuration-excluded       ;list of strings
-                     (default %home-dotfiles-excluded)))
-
-(define (import-dotfiles directory files)
+(define %home-dotfiles-layouts
+  '(plain stow))
+
+(define (sanitize-layout value)
+  (if (member value %home-dotfiles-layouts)
+      value
+      (raise
+       (formatted-message
+        (G_ "layout field of home-dotfiles-configuration should be either 'plain
+or 'stow, but ~a was found.")
+        value))))
+
+(define list-of-strings?
+  (list-of string?))
+
+(define-maybe list-of-strings)
+
+(define-configuration/no-serialization home-dotfiles-configuration
+  (source-directory
+   (string (current-source-directory))
+   "The path where dotfile directories are resolved.  By default dotfile
+directories are resolved relative the source location where
+@code{home-dotfiles-configuration} appears.")
+  (layout
+   (symbol 'plain)
+   "The intended layout of the specified @code{directory}.  It can be either
+@code{'stow} or @code{'plain}."
+   (sanitizer sanitize-layout))
+  (directories
+   (list-of-strings '())
+   "The list of dotfiles directories where @code{home-dotfiles-service-type}
+will look for application dotfiles.")
+  (packages
+   (maybe-list-of-strings)
+   "The names of a subset of the GNU Stow package layer directories.  When provided
+the @code{home-dotfiles-service-type} will only provision dotfiles from this
+subset of applications.  This field will be ignored if @code{layout} is set
+to @code{'plain}.")
+  (excluded
+   (list-of-strings %home-dotfiles-excluded)
+   "The list of file patterns @code{home-dotfiles-service-type} will exclude
+while visiting @code{directory}."))
+
+(define (strip-stow-dotfile file-name directory)
+  (let ((dotfile-name (string-drop file-name (1+ (string-length directory)))))
+    (match (string-split dotfile-name #\/)
+      ((package parts ...)
+       (string-join parts "/")))))
+
+(define (strip-plain-dotfile file-name directory)
+  (string-drop file-name (+ 1 (string-length directory))))
+
+(define (import-dotfiles directory files strip)
   "Return a list of objects compatible with @code{home-files-service-type}'s
 value.  Each object is a pair where the first element is the relative path
 of a file and the second is a gexp representing the file content.  Objects are
 generated by recursively visiting DIRECTORY and mapping its contents to the
 user's home directory, excluding files that match any of the patterns in EXCLUDED."
-  (define (strip file)
-    (string-drop file (+ 1 (string-length directory))))
-
   (define (format file)
     ;; Remove from FILE characters that cannot be used in the store.
     (string-append
@@ -73,7 +119,7 @@ (define (import-dotfiles directory files)
                  file)))
 
   (map (lambda (file)
-         (let ((stripped (strip file)))
+         (let ((stripped (strip file directory)))
            (list stripped
                  (local-file file (format stripped)
                              #:recursive? #t))))
@@ -81,18 +127,25 @@ (define (import-dotfiles directory files)
 
 (define (home-dotfiles-configuration->files config)
   "Return a list of objects compatible with @code{home-files-service-type}'s
-value, generated following GNU Stow's algorithm for each of the
-directories in CONFIG, excluding files that match any of the patterns configured."
+value, excluding files that match any of the patterns configured."
+  (define stow? (eq? (home-dotfiles-configuration-layout config) 'stow))
   (define excluded
     (home-dotfiles-configuration-excluded config))
   (define exclusion-rx
     (make-regexp (string-append "^.*(" (string-join excluded "|") ")$")))
 
-  (define (directory-contents directory)
-    (find-files directory
-                (lambda (file stat)
-                  (not (regexp-exec exclusion-rx
-                                    (basename file))))))
+  (define* (directory-contents directory #:key (packages #f))
+    (define (filter-files directory)
+      (find-files directory
+                  (lambda (file stat)
+                    (not (regexp-exec exclusion-rx
+                                      (basename file))))))
+    (if (and stow? packages (maybe-value-set? packages))
+        (append-map filter-files
+                    (map (lambda (pkg)
+                           (string-append directory "/" pkg))
+                         packages))
+        (filter-files directory)))
 
   (define (resolve directory)
     ;; Resolve DIRECTORY relative to the 'source-directory' field of CONFIG.
@@ -103,15 +156,23 @@ (define (home-dotfiles-configuration->files config)
 
   (append-map (lambda (directory)
                 (let* ((directory (resolve directory))
-                       (contents  (directory-contents directory)))
-                  (import-dotfiles directory contents)))
+                       (packages
+                        (home-dotfiles-configuration-packages config))
+                       (contents
+                        (directory-contents directory
+                                            #:packages packages))
+                       (strip
+                        (if stow? strip-stow-dotfile strip-plain-dotfile)))
+                  (import-dotfiles directory contents strip)))
               (home-dotfiles-configuration-directories config)))
 
 (define-public home-dotfiles-service-type
   (service-type (name 'home-dotfiles)
                 (extensions
                  (list (service-extension home-files-service-type
-                                          home-dotfiles-configuration->files)))
+                                          (lambda (config)
+                                            (when config
+                                              (home-dotfiles-configuration->files config))))))
                 (default-value (home-dotfiles-configuration))
                 (description "Files that will be put in the user's home directory
 following GNU Stow's algorithm, and further processed during activation.")))

base-commit: f18d13b5f89c161c6ee88d15ecdaa8d973ee4503
-- 
2.41.0





Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Wed, 06 Mar 2024 22:17:02 GMT) Full text and rfc822 format available.

Notification sent to paul <goodoldpaul <at> autistici.org>:
bug acknowledged by developer. (Wed, 06 Mar 2024 22:17:02 GMT) Full text and rfc822 format available.

Message #58 received at 68857-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Giacomo Leidi <goodoldpaul <at> autistici.org>
Cc: paren <at> disroot.org, 68848-done <at> debbugs.gnu.org,
 Andrew Tropin <andrew <at> trop.in>, 68857-done <at> debbugs.gnu.org
Subject: Re: bug#68857: gnu: home: dotfiles: Avoid creating extra directory
 in $HOME.
Date: Wed, 06 Mar 2024 23:15:03 +0100
Hi,

Giacomo Leidi <goodoldpaul <at> autistici.org> skribis:

> The current implementation of the home-dotfiles-service-type contradicts
> the Guix manual (see https://issues.guix.gnu.org/68848 ). This patch
> properly implements both the plain and Stow dotfiles directory layouts.
>
> It does so by refactoring home-dotfiles-configuration adding a new
> packages field to support GNU Stow's users workflow and introducing
> a new layout field to switch between the two directory layouts.
>
> * gnu/home/services/dotfiles (home-dotfiles-configuration): Migrate to
> (gnu services configuration);
> [packages]: new field;
> [layout]: new field;
> (strip-stow-dotfile): new variable;
> (strip-plain-dotfile): new variable;
> (home-dotfiles-configuration->files): use the new fields;
> [directory-contents]: allow for
> selecting a subset of application dotfile directories;
> * doc/guix.texi: document the new layouts.
>
> Change-Id: I2e96037608353e360828290f055ec5271cfdfd48

Applied, thanks again!

Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 04 Apr 2024 11:24:22 GMT) Full text and rfc822 format available.

This bug report was last modified 113 days ago.

Previous Next


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