From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id CIdrBVOQDWXBFgEA9RJhRA:P1 (envelope-from ) for ; Fri, 22 Sep 2023 15:02:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:306:2d92::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id CIdrBVOQDWXBFgEA9RJhRA (envelope-from ) for ; Fri, 22 Sep 2023 15:02:11 +0200 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 98A933D253 for ; Fri, 22 Sep 2023 15:02:10 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=autistici.org header.s=stigmate header.b=AWQ2Q7us; 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"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1695387730; 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=f8HNJt7MQUDy5ZWR6nrFXHXrX9I8B3ygjQhMs3F3S+8=; b=n99zqgIzgUjdNY2vqgIBtjIS/TJwHaAXOQeNdIwoLYygKdRtQA6x4u9a7kWZ5uZ6xkIrcE hDXGvhrDum06/KirFnltYRj0Zl7DVoXvajWHib1/TcEL1C5+OiqN7WFhBkTfN98FFGxal/ tNFvm3Ut4XRRyUMssOf+6vXuoelmeg7Id58lBb0/b45Mb8BOeev1ZeaM7s2Z8iZaTDPvBH f318MqwKSJrVefqf88D4Kk53iTsy89XtuRerhEYI06RkNkBLEw5QcE1KhF15gRNGfGsHFh GUo/RmBhX1GW8khzbg4z+Ei/gqxtg6Ymof8vbE54GohH/VV8j6WRUGABHlQA4g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=autistici.org header.s=stigmate header.b=AWQ2Q7us; 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"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1695387730; a=rsa-sha256; cv=none; b=GJgKqFjx29ePoBevt3fqekFZfvqfbMJdWOlsKt6K6z+c+CWOZRRdCboC2oN8oYbWgu7YxW qJUKQM+9LdPrykLTBoR8U13Pw90Dfn7xzcetyNRMt/J8qhL/0N3jnQSSWHNaiS2pfON5p1 svkRViISpIOqOy6xIp//NYuOp9ThEgvFPsfIsKlsSqcdl+M/W280WipvmcVXkz4ULTzP1K Gy20kKFvGIUw/fyvS0xZWYOvByrwEkwieN49eResJhx937lFtiglcgJEwi5uRrGFCi/yJP NXLfSpnZOy7Ps1ncJNkw96hcaioz945PP+//n+QrfuB/m/NAOOvCQMtYGM8Lcg== Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjfnJ-0004hH-Aa; Fri, 22 Sep 2023 09:02:05 -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 1qjfn6-0004bG-QV for guix-patches@gnu.org; Fri, 22 Sep 2023 09:02:00 -0400 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 1qjfn5-0000xz-4G for guix-patches@gnu.org; Fri, 22 Sep 2023 09:01:52 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qjfnF-0005uD-MP for guix-patches@gnu.org; Fri, 22 Sep 2023 09:02:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#60521] [PATCH] 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: , guix-patches@gnu.org Resent-Date: Fri, 22 Sep 2023 13:02: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 , ( , 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 60521-submit@debbugs.gnu.org id=B60521.169538771922691 (code B ref 60521); Fri, 22 Sep 2023 13:02:01 +0000 Received: (at 60521) by debbugs.gnu.org; 22 Sep 2023 13:01:59 +0000 Received: from localhost ([127.0.0.1]:35626 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjfnC-0005tu-OO for submit@debbugs.gnu.org; Fri, 22 Sep 2023 09:01:59 -0400 Received: from confino.investici.org ([2a11:7980:1::2:0]:54533) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjfnA-0005tm-6c for 60521@debbugs.gnu.org; Fri, 22 Sep 2023 09:01:57 -0400 Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4RsXTh71Yfz113P; Fri, 22 Sep 2023 13:01:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1695387704; bh=f8HNJt7MQUDy5ZWR6nrFXHXrX9I8B3ygjQhMs3F3S+8=; h=From:To:Cc:Subject:Date:From; b=AWQ2Q7usYYMAE2oFtD/9GQCX11vQFVJbEQmKGr82TAMhgRBeJ5ndDIy6/WpLMqPC4 au1Jt3W5tx7dmO2LwzhL/7suQxC3qLbZkPhhcMG1qNOu0H7Ekj56z1z34O6GJXDY3t uoZ4wEXI02Y/86AebkDg8YcE3VFnNG0KOpX/8utk= Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 4RsXTh6CX8z111v; Fri, 22 Sep 2023 13:01:44 +0000 (UTC) Date: Fri, 22 Sep 2023 15:01:04 +0200 Message-ID: <88eee8890b69cd58052188348f89fc673fa1c922.1695387663.git.goodoldpaul@autistici.org> 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-Spam-Score: -3.70 X-Migadu-Scanner: mx2.migadu.com X-Migadu-Queue-Id: 98A933D253 X-Spam-Score: -3.70 X-TUID: 8C84jR83G9Ev * 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(+) diff --git a/doc/guix.texi b/doc/guix.texi index 617b8463e3..9d75253c2b 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -43239,6 +43239,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 8d53f2f4d3..8a74052b5a 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) @@ -34,15 +36,24 @@ (define-module (gnu home services) #:use-module (guix i18n) #:use-module (guix modules) #:use-module (guix memoization) + #: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 @@ -354,6 +365,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 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: f45c0c82289d409b4fac00464ea8b323839ba53f -- 2.41.0