[PATCH-v4] home: Add home-dotfiles-service.

  • Done
  • quality assurance status badge
Details
2 participants
  • Efraim Flashner
  • Giacomo Leidi
Owner
unassigned
Submitted by
Giacomo Leidi
Severity
normal

Debbugs page

Giacomo Leidi wrote 2 years ago
(address . guix-patches@gnu.org)(name . Giacomo Leidi)(address . goodoldpaul@autistici.org)
b85ed5e41596e6035669cf826df19e7913ceda15.1687622341.git.goodoldpaul@autistici.org
* gnu/home/services.scm (dotfiles-for-app): New variable;
(home-dotfiles-configuration): new variable;
(home-dotfiles-service-type): new variable.
* doc/guix.texi: Document it.
---
doc/guix.texi | 108 ++++++++++++++++++++++++++++++++++++++++++
gnu/home/services.scm | 78 ++++++++++++++++++++++++++++++
2 files changed, 186 insertions(+)

Toggle diff (242 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index c961f706ec..cb3b0d05b0 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -42659,6 +42659,114 @@ Essential Home Services
read-only home. Feel free to experiment and share your results.
@end defvar
+It is often the case that Guix Home users already have a setup for versioning
+their user configuration files (also known as @emph{dotfiles}) in a single
+directory, and some way of automatically deploy changes to their user home.
+
+The @code{home-dotfiles-service-type} 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
+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
+version control, for example in the same repository where you'd track your
+Guix Home configuration.
+
+@example
+~$ tree -a .dotfiles/
+.dotfiles/
+├── git
+│ └── .gitconfig
+├── gpg
+│ └── .gnupg
+│ ├── gpg-agent.conf
+│ └── gpg.conf
+├── guile
+│ └── .guile
+├── guix
+│ └── .config
+│ └── guix
+│ └── channels.scm
+├── nix
+│ ├── .config
+│ │ └── nixpkgs
+│ │ └── config.nix
+│ └── .nix-channels
+├── tmux
+│ └── .tmux.conf
+└── vim
+ └── .vimrc
+
+13 directories, 10 files
+@end example
+
+For an informal specification please refer to the Stow manual
+(@pxref{Top,,, stow, Introduction}). A suitable configuration would then
+be:
+
+@lisp
+(use-modules (guix utils))
+
+(home-environment
+
+ [...]
+
+ (services
+ (service home-dotfiles-service-type
+ (home-dotfiles-configuration
+ (directories
+ (list (string-append (current-source-directory)
+ "/.dotfiles")))))))
+@end lisp
+
+The expected home directory state would be:
+
+@example
+.
+├── .config
+│ ├── guix
+│ │ └── channels.scm
+│ └── nixpkgs
+│ └── config.nix
+├── .gitconfig
+├── .gnupg
+│ ├── gpg-agent.conf
+│ └── gpg.conf
+├── .guile
+├── .nix-channels
+├── .tmux.conf
+└── .vimrc
+@end example
+
+@defvar home-dotfiles-service-type
+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 file automatically deployed to their home directory
+just like Stow would, without migrating all of their dotfiles to Guix native
+configurations.
+@end defvar
+
+@deftp {Data Type} home-dotfiles-configuration
+Available @code{home-dotfiles-configuration} fields are:
+
+@table @asis
+@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{exclude} (default: @code{'(".*~" ".*\\.swp" "\\.gitignore")})
+The list of file patterns @code{home-dotfiles-service-type} will exclude while
+visiting @code{directories}.
+
+@end table
+
+@end deftp
+
@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.scm b/gnu/home/services.scm
index b17a34d19d..2fe6508a9a 100644
--- a/gnu/home/services.scm
+++ b/gnu/home/services.scm
@@ -2,6 +2,7 @@
;;; Copyright © 2021-2023 Andrew Tropin <andrew@trop.in>
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
;;; Copyright © 2022-2023 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2023 Giacomo Leidi <goodoldpaul@autistici.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -22,6 +23,7 @@ (define-module (gnu home services)
#:use-module (gnu services)
#:use-module ((gnu packages package-management) #:select (guix))
#:use-module ((gnu packages base) #:select (coreutils))
+ #:use-module (guix build utils)
#:use-module (guix channels)
#:use-module (guix monads)
#:use-module (guix store)
@@ -33,15 +35,24 @@ (define-module (gnu home services)
#:use-module (guix diagnostics)
#:use-module (guix i18n)
#:use-module (guix modules)
+ #:use-module (guix records)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
+ #:use-module (ice-9 ftw)
#:use-module (ice-9 match)
+ #:use-module (ice-9 regex)
+ #:use-module (ice-9 string-fun)
#:use-module (ice-9 vlist)
#:export (home-service-type
home-profile-service-type
home-environment-variables-service-type
home-files-service-type
+ home-dotfiles-service-type
+ home-dotfiles-configuration
+ home-dotfiles-configuration?
+ home-dotfiles-configuration-directories
+ home-dotfiles-configuration-excluded
home-xdg-configuration-files-service-type
home-xdg-data-files-service-type
home-run-on-first-login-service-type
@@ -341,6 +352,73 @@ (define home-files-service-type
(description "Files that will be put in
@file{~/.guix-home/files}, and further processed during activation.")))
+(define %home-dotfiles-excluded
+ '(".*~"
+ ".*\\.swp"
+ "\\.gitignore"))
+
+(define-record-type* <home-dotfiles-configuration>
+ home-dotfiles-configuration make-home-dotfiles-configuration
+ home-dotfiles-configuration?
+ (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 excluded)
+ "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 filtered
+ (find-files directory
+ (lambda (file stat)
+ (not (string-match
+ (string-append
+ "^.*(" (string-join excluded "|") ")$") file)))))
+ (define (strip file)
+ (string-drop file (+ 1 (string-length directory))))
+ (define (format file)
+ (string-append "home-dotfiles-"
+ (string-replace-substring file "/" "-")))
+
+ (map (lambda (file)
+ (let* ((stripped (strip file)))
+ (list stripped
+ (local-file file (format stripped)))))
+ filtered))
+
+(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."
+ (define (directory-contents directories)
+ (append-map
+ (lambda (directory)
+ (map
+ (lambda (content)
+ (with-directory-excursion directory
+ (canonicalize-path content)))
+ (scandir directory
+ (lambda (name)
+ (not (member name '("." "..")))))))
+ directories))
+ (append-map
+ (lambda (app)
+ (import-dotfiles app (home-dotfiles-configuration-excluded config)))
+ (directory-contents
+ (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)))
+ (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.")))
+
(define xdg-configuration-files-directory ".config")
(define (xdg-configuration-files files)

base-commit: d6dc82e8cdb2d6114a12b06d449ce7f1150c7f70
--
2.40.1
paul wrote 2 years ago
close this please
(address . 64269@debbugs.gnu.org)
b91074cf-2a31-ca7e-da9f-d75a2105a4f5@autistici.org
apologies for the noise i opened this issue by mistake. you can close
it, thank you
Efraim Flashner wrote 2 years ago
(address . 64269-done@debbugs.gnu.org)
ZPoH9xMlozkN5OC7@pbp
On Sat, Jun 24, 2023 at 06:02:59PM +0200, paul via Guix-patches via wrote:
Toggle quote (3 lines)
> apologies for the noise i opened this issue by mistake. you can close it,
> thank you

closing

--
Efraim Flashner <efraim@flashner.co.il> רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEoov0DD5VE3JmLRT3Qarn3Mo9g1EFAmT6B/cACgkQQarn3Mo9
g1EHUA/9GwscsoIMQ8AYtgE28T78PPwXmDVGiKopJJX8Spo8uTCjImxeUSZ5VNjG
d5zAh8k6yi8D4UA+Rdc5xiTbmfEY9AajLBTIoNzK/w0AZSkwHOFWyl+PDj9gt/Lp
2iuG9ujK8HDeVahyzwqideOX29zap+ZwrmNE5AFANjECDrISyz1xTRbvW5vTIJR9
SydYj2WpqyqKkIxdW7cp3Xjp+8bDbZnOCQEaT9qIawp37IardSP6Fe1rq+M43BXz
LBMuK1qhnvZk5RUXTcNlDT2jrCg2Q9KZcjDRuHOv6AKPpp73MAX0jbGymUXHCPUq
Ryr+bX1SQRTnWU+sNj+yPO6K7avzpfH7JePYyhQjydIK9IEA6/rXJzdPd8ebBO5C
8bWu99wMF0m1btPjYQkJc9vQcYyw0ruHC86V+OLyQeD2zaB/THHHfF0rnYxlWF+T
pIsunKPJyN0eJTPKNa35iXTdWhuzukazHVoVO+5EiD1mlcz83u415WcPJIQ5KU5A
FYvpuMVy9EnpU4c5UqArNdjFomubRnW9cCJPpGpo3fC62JkzaP60eGkVpSvhcFjb
zMOFcT2vZmaJw34uqCNr2kPFVDLIXU93RnFolZmLUYGx6a64wALYDYpwFBUxwEz+
sTXIQlOnY3L2NjnogQyOblQh+T1mJ6OtYaIYjXkQwIvlHPXAqGM=
=3FwP
-----END PGP SIGNATURE-----


Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 64269@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 64269
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help