From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id MGGWLd3X6GVXWAAAqHPOHw:P1 (envelope-from ) for ; Wed, 06 Mar 2024 21:53:49 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id MGGWLd3X6GVXWAAAqHPOHw (envelope-from ) for ; Wed, 06 Mar 2024 21:53:49 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=autistici.org header.s=stigmate header.b=ug1Swmrx; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1709758429; a=rsa-sha256; cv=none; b=gICj2Mw4VsAhFCW/YRCnTSKYqz4cKNIIxES68QaGjfd9vs3lUCP72fwwu7xe/kHrIKBVDU TuHnuhYlh5k3cP6+Z7xYcZAoCvBL6upCQgXKUCwM81d3nW8iS57v6bIwMA46MaXHnGHWFH 8K9PlWH8ltfd7CXsDeVxCdMfKJICmg/6gfAJWGUrQYrm2J6nf75qcki7pL+3WuGt4juiOM OTtXSLdW9lUQU1rzXhhl6soN0MlXtzeknyxVMBNy444dZpSDix0XWkEDJXFfhGrmQs/6GK xgXlLUcDYXcAzrKjt0e08giAEDNt/iiVpFj1U1z/A/xTIWgmVFrqt3e8KBiRxQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=autistici.org header.s=stigmate header.b=ug1Swmrx; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1709758429; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=KyTKp9+Y5tOvao5FVH6T7zBau3qai8s+o3jrfyGx8X4=; b=LHs76xPHd7350PyUpy8DFf0+JDjetRXyrR/22M4IlNbXrPR5JtPk+5rjem9FB1dqOFFe/7 KmSt1qI900Bca3noWR2XZ6CVS9i78uiCqMZF1JvYtB12g3BHLCNxgXi84xUuGmGqwLWo6G R9ZyZIcnWh5ff+9YE71787G3Cd2HSkO3zx9F2fiOUGU0uZZ6QXZEtvV7lTa4bYGlnoby3q ywj/k7sQMQMzeAlufF+OtQGjci7XknVfBnxub1L6egvPnKPR7Ofc1V7HUVzEe+zKg+eyEW dZLv69geB4Q+8Rz/MZA1eLj4OluzZb3VoB0A7DjvDR7qFN2eAaXmIWlKF6hcvw== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6CC876BBF6 for ; Wed, 6 Mar 2024 21:53:49 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhyGa-0001pZ-Gp; Wed, 06 Mar 2024 15:53:32 -0500 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 1rhyGZ-0001mw-3S for guix-patches@gnu.org; Wed, 06 Mar 2024 15:53:31 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhyGY-0000FT-R7 for guix-patches@gnu.org; Wed, 06 Mar 2024 15:53:30 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rhyH3-0001lX-QT for guix-patches@gnu.org; Wed, 06 Mar 2024 15:54:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68857] [PATCH v4] gnu: home: dotfiles: Properly support both plain and Stow directory layouts. References: <14bc720d-7fdc-516a-3018-58294c1cafcd@autistici.org> In-Reply-To: <14bc720d-7fdc-516a-3018-58294c1cafcd@autistici.org> Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: , guix-patches@gnu.org Resent-Date: Wed, 06 Mar 2024 20:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68857 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 68857@debbugs.gnu.org Cc: Giacomo Leidi , ( , Andrew Tropin , Ludovic =?UTF-8?Q?Court=C3=A8s?= X-Debbugs-Original-Xcc: ( , Andrew Tropin , Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 68857-submit@debbugs.gnu.org id=B68857.17097584386778 (code B ref 68857); Wed, 06 Mar 2024 20:54:01 +0000 Received: (at 68857) by debbugs.gnu.org; 6 Mar 2024 20:53:58 +0000 Received: from localhost ([127.0.0.1]:51742 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rhyGz-0001lF-I1 for submit@debbugs.gnu.org; Wed, 06 Mar 2024 15:53:58 -0500 Received: from confino.investici.org ([93.190.126.19]:58623) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rhyGx-0001l6-0E for 68857@debbugs.gnu.org; Wed, 06 Mar 2024 15:53:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1709758396; bh=KyTKp9+Y5tOvao5FVH6T7zBau3qai8s+o3jrfyGx8X4=; h=From:To:Cc:Subject:Date:From; b=ug1Swmrx1+9S6RlOkQfR3Y+nj8su95/ceWoYZ5AMymjKb69knQequp4P+Z7KXpmAv Xh7eY6To/slRaS/QfxCMT6pEWDUllq/ZqKQ3hH5HWFfGGFsiIgubwmlqK7CJGj9mSb Yvbx/QMebZbJG8YGx3tbjlkavaWeLTKxB/9duBaQ= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4Tql581LTnz119V; Wed, 6 Mar 2024 20:53:16 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 4Tql57567pz119P; Wed, 6 Mar 2024 20:53:15 +0000 (UTC) Date: Wed, 6 Mar 2024 21:52:42 +0100 Message-ID: X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 From: Giacomo Leidi via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -5.38 X-Spam-Score: -5.38 X-Migadu-Queue-Id: 6CC876BBF6 X-TUID: NLOP6u/7Vs1u 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 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