GNU bug report logs - #60521
[PATCH] home: Add home-stow-migration-service.

Previous Next

Package: guix-patches;

Reported by: goodoldpaul <at> autistici.org

Date: Tue, 3 Jan 2023 16:53:02 UTC

Severity: normal

Tags: moreinfo, patch

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

Bug is archived. No further changes may be made.

Full log


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

From: Ludovic Courtès <ludo <at> gnu.org>
To: Giacomo Leidi <goodoldpaul <at> autistici.org>
Cc: 60521 <at> debbugs.gnu.org
Subject: Re: bug#60521: [PATCH] home: Add home-stow-migration-service.
Date: Tue, 17 Jan 2023 14:09:37 +0100
Hi!

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

> * gnu/home/services.scm (dotfiles-for-app): New variable;
> (home-stow-migration-configuration): new variable;
> (home-stow-migration-service): new variable.
> * doc/guix.texi: Document it.

That looks very useful!

> @@ -41119,6 +41120,55 @@ to use alternative services to implement more advanced use cases like
>  read-only home.  Feel free to experiment and share your results.
>  @end defvr
>  
> +@deffn {Scheme Procedure} home-stow-migration-service

Perhaps write a short intro (one or two sentences) above?

> +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 GNU Stow users.  This service allows users to point Guix Home to
> +their Stow 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.
> +
> +A typical Stow setup consists of a source directory and a target directory.
> +The source directory must be structured as follows:
> +
> +@example
> +~$ tree -a .dotfiles/
> +.dotfiles/
> +├── git
> +│   └── .gitconfig
> +├── gpg
> +│   └── .gnupg
> +│       ├── gpg-agent.conf
> +│       └── gpg.conf
> +├── guile
> +│   └── .guile
> +├── guix
> +│   └── .config
> +│       └── guix
> +│           ├── channels.scm
> +│           └── .gitignore
> +├── nix
> +│   ├── .config
> +│   │   └── nixpkgs
> +│   │       └── config.nix
> +│   └── .nix-channels
> +├── tmux
> +│   └── .tmux.conf
> +└── vim
> +    └── .vimrc
> +
> +13 directories, 10 files
> +@end example
> +
> +A suitable configuration would then be:
> +
> +@lisp
> +  (home-stow-migration-service
> +   (string-append (getenv "HOME")
> +                  "/.dotfiles"))
> +@end lisp

Maybe add a description of what it’s going to do with those files?  It’s
kinda implicit but better be clear.

Also, I feel like there’s nothing really Stow-specific here; it just
happens to be a file layout convention that’s used by Stow, right?  So I
wonder if could frame it differently, by describing the expected file
tree structure first, and mentioning Stow only then?

Last, I suggest adding a cross-reference to the Stow manual, as in:

  @pxref{Top,,, stow, GNU Stow Manual}

> +(define (dotfiles-for-app app-dir)
> +  "Return a list of objects compatible with @{home-files-service-type}'s
                                               ^
Typo, should be @code.

> +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 APP-DIR and mapping its contents to the
> +user's home directory."
> +  (let ((app-absolute-path (canonicalize-path app-dir)))
> +    (map (lambda (path)
> +           (let ((app-file-relative-path
> +                  (string-replace-substring path
> +                                           (string-append app-absolute-path "/")
> +                                           "")))

Or just (string-drop path (string-length app-absolute-path)).

> +             (list app-file-relative-path
> +                   (local-file path
> +                               (string-append "home-stow-migration-"
> +                                              (string-replace-substring
> +                                               app-file-relative-path
> +                                               "/" "-"))))))
> +         (find-files app-absolute-path))))

Nitpick: by convention, the term “path” refers to “search paths”; here
we’d instead use “file name”, but you can also call the variable just
‘file’.

The other convention is to avoid abbreviations in identifiers, and to
avoid long identifiers for local variables.

So s/app-dir/directory/ etc.

> +(define (home-stow-migration-configuration stow-dir)
> +  "Return a list of objects compatible with @{home-files-service-type}'s
> +value, generated following GNU Stow's algorithm using STOW-DIR as input
> +directory."
> +  (define (dir-contents dir)
> +    (scandir dir
> +             (lambda (name)
> +               (not (member name '("." ".."))))))
> +  (fold append
> +        '()
> +        (map (lambda (app-dir)
> +               (dotfiles-for-app
> +                (string-append stow-dir "/" app-dir)))
> +             (dir-contents stow-dir))))

You can replace (fold append …) with (append-map …).

> +(define-public (home-stow-migration-service stow-dir)

You can drop this procedure.  Users are expected to write:

  (service home-stow-migration-service)

Could you send an updated patch?

Thanks!

Ludo’.




This bug report was last modified 1 year and 104 days ago.

Previous Next


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