From patchwork Wed Apr 12 20:32:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Giacomo Leidi X-Patchwork-Id: 49113 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id B3DDD174EE; Wed, 12 Apr 2023 21:33:16 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id C1ABA174BB for ; Wed, 12 Apr 2023 21:33:13 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmh9L-0004Jk-Ib; Wed, 12 Apr 2023 16:33:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pmh9K-0004JT-IP for guix-patches@gnu.org; Wed, 12 Apr 2023 16:33:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmh9K-0000AA-2t; Wed, 12 Apr 2023 16:33:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pmh9J-0008AG-Tu; Wed, 12 Apr 2023 16:33:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#60521] [v3] home: Add home-dotfiles-service. References: <0a8d7bce31856292baa06a08260494c0@autistici.org> In-Reply-To: <0a8d7bce31856292baa06a08260494c0@autistici.org> Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, guix-patches@gnu.org Resent-Date: Wed, 12 Apr 2023 20:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60521 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: moreinfo patch To: 60521@debbugs.gnu.org Cc: Giacomo Leidi , ludo@gnu.org X-Debbugs-Original-Xcc: ludo@gnu.org Received: via spool by 60521-submit@debbugs.gnu.org id=B60521.168133155831351 (code B ref 60521); Wed, 12 Apr 2023 20:33:01 +0000 Received: (at 60521) by debbugs.gnu.org; 12 Apr 2023 20:32:38 +0000 Received: from localhost ([127.0.0.1]:41889 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pmh8v-00089b-EC for submit@debbugs.gnu.org; Wed, 12 Apr 2023 16:32:38 -0400 Received: from confino.investici.org ([93.190.126.19]:31285) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pmh8t-00089T-U5 for 60521@debbugs.gnu.org; Wed, 12 Apr 2023 16:32:36 -0400 Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4PxZC73KV2z110k; Wed, 12 Apr 2023 20:32:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1681331555; bh=WU7i1lQyZdlYbnvAvN4FOwUL11zxbLn2Z0mWAPpoTLo=; h=From:To:Cc:Subject:Date:From; b=HVYjafy/JxrTDTj1Dd2KuStCLNdRivHWFYhlkUY06ZwkP8GuQThksZ/I0WCdibkDH sBj9H91aBKv3KgosK8Pi1w6ipHlZa8lNdBR6sIHytjVi3hq/NtMfiNJXJe0oUrHOxN um5/H7v9svUhpCC3X4kDl3rD0Z2wLTPYhJuhZJY4= Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 4PxZC72lR6z110h; Wed, 12 Apr 2023 20:32:35 +0000 (UTC) Date: Wed, 12 Apr 2023 22:32:17 +0200 Message-Id: <20230412203217.32606-1-goodoldpaul@autistici.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Giacomo Leidi X-ACL-Warn: , Giacomo Leidi via Guix-patches X-Patchwork-Original-From: Giacomo Leidi via Guix-patches via From: Giacomo Leidi Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * 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 | 85 ++++++++++++++++++++++++++++++++++++++++++- gnu/home/services.scm | 54 +++++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 1 deletion(-) base-commit: dd3e5e71104a2bcbad80e52e062a144ea96b8c6a diff --git a/doc/guix.texi b/doc/guix.texi index acb6f0c2e1..b95053039f 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -111,9 +111,9 @@ Copyright @copyright{} 2022 (@* 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{} 2022 Antero Mejr@* Copyright @copyright{} 2023 Karl Hallsby +Copyright @copyright{} 2023 Giacomo Leidi@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -42029,6 +42029,89 @@ to use alternative services to implement more advanced use cases like 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 +@uref{https://www.gnu.org/software/stow/, GNU Stow}'s layout) 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: + +@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 a more formal specification please refer to the +@pxref{Top,,, stow, GNU Stow Manual}. 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. A suitable configuration would then +be: + +@lisp + (simple-service 'home-dotfiles + home-dotfiles-service-type + (list (string-append (getcwd) + "/.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 + @defvar home-xdg-configuration-files-service-type The service is very similiar 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..c45b8cbe24 100644 --- a/gnu/home/services.scm +++ b/gnu/home/services.scm @@ -2,6 +2,7 @@ ;;; Copyright © 2021-2023 Andrew Tropin ;;; Copyright © 2021 Xinglu Chen ;;; Copyright © 2022-2023 Ludovic Courtès +;;; Copyright © 2023 Giacomo Leidi ;;; ;;; 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) @@ -35,13 +37,17 @@ (define-module (gnu home services) #:use-module (guix modules) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) + #:use-module (ice-9 ftw) #:use-module (ice-9 match) + #: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-xdg-configuration-files-service-type home-xdg-data-files-service-type home-run-on-first-login-service-type @@ -341,6 +347,54 @@ (define home-files-service-type (description "Files that will be put in @file{~/.guix-home/files}, and further processed during activation."))) +(define (dotfiles-for-app directory) + "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." + (map (lambda (file) + (let ((file-relative-path + (string-drop file (1+ (string-length directory))))) + (list file-relative-path + (local-file file + (string-append "home-dotfiles-" + (string-replace-substring + file-relative-path + "/" "-")))))) + (find-files directory))) + +(define-public (home-dotfiles-configuration dotfiles-directories) + "Return a list of objects compatible with @code{home-files-service-type}'s +value, generated following GNU Stow's algorithm for each of the +DOTFILES-DIRECTORIES." + (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 + dotfiles-for-app + (directory-contents dotfiles-directories))) + +(define-public home-dotfiles-service-type + (service-type (name 'home-dotfiles) + (extensions + (list (service-extension home-files-service-type + home-dotfiles-configuration))) + (default-value '()) + (extend append) + (compose concatenate) + (description "Files contained is these directories will be put +in the user's home directory according to GNU Stow's algorithm, and further +processed during activation."))) + (define xdg-configuration-files-directory ".config") (define (xdg-configuration-files files)