Subject: Re: bug#68857: gnu: home: dotfiles: Avoid creating extra directory in $HOME.

From: Ludovic Courtès <[email-masked]>
Date: Tue, 20 Feb 2024 10:37:08 +0100

Hello Giacomo!

Giacomo Leidi <[email-masked]> 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’.