Received: (at 76169-done) by debbugs.gnu.org; 18 May 2025 21:03:06 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sun May 18 17:03:05 2025 Received: from localhost ([127.0.0.1]:60938 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1uGlA1-0007YK-Ia for submit <at> debbugs.gnu.org; Sun, 18 May 2025 17:03:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60176) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <ludo@HIDDEN>) id 1uGl9z-0007Xm-Vb for 76169-done <at> debbugs.gnu.org; Sun, 18 May 2025 17:03:04 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <ludo@HIDDEN>) id 1uGl9p-0002Ff-Du; Sun, 18 May 2025 17:02:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=U8QB9t7yfu7V7ucgQO2UE4NOQMRh3Swh/48w9ryS0pM=; b=cbp8LUysav/2iSrDHJMv FOqnw23V9ZUGPECNO0jB46Lq9fnQ5Q9fgnbpLld1FWyJ8RvO5q5S03ECt4eWjgOHI9H3o6eu2nXJ/ 8woCD2Ulq0IaCm/2rYGt3MePsm2C+waeMGwqxmt97mT1zfGSERpp1kOa2y2J+iWYEnQ4m3uHcBGaD wCKNl9L5I4EldelXk0hhKZYHxJ90QNylGrvKJ/rwIrHphAtVt8VNsRqhOL4nBGyXDWQRuln/5fGLU eOKJtQjncYdViHD+eb8AWf4X0SHrz5GO4mhr27ahud3gc/b3W3ka0BTVrV20oaXlATaJm1a6EqIkr HJ8VqNERR0XW/A==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN> To: Giacomo Leidi <goodoldpaul@HIDDEN> Subject: Re: [bug#76169] [PATCH v9] home: Add home-restic-backup service. In-Reply-To: <dc03dc12641c39a192fddddfe91856eb839dff9f.1747494594.git.goodoldpaul@HIDDEN> (Giacomo Leidi's message of "Sat, 17 May 2025 17:09:54 +0200") References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <dc03dc12641c39a192fddddfe91856eb839dff9f.1747494594.git.goodoldpaul@HIDDEN> User-Agent: mu4e 1.12.9; emacs 29.4 X-URL: https://people.bordeaux.inria.fr/lcourtes/ X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu X-Revolutionary-Date: Nonidi 29 =?utf-8?Q?Flor=C3=A9al?= an 233 de la =?utf-8?Q?R=C3=A9volution=2C?= jour du =?utf-8?B?U8OpbmV2w6k=?= Date: Sun, 18 May 2025 22:05:09 +0200 Message-ID: <874ixhn0qy.fsf@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 76169-done Cc: Tanguy Le Carrour <tanguy@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Gabriel Wicki <gabriel@HIDDEN>, Andrew Tropin <andrew@HIDDEN>, Hilton Chain <hako@HIDDEN>, 76169-done <at> debbugs.gnu.org, Janneke Nieuwenhuizen <janneke@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -3.3 (---) Hello, Giacomo Leidi <goodoldpaul@HIDDEN> writes: > * gnu/services/backup.scm: Drop mcron obsolete export. > (restic-backup-job-program): Generalize to restic-program. > (lower-restic-backup-job): New procedure implementing a standard way to > lower restic-backup-job records into lists. > (restic-program): Implement general way to run restic commands, for > example to initialize repositories. > (restic-backup-configuration): Reimplement > with (guix records). > (restic-backup-job-{logfile,command,requirement,modules}): Add new > procedures and add support for Guix Home environments. > (restic-backup-job->shepherd-service): Add support for Guix Home > environments. > (restic-backup-service-activation): Drop procedure as now the Shepherd > takes care of creating timers log file directories. > (restic-backup-service-type): Drop profile and activation services extensions. > * gnu/home/services/backup.scm: New file. > * gnu/local.mk: Add this. > * doc/guix.texi: Document this. > > Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be Finally applied, thanks!
paul <goodoldpaul@HIDDEN>
:Ludovic Courtès <ludo@HIDDEN>
:Received: (at 76169) by debbugs.gnu.org; 17 May 2025 15:10:30 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat May 17 11:10:30 2025 Received: from localhost ([127.0.0.1]:49790 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1uGJBF-0004XG-AC for submit <at> debbugs.gnu.org; Sat, 17 May 2025 11:10:30 -0400 Received: from confino.investici.org ([2a11:7980:1::2:0]:46693) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1uGJBB-0004Wj-4F for 76169 <at> debbugs.gnu.org; Sat, 17 May 2025 11:10:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1747494624; bh=yvo5Ja/CaxQI4sbz376Q6L3v7VUXf6Xk9rsCU5zJ7LQ=; h=From:To:Cc:Subject:Date:From; b=TzWQBtSOy9MHHTc5K8ImM/FYGCdm+2Ae4kAuIAvxHd9Ukf+UXKYaMoo20dZ0yvQOs ktr/Rbq2si/Bf9fIGzVACEmGSjcV3L2Cywcx4ey+dMkFodrQUbGvy3SI+h5zQxRf5z P89DXw41AMD2GKzzCHdyLS/LXbW2hM7DBRJ2gW8s= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4b06nr1pHjz11Kh; Sat, 17 May 2025 15:10:24 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4b06nr0bLCz11Hq; Sat, 17 May 2025 15:10:24 +0000 (UTC) From: Giacomo Leidi <goodoldpaul@HIDDEN> To: 76169 <at> debbugs.gnu.org Subject: [PATCH v9] home: Add home-restic-backup service. Date: Sat, 17 May 2025 17:09:54 +0200 Message-ID: <dc03dc12641c39a192fddddfe91856eb839dff9f.1747494594.git.goodoldpaul@HIDDEN> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 X-Debbugs-Cc: Andrew Tropin <andrew@HIDDEN>, Gabriel Wicki <gabriel@HIDDEN>, Hilton Chain <hako@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 76169 Cc: Giacomo Leidi <goodoldpaul@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) * gnu/services/backup.scm: Drop mcron obsolete export. (restic-backup-job-program): Generalize to restic-program. (lower-restic-backup-job): New procedure implementing a standard way to lower restic-backup-job records into lists. (restic-program): Implement general way to run restic commands, for example to initialize repositories. (restic-backup-configuration): Reimplement with (guix records). (restic-backup-job-{logfile,command,requirement,modules}): Add new procedures and add support for Guix Home environments. (restic-backup-job->shepherd-service): Add support for Guix Home environments. (restic-backup-service-activation): Drop procedure as now the Shepherd takes care of creating timers log file directories. (restic-backup-service-type): Drop profile and activation services extensions. * gnu/home/services/backup.scm: New file. * gnu/local.mk: Add this. * doc/guix.texi: Document this. Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be --- doc/guix.texi | 82 ++++++++++++++- gnu/home/services/backup.scm | 38 +++++++ gnu/local.mk | 1 + gnu/services/backup.scm | 187 +++++++++++++++++++++++------------ 4 files changed, 243 insertions(+), 65 deletions(-) create mode 100644 gnu/home/services/backup.scm diff --git a/doc/guix.texi b/doc/guix.texi index 8e73685a216..98a9ed573aa 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -466,6 +466,7 @@ Top * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -44895,7 +44896,8 @@ Miscellaneous Services @item @code{log-file} (type: maybe-string) The file system path to the log file for this job. By default the file will have be @file{/var/log/restic-backup/@var{job-name}.log}, where @var{job-name} is the -name defined in the @code{name} field. +name defined in the @code{name} field. For Guix Home services it defaults to +@file{$XDG_STATE_HOME/shepherd/restic-backup/@var{job-name}.log}. @item @code{max-duration} (type: maybe-number) The maximum duration in seconds that a job may last. Past @@ -44922,8 +44924,10 @@ Miscellaneous Services evaluate to @code{calendar-event} records or to strings. Strings must contain Vixie cron date lines. -@item @code{requirement} (default: @code{'()}) (type: list-of-symbols) -The list of Shepherd services that this backup job depends upon. +@item @code{requirement} (type: maybe-list-of-symbols) +The list of Shepherd services that this backup job depends upon. When unset it +defaults to @code{'()}, for Guix Home. Otherwise to +@code{'(user-processes file-systems)}. @item @code{files} (default: @code{'()}) (type: list-of-lowerables) The list of files or directories to be backed up. It must be a list of @@ -48824,6 +48828,7 @@ Home Services * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -50414,6 +50419,77 @@ Guix Home Services @end lisp @end defvar +@node Backup Home Services +@subsection Backup Services + +The @code{(gnu home services backup)} module offers services for backing up +file system trees. For now, it provides the @code{home-restic-backup-service-type}. + +With @code{home-restic-backup-service-type}, you can periodically back up +directories and files with @uref{https://restic.net/, Restic}, which +supports end-to-end encryption and deduplication. Consider the +following configuration: + +@lisp +(use-modules (gnu home services backup) ;for 'restic-backup-job', 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (simple-service 'backup-jobs + home-restic-backup-service-type + (list (restic-backup-job + (name "remote-ftp") + (repository "rclone:remote-ftp:backup/restic") + (password-file "/home/alice/.restic") + ;; Every day at 23. + (schedule "0 23 * * *") + (files '("/home/alice/.restic" + "/home/alice/.config/rclone" + "/home/alice/Pictures")))))))) +@end lisp + +In general it is preferrable to extend the @code{home-restic-backup-service-type}, +as shown in the example above. This is because it takes care of wrapping everything +with @code{for-home}, which enables the @code{home-restic-backup-service-type} and +@code{restic-backup-service-type} to share the same codebase. + +For a custom configuration, wrap your @code{restic-backup-configuration} in +@code{for-home}, as in this example: + +@lisp +(use-modules (gnu services) ;for 'for-home' + (gnu services backup) ;for 'restic-backup-job' and 'restic-backup-configuration' + (gnu home services backup) ;for 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (service home-restic-backup-service-type + (for-home + (restic-backup-configuration + (jobs (list @dots{})))))))) +@end lisp + +You can refer to @pxref{Miscellaneous Services, +@code{restic-backup-service-type}} for details about +@code{restic-backup-configuration} and @code{restic-backup-job}. +The only difference is that the @code{home-restic-backup-service-type} +will ignore the @code{user} and @code{group} field of +@code{restic-backup-job}. + @node Fonts Home Services @subsection Fonts Home Services diff --git a/gnu/home/services/backup.scm b/gnu/home/services/backup.scm new file mode 100644 index 00000000000..ac977f835b6 --- /dev/null +++ b/gnu/home/services/backup.scm @@ -0,0 +1,38 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2025 Giacomo Leidi <goodoldpaul@HIDDEN> +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. + +(define-module (gnu home services backup) + #:use-module (gnu services) + #:use-module (gnu services backup) + #:use-module (gnu home services) + #:use-module (gnu home services shepherd) + #:export (home-restic-backup-service-type) + #:re-export (restic-backup-configuration + restic-backup-job)) + +(define home-restic-backup-service-type + (service-type + (inherit (system->home-service-type restic-backup-service-type)) + (extend + (lambda (config jobs) + (for-home + (restic-backup-configuration + (inherit config) + (jobs (append (restic-backup-configuration-jobs config) + jobs)))))) + (default-value (for-home (restic-backup-configuration))))) diff --git a/gnu/local.mk b/gnu/local.mk index dfafe8b8953..7311c33f0f6 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -103,6 +103,7 @@ GNU_SYSTEM_MODULES = \ %D%/home.scm \ %D%/home/services.scm \ %D%/home/services/admin.scm \ + %D%/home/services/backup.scm \ %D%/home/services/desktop.scm \ %D%/home/services/dict.scm \ %D%/home/services/dotfiles.scm \ diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm index 6e066bd3d66..8fdf9ce902f 100644 --- a/gnu/services/backup.scm +++ b/gnu/services/backup.scm @@ -28,6 +28,7 @@ (define-module (gnu services backup) #:prefix license:) #:use-module (guix modules) #:use-module (guix packages) + #:use-module (guix records) #:use-module (srfi srfi-1) #:export (restic-backup-job restic-backup-job? @@ -47,16 +48,21 @@ (define-module (gnu services backup) restic-backup-job-verbose? restic-backup-job-extra-flags + lower-restic-backup-job + restic-backup-configuration restic-backup-configuration? - restic-backup-configuration-fields restic-backup-configuration-jobs restic-backup-job-program - restic-backup-job->mcron-job + restic-backup-job->shepherd-service restic-guix restic-guix-wrapper-package restic-backup-service-profile + restic-program + restic-job-log-file + restic-backup-job-command + restic-backup-job-modules restic-backup-service-type)) (define (gexp-or-string? value) @@ -75,6 +81,8 @@ (define list-of-symbols? (define-maybe/no-serialization string) (define-maybe/no-serialization number) +(define-maybe/no-serialization symbol) +(define-maybe/no-serialization list-of-symbols) (define-configuration/no-serialization restic-backup-job (restic @@ -90,7 +98,8 @@ (define-configuration/no-serialization restic-backup-job (maybe-string) "The file system path to the log file for this job. By default the file will have be @file{/var/log/restic-backup/@var{job-name}.log}, where @var{job-name} is the -name defined in the @code{name} field.") +name defined in the @code{name} field. For Guix Home services it defaults to +@file{$XDG_STATE_HOME/shepherd/restic-backup/@var{job-name}.log}.") (max-duration (maybe-number) "The maximum duration in seconds that a job may last. Past @@ -117,8 +126,10 @@ (define-configuration/no-serialization restic-backup-job evaluate to @code{calendar-event} records or to strings. Strings must contain Vixie cron date lines.") (requirement - (list-of-symbols '()) - "The list of Shepherd services that this backup job depends upon.") + (maybe-list-of-symbols) + "The list of Shepherd services that this backup job depends upon. When unset it +defaults to @code{'()}, for Guix Home. Otherwise to +@code{'(user-processes file-systems)}.") (files (list-of-lowerables '()) "The list of files or directories to be backed up. It must be a list of @@ -131,15 +142,20 @@ (define-configuration/no-serialization restic-backup-job "A list of values that are lowered to strings. These will be passed as command-line arguments to the current job @command{restic backup} invocation.")) -(define list-of-restic-backup-jobs? - (list-of restic-backup-job?)) +;; (for-home (restic-backup-configuration ...)) is not able to replace for-home? with #t, +;; pk prints #f. Once for-home will be able to work with (gnu services configuration) the +;; record can be migrated back to define-configuration. +(define-record-type* <restic-backup-configuration> + restic-backup-configuration + make-restic-backup-configuration + restic-backup-configuration? + this-restic-backup-configuration -(define-configuration/no-serialization restic-backup-configuration - (jobs - (list-of-restic-backup-jobs '()) - "The list of backup jobs for the current system.")) + (jobs restic-backup-configuration-jobs (default '())) ; list of restic-backup-job + (home-service? restic-backup-configuration-home-service? + (default for-home?) (innate))) -(define (restic-backup-job-program config) +(define (lower-restic-backup-job config) (let ((restic (file-append (restic-backup-job-restic config) "/bin/restic")) (repository @@ -150,22 +166,42 @@ (define (restic-backup-job-program config) (restic-backup-job-files config)) (extra-flags (restic-backup-job-extra-flags config)) - (verbose + (verbose? (if (restic-backup-job-verbose? config) '("--verbose") '()))) - (program-file - "restic-backup-job.scm" - #~(begin - (use-modules (ice-9 popen) - (ice-9 rdelim)) - (setenv "RESTIC_PASSWORD" - (with-input-from-file #$password-file read-line)) - - (execlp #$restic #$restic #$@verbose - "-r" #$repository - #$@extra-flags - "backup" #$@files))))) + #~(list (list #$@files) #$restic #$repository #$password-file + (list #$@verbose?) (list #$@extra-flags)))) + +(define restic-program + #~(lambda (action action-args job-restic repository password-file verbose? extra-flags) + (use-modules (ice-9 format)) + ;; This can be extended later, i.e. to have a + ;; centrally defined restic package. + ;; See https://issues.guix.gnu.org/71639 + (define restic job-restic) + + (define command + `(,restic ,@verbose? + "-r" ,repository + ,@extra-flags + ,action ,@action-args)) + + (setenv "RESTIC_PASSWORD_FILE" password-file) + + (when (> (length verbose?) 0) + (format #t "Running~{ ~a~}~%" command)) + + (apply execlp `(,restic ,@command)))) + +(define (restic-backup-job-program config) + (program-file + "restic-backup" + #~(let ((restic-exec + #$restic-program) + (job #$(lower-restic-backup-job config))) + + (apply restic-exec `("backup" ,@job))))) (define (restic-guix jobs) (program-file @@ -207,55 +243,89 @@ (define (restic-guix jobs) (main (command-line))))) -(define (restic-job-log-file job) +(define* (restic-job-log-file job #:key (home-service? #f)) (let ((name (restic-backup-job-name job)) (log-file (restic-backup-job-log-file job))) (if (maybe-value-set? log-file) log-file - (string-append "/var/log/restic-backup/" name ".log")))) + (if home-service? + #~(begin + (use-modules (shepherd support)) + (string-append %user-log-dir "/restic-backup/" #$name ".log")) + (string-append "/var/log/restic-backup/" name ".log"))))) + +(define* (restic-backup-job-command name files #:key (home-service? #f)) + (if home-service? + #~(list + "restic-guix" "backup" #$name) + ;; We go through bash, instead of executing + ;; restic-guix directly, because the login shell + ;; gives us the correct user environment that some + ;; backends require, such as rclone. + #~(list + (string-append #$bash-minimal "/bin/bash") + "-l" "-c" + (string-append "restic-guix backup " #$name)))) -(define (restic-backup-job->shepherd-service config) +(define* (restic-job-requirement config #:key (home-service? #f)) + (define maybe-requirement (restic-backup-job-requirement config)) + (if (maybe-value-set? maybe-requirement) + maybe-requirement + (if home-service? + '() + '(user-processes file-systems)))) + +(define* (restic-backup-job-modules #:key (home-service? #f)) + `((shepherd service timer) + ,@(if home-service? + ;;for %user-log-dir + '((shepherd support)) + '()))) + +(define* (restic-backup-job->shepherd-service config #:key (home-service? #f)) (let ((schedule (restic-backup-job-schedule config)) (name (restic-backup-job-name config)) + (files (restic-backup-job-files config)) (user (restic-backup-job-user config)) (group (restic-backup-job-group config)) (max-duration (restic-backup-job-max-duration config)) (wait-for-termination? (restic-backup-job-wait-for-termination? config)) - (log-file (restic-job-log-file config)) - (requirement (restic-backup-job-requirement config))) + (log-file (restic-job-log-file + config #:home-service? home-service?)) + (requirement + (restic-job-requirement config #:home-service? home-service?))) (shepherd-service (provision `(,(string->symbol name))) - (requirement - `(user-processes file-systems ,@requirement)) + (requirement requirement) (documentation - "Run @code{restic} backed backups on a regular basis.") - (modules '((shepherd service timer))) + "Run restic backed backups on a regular basis.") + (modules (restic-backup-job-modules + #:home-service? home-service?)) (start #~(make-timer-constructor (if (string? #$schedule) (cron-string->calendar-event #$schedule) #$schedule) (command - (list - ;; We go through bash, instead of executing - ;; restic-guix directly, because the login shell - ;; gives us the correct user environment that some - ;; backends require, such as rclone. - (string-append #+bash-minimal "/bin/bash") - "-l" "-c" - (string-append "restic-guix backup " #$name)) - #:user #$user - #:group #$group - #:environment-variables - (list - (string-append - "HOME=" (passwd:dir (getpwnam #$user))))) + #$(restic-backup-job-command + name files #:home-service? home-service?) + #$@(if home-service? '() (list #:user user)) + #$@(if home-service? '() (list #:group group)) + #$@(if home-service? '() + (list + #:environment-variables + #~(list + (string-append + "HOME=" (passwd:dir (getpwnam #$user))))))) #:log-file #$log-file #:wait-for-termination? #$wait-for-termination? #:max-duration #$(and (maybe-value-set? max-duration) max-duration))) (stop #~(make-timer-destructor)) - (actions (list shepherd-trigger-action))))) + (actions (list (shepherd-action + (inherit shepherd-trigger-action) + (documentation "Manually trigger a backup, +without waiting for the scheduled time."))))))) (define (restic-guix-wrapper-package jobs) (package @@ -283,26 +353,19 @@ (define restic-backup-service-profile (restic-guix-wrapper-package jobs)) '()))) -(define (restic-backup-activation config) - #~(for-each - (lambda (log-file) - (mkdir-p (dirname log-file))) - (list #$@(map restic-job-log-file - (restic-backup-configuration-jobs config))))) - (define restic-backup-service-type (service-type (name 'restic-backup) (extensions (list - (service-extension activation-service-type - restic-backup-activation) (service-extension profile-service-type restic-backup-service-profile) (service-extension shepherd-root-service-type - (lambda (config) - (map restic-backup-job->shepherd-service - (restic-backup-configuration-jobs - config)))))) + (match-record-lambda <restic-backup-configuration> + (jobs home-service?) + (map (lambda (job) + (restic-backup-job->shepherd-service + job #:home-service? home-service?)) + jobs))))) (compose concatenate) (extend (lambda (config jobs) base-commit: 9f3d8dbda60bb1dd15d2956c334354947df8b3f5 -- 2.49.0
andrew@HIDDEN, gabriel@HIDDEN, hako@HIDDEN, janneke@HIDDEN, ludo@HIDDEN, maxim.cournoyer@HIDDEN, tanguy@HIDDEN, guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 17 May 2025 15:09:27 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat May 17 11:09:27 2025 Received: from localhost ([127.0.0.1]:49778 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1uGJAF-0004MJ-El for submit <at> debbugs.gnu.org; Sat, 17 May 2025 11:09:27 -0400 Received: from confino.investici.org ([2a11:7980:1::2:0]:33701) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1uGJAC-0004M5-Bw for 76169 <at> debbugs.gnu.org; Sat, 17 May 2025 11:09:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1747494561; bh=Cbe2bbhBCTOCCRVS5yvNNH7GQ60PWg5S+v/P/QP/VxM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=aRaXs3rs2e5GPC2p51DQUXFWkXAHHeNaChTwjy3y7eQCWb0o5ODWTfZOSv6EMxwAq F+3Iw6pCLCHDYiR8qYtp52uajsFCyyXHcw+AU+dS3wMoJJMhj1HmYz9D6XURL/FhrE pss8wsqKVHTjzckuMJL+8TfGHLpPoxd5xc9sPIII= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4b06md1CSBz11LR; Sat, 17 May 2025 15:09:21 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4b06mc5M2Kz11Hq; Sat, 17 May 2025 15:09:20 +0000 (UTC) Message-ID: <d2c40ba8-b2ff-4b79-97ef-94bd2af465c4@HIDDEN> Date: Sat, 17 May 2025 17:09:20 +0200 MIME-Version: 1.0 User-Agent: Icedove Daily Subject: Re: [bug#76169] home: Add home-restic-backup service. To: =?UTF-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN> References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <c26fa6a42c1d223cda6803f11a521279d488920f.1746577702.git.goodoldpaul@HIDDEN> <87o6vy5ngt.fsf@HIDDEN> Content-Language: en-US From: paul <goodoldpaul@HIDDEN> In-Reply-To: <87o6vy5ngt.fsf@HIDDEN> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 76169 Cc: 76169 <at> debbugs.gnu.org, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Gabriel Wicki <gabriel@HIDDEN>, Andrew Tropin <andrew@HIDDEN>, Hilton Chain <hako@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) Sorry I've been copy-pasting code manually and forgot some :/ v9 should build fine. thank you for your help. cheers, giacomo
guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Maxim Cournoyer <maxim.cournoyer@HIDDEN>
to control <at> debbugs.gnu.org
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 12 May 2025 07:07:58 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Mon May 12 03:07:58 2025 Received: from localhost ([127.0.0.1]:49527 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1uENGX-0006PC-HC for submit <at> debbugs.gnu.org; Mon, 12 May 2025 03:07:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39926) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <ludo@HIDDEN>) id 1uENGR-0006OG-SS for 76169 <at> debbugs.gnu.org; Mon, 12 May 2025 03:07:52 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <ludo@HIDDEN>) id 1uENGI-0007f6-E8; Mon, 12 May 2025 03:07:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=96UoZwWNqRYXhDXYT8aKf4T4Tbw4G6EbjEuvlbLMcrM=; b=MyEYeRRhDK24LmsWpjxz 76Bwg8ZFbEdWiYax3rWVnqd7QwMwELr2axY6NRD/dDsgMi4vlEwfDSySjY06y3kYXHQ+RDBR60jYW xzBZJsA4uf9VfvViBo6YRRLGXhIaIMzMOATNohKHXlil7pL0GwSvn2XO6DwckmNcprXRTCa7hP+7U q0Zl9ezFLYRtbTcZL2gs7uXfZ6lp9MK2grfjvmz/+ztVWCAmFvrWoKMxp7UABL7H197Xs788pWSNm FJzc5jusrdWaR/uAnagmpf1dTHzP9RckBXijCB9gWEkek/84OqOogkS38SrISRDGZcoOs3upVEU3Y +B2izJ06wjSoFg==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN> To: Giacomo Leidi <goodoldpaul@HIDDEN> Subject: Re: [bug#76169] [PATCH v8] home: Add home-restic-backup service. In-Reply-To: <c26fa6a42c1d223cda6803f11a521279d488920f.1746577702.git.goodoldpaul@HIDDEN> (Giacomo Leidi's message of "Wed, 7 May 2025 02:28:22 +0200") References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <c26fa6a42c1d223cda6803f11a521279d488920f.1746577702.git.goodoldpaul@HIDDEN> User-Agent: mu4e 1.12.9; emacs 29.4 X-URL: https://people.bordeaux.inria.fr/lcourtes/ X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu X-Revolutionary-Date: Tridi 23 =?utf-8?Q?Flor=C3=A9al?= an 233 de la =?utf-8?Q?R=C3=A9volution=2C?= jour de la Bourrache Date: Mon, 12 May 2025 08:53:38 +0200 Message-ID: <87o6vy5ngt.fsf@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 76169 Cc: 76169 <at> debbugs.gnu.org, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Gabriel Wicki <gabriel@HIDDEN>, Andrew Tropin <andrew@HIDDEN>, Hilton Chain <hako@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -3.3 (---) Hi, Giacomo Leidi <goodoldpaul@HIDDEN> writes: > * gnu/services/backup.scm: Drop mcron obsolete export. > (restic-backup-job-program): Generalize to restic-program. > (lower-restic-backup-job): New procedure implementing a standard way to > lower restic-backup-job records into lists. > (restic-program): Implement general way to run restic commands, for > example to initialize repositories. > (restic-backup-configuration): Reimplement > with (guix records). > (restic-backup-job-{logfile,command,requirement,modules}): Add new > procedures and add support for Guix Home environments. > (restic-backup-job->shepherd-service): Add support for Guix Home > environments. > (restic-backup-service-activation): Drop procedure as now the Shepherd > takes care of creating timers log file directories. > (restic-backup-service-type): Drop profile and activation services extens= ions. > * gnu/home/services/backup.scm: New file. > * gnu/local.mk: Add this. > * doc/guix.texi: Document this. > > Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be We must be getting closer, but=E2=80=A6 --8<---------------cut here---------------start------------->8--- [ 94%] LOAD gnu/home/services/backup.scm ;;; note: source file ./gnu/services/backup.scm ;;; newer than compiled /home/ludo/src/guix/gnu/services/backup.go ;;; note: source file ./gnu/services/backup.scm ;;; newer than compiled /home/ludo/src/guix/gnu/services/backup.go ice-9/eval.scm:293:34: error: maybe-list-of-symbols?: unbound variable [1;36mhint: [0mDid you forget a `use-modules' form? make[2]: *** [Makefile:7696: make-system-go] Error 1 --8<---------------cut here---------------end--------------->8--- Could you take a look? Ludo=E2=80=99.
guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 7 May 2025 00:28:41 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Tue May 06 20:28:41 2025 Received: from localhost ([127.0.0.1]:35994 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1uCSeN-0000xj-Rx for submit <at> debbugs.gnu.org; Tue, 06 May 2025 20:28:41 -0400 Received: from confino.investici.org ([2a11:7980:1::2:0]:22603) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1uCSeL-0000xV-0Y for 76169 <at> debbugs.gnu.org; Tue, 06 May 2025 20:28:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1746577716; bh=FgcF0YlwTPKYpO1CVgmRc8P8RxPfyQVMrQ+ybG3fpDU=; h=From:To:Cc:Subject:Date:From; b=jKCQSEpjaivuUPHI4iqPjM7gURVJlsMWZpAqpMIqLpAtAZMjggr6Na1iNcDifFR2Y tQuRbLidYOMPPXM9EcecwgHn7klg+xKttORUz8h37M49DV5RYupFrwV79u3035NCHK RbA4cvuDF7ViZ2yODw4kRFsyDpwyTB5K/i67A5LY= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4Zsbj01STKz11JZ; Wed, 7 May 2025 00:28:36 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4Zsbj00KZsz11JN; Wed, 7 May 2025 00:28:36 +0000 (UTC) From: Giacomo Leidi <goodoldpaul@HIDDEN> To: 76169 <at> debbugs.gnu.org Subject: [PATCH v8] home: Add home-restic-backup service. Date: Wed, 7 May 2025 02:28:22 +0200 Message-ID: <c26fa6a42c1d223cda6803f11a521279d488920f.1746577702.git.goodoldpaul@HIDDEN> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 X-Debbugs-Cc: Andrew Tropin <andrew@HIDDEN>, Gabriel Wicki <gabriel@HIDDEN>, Hilton Chain <hako@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 76169 Cc: Giacomo Leidi <goodoldpaul@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) * gnu/services/backup.scm: Drop mcron obsolete export. (restic-backup-job-program): Generalize to restic-program. (lower-restic-backup-job): New procedure implementing a standard way to lower restic-backup-job records into lists. (restic-program): Implement general way to run restic commands, for example to initialize repositories. (restic-backup-configuration): Reimplement with (guix records). (restic-backup-job-{logfile,command,requirement,modules}): Add new procedures and add support for Guix Home environments. (restic-backup-job->shepherd-service): Add support for Guix Home environments. (restic-backup-service-activation): Drop procedure as now the Shepherd takes care of creating timers log file directories. (restic-backup-service-type): Drop profile and activation services extensions. * gnu/home/services/backup.scm: New file. * gnu/local.mk: Add this. * doc/guix.texi: Document this. Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be --- doc/guix.texi | 82 ++++++++++++++- gnu/home/services/backup.scm | 38 +++++++ gnu/local.mk | 1 + gnu/services/backup.scm | 189 +++++++++++++++++++++++------------ 4 files changed, 245 insertions(+), 65 deletions(-) create mode 100644 gnu/home/services/backup.scm diff --git a/doc/guix.texi b/doc/guix.texi index 889eab2ab35..c8d56678e39 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -465,6 +465,7 @@ Top * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -44788,7 +44789,8 @@ Miscellaneous Services @item @code{log-file} (type: maybe-string) The file system path to the log file for this job. By default the file will have be @file{/var/log/restic-backup/@var{job-name}.log}, where @var{job-name} is the -name defined in the @code{name} field. +name defined in the @code{name} field. For Guix Home services it defaults to +@file{$XDG_STATE_HOME/shepherd/restic-backup/@var{job-name}.log}. @item @code{max-duration} (type: maybe-number) The maximum duration in seconds that a job may last. Past @@ -44815,8 +44817,10 @@ Miscellaneous Services evaluate to @code{calendar-event} records or to strings. Strings must contain Vixie cron date lines. -@item @code{requirement} (default: @code{'()}) (type: list-of-symbols) -The list of Shepherd services that this backup job depends upon. +@item @code{requirement} (type: maybe-list-of-symbols) +The list of Shepherd services that this backup job depends upon. When unset it +defaults to @code{'()}, for Guix Home. Otherwise to +@code{'(user-processes file-systems)}. @item @code{files} (default: @code{'()}) (type: list-of-lowerables) The list of files or directories to be backed up. It must be a list of @@ -48717,6 +48721,7 @@ Home Services * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -50307,6 +50312,77 @@ Guix Home Services @end lisp @end defvar +@node Backup Home Services +@subsection Backup Services + +The @code{(gnu home services backup)} module offers services for backing up +file system trees. For now, it provides the @code{home-restic-backup-service-type}. + +With @code{home-restic-backup-service-type}, you can periodically back up +directories and files with @uref{https://restic.net/, Restic}, which +supports end-to-end encryption and deduplication. Consider the +following configuration: + +@lisp +(use-modules (gnu home services backup) ;for 'restic-backup-job', 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (simple-service 'backup-jobs + home-restic-backup-service-type + (list (restic-backup-job + (name "remote-ftp") + (repository "rclone:remote-ftp:backup/restic") + (password-file "/home/alice/.restic") + ;; Every day at 23. + (schedule "0 23 * * *") + (files '("/home/alice/.restic" + "/home/alice/.config/rclone" + "/home/alice/Pictures")))))))) +@end lisp + +In general it is preferrable to extend the @code{home-restic-backup-service-type}, +as shown in the example above. This is because it takes care of wrapping everything +with @code{for-home}, which enables the @code{home-restic-backup-service-type} and +@code{restic-backup-service-type} to share the same codebase. + +For a custom configuration, wrap your @code{restic-backup-configuration} in +@code{for-home}, as in this example: + +@lisp +(use-modules (gnu services) ;for 'for-home' + (gnu services backup) ;for 'restic-backup-job' and 'restic-backup-configuration' + (gnu home services backup) ;for 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (service home-restic-backup-service-type + (for-home + (restic-backup-configuration + (jobs (list @dots{})))))))) +@end lisp + +You can refer to @pxref{Miscellaneous Services, +@code{restic-backup-service-type}} for details about +@code{restic-backup-configuration} and @code{restic-backup-job}. +The only difference is that the @code{home-restic-backup-service-type} +will ignore the @code{user} and @code{group} field of +@code{restic-backup-job}. + @node Fonts Home Services @subsection Fonts Home Services diff --git a/gnu/home/services/backup.scm b/gnu/home/services/backup.scm new file mode 100644 index 00000000000..ac977f835b6 --- /dev/null +++ b/gnu/home/services/backup.scm @@ -0,0 +1,38 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2025 Giacomo Leidi <goodoldpaul@HIDDEN> +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. + +(define-module (gnu home services backup) + #:use-module (gnu services) + #:use-module (gnu services backup) + #:use-module (gnu home services) + #:use-module (gnu home services shepherd) + #:export (home-restic-backup-service-type) + #:re-export (restic-backup-configuration + restic-backup-job)) + +(define home-restic-backup-service-type + (service-type + (inherit (system->home-service-type restic-backup-service-type)) + (extend + (lambda (config jobs) + (for-home + (restic-backup-configuration + (inherit config) + (jobs (append (restic-backup-configuration-jobs config) + jobs)))))) + (default-value (for-home (restic-backup-configuration))))) diff --git a/gnu/local.mk b/gnu/local.mk index e6ece8cc483..3d4316454a8 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -103,6 +103,7 @@ GNU_SYSTEM_MODULES = \ %D%/home.scm \ %D%/home/services.scm \ %D%/home/services/admin.scm \ + %D%/home/services/backup.scm \ %D%/home/services/desktop.scm \ %D%/home/services/dict.scm \ %D%/home/services/dotfiles.scm \ diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm index 6e066bd3d66..06f68302682 100644 --- a/gnu/services/backup.scm +++ b/gnu/services/backup.scm @@ -28,6 +28,7 @@ (define-module (gnu services backup) #:prefix license:) #:use-module (guix modules) #:use-module (guix packages) + #:use-module (guix records) #:use-module (srfi srfi-1) #:export (restic-backup-job restic-backup-job? @@ -47,16 +48,21 @@ (define-module (gnu services backup) restic-backup-job-verbose? restic-backup-job-extra-flags + lower-restic-backup-job + restic-backup-configuration restic-backup-configuration? - restic-backup-configuration-fields restic-backup-configuration-jobs restic-backup-job-program - restic-backup-job->mcron-job + restic-backup-job->shepherd-service restic-guix restic-guix-wrapper-package restic-backup-service-profile + restic-program + restic-job-log-file + restic-backup-job-command + restic-backup-job-modules restic-backup-service-type)) (define (gexp-or-string? value) @@ -75,6 +81,7 @@ (define list-of-symbols? (define-maybe/no-serialization string) (define-maybe/no-serialization number) +(define-maybe/no-serialization symbol) (define-configuration/no-serialization restic-backup-job (restic @@ -90,7 +97,8 @@ (define-configuration/no-serialization restic-backup-job (maybe-string) "The file system path to the log file for this job. By default the file will have be @file{/var/log/restic-backup/@var{job-name}.log}, where @var{job-name} is the -name defined in the @code{name} field.") +name defined in the @code{name} field. For Guix Home services it defaults to +@file{$XDG_STATE_HOME/shepherd/restic-backup/@var{job-name}.log}.") (max-duration (maybe-number) "The maximum duration in seconds that a job may last. Past @@ -117,8 +125,10 @@ (define-configuration/no-serialization restic-backup-job evaluate to @code{calendar-event} records or to strings. Strings must contain Vixie cron date lines.") (requirement - (list-of-symbols '()) - "The list of Shepherd services that this backup job depends upon.") + (maybe-list-of-symbols) + "The list of Shepherd services that this backup job depends upon. When unset it +defaults to @code{'()}, for Guix Home. Otherwise to +@code{'(user-processes file-systems)}.") (files (list-of-lowerables '()) "The list of files or directories to be backed up. It must be a list of @@ -131,15 +141,20 @@ (define-configuration/no-serialization restic-backup-job "A list of values that are lowered to strings. These will be passed as command-line arguments to the current job @command{restic backup} invocation.")) -(define list-of-restic-backup-jobs? - (list-of restic-backup-job?)) +;; (for-home (restic-backup-configuration ...)) is not able to replace for-home? with #t, +;; pk prints #f. Once for-home will be able to work with (gnu services configuration) the +;; record can be migrated back to define-configuration. +(define-record-type* <restic-backup-configuration> + restic-backup-configuration + make-restic-backup-configuration + restic-backup-configuration? + this-restic-backup-configuration -(define-configuration/no-serialization restic-backup-configuration - (jobs - (list-of-restic-backup-jobs '()) - "The list of backup jobs for the current system.")) + (jobs restic-backup-configuration-jobs (default '())) ; list of restic-backup-job + (home-service? restic-backup-configuration-home-service? + (default for-home?) (innate))) -(define (restic-backup-job-program config) +(define (lower-restic-backup-job config) (let ((restic (file-append (restic-backup-job-restic config) "/bin/restic")) (repository @@ -150,22 +165,42 @@ (define (restic-backup-job-program config) (restic-backup-job-files config)) (extra-flags (restic-backup-job-extra-flags config)) - (verbose + (verbose? (if (restic-backup-job-verbose? config) '("--verbose") '()))) - (program-file - "restic-backup-job.scm" - #~(begin - (use-modules (ice-9 popen) - (ice-9 rdelim)) - (setenv "RESTIC_PASSWORD" - (with-input-from-file #$password-file read-line)) - - (execlp #$restic #$restic #$@verbose - "-r" #$repository - #$@extra-flags - "backup" #$@files))))) + #~(list (list #$@files) #$restic #$repository #$password-file + (list #$@verbose?) (list #$@extra-flags)))) + +(define restic-program + #~(lambda (action action-args job-restic repository password-file verbose? extra-flags) + (use-modules (ice-9 format)) + ;; This can be extended later, i.e. to have a + ;; centrally defined restic package. + ;; See https://issues.guix.gnu.org/71639 + (define restic job-restic) + + (define command + `(,restic ,@verbose? + "-r" ,repository + ,@extra-flags + ,action ,@action-args)) + + (setenv "RESTIC_PASSWORD_FILE" password-file) + + (when (> (length verbose?) 0) + (format #t "Running~{ ~a~}~%" command)) + + (apply execlp `(,restic ,@command)))) + +(define (restic-backup-job-program config) + (program-file + "restic-backup" + #~(let ((restic-exec + #$restic-program) + (job #$(lower-restic-backup-job config))) + + (apply restic-exec `("backup" ,@job))))) (define (restic-guix jobs) (program-file @@ -207,55 +242,92 @@ (define (restic-guix jobs) (main (command-line))))) -(define (restic-job-log-file job) +(define* (restic-job-log-file job #:key (home-service? #f)) (let ((name (restic-backup-job-name job)) (log-file (restic-backup-job-log-file job))) (if (maybe-value-set? log-file) log-file - (string-append "/var/log/restic-backup/" name ".log")))) + (if home-service? + #~(begin + (use-modules (shepherd support)) + (string-append %user-log-dir "/restic-backup/" #$name ".log")) + (string-append "/var/log/restic-backup/" name ".log"))))) + +(define* (restic-backup-job-command name files #:key (home-service? #f)) + (if home-service? + #~(list + "restic-guix" "backup" #$name) + ;; We go through bash, instead of executing + ;; restic-guix directly, because the login shell + ;; gives us the correct user environment that some + ;; backends require, such as rclone. + #~(list + (string-append #$bash-minimal "/bin/bash") + "-l" "-c" + (string-append "restic-guix backup " #$name)))) -(define (restic-backup-job->shepherd-service config) +(define (restic-backup-job-modules) + `((shepherd service timer))) + +(define* (restic-job-requirement config #:key (home-service? #f)) + (define maybe-requirement (restic-backup-job-requirement config)) + (if (maybe-value-set? maybe-requirement) + maybe-requirement + (if home-service? + '() + '(user-processes file-systems)))) + +(define* (restic-backup-job-modules #:key (home-service? #f)) + `((shepherd service timer) + ,@(if home-service? + ;;for %user-log-dir + '((shepherd support)) + '()))) + +(define* (restic-backup-job->shepherd-service config #:key (home-service? #f)) (let ((schedule (restic-backup-job-schedule config)) (name (restic-backup-job-name config)) + (files (restic-backup-job-files config)) (user (restic-backup-job-user config)) (group (restic-backup-job-group config)) (max-duration (restic-backup-job-max-duration config)) (wait-for-termination? (restic-backup-job-wait-for-termination? config)) - (log-file (restic-job-log-file config)) - (requirement (restic-backup-job-requirement config))) + (log-file (restic-job-log-file + config #:home-service? home-service?)) + (requirement + (restic-job-requirement config #:home-service? home-service?))) (shepherd-service (provision `(,(string->symbol name))) - (requirement - `(user-processes file-systems ,@requirement)) + (requirement requirement) (documentation - "Run @code{restic} backed backups on a regular basis.") - (modules '((shepherd service timer))) + "Run restic backed backups on a regular basis.") + (modules (restic-backup-job-modules + #:home-service? home-service?)) (start #~(make-timer-constructor (if (string? #$schedule) (cron-string->calendar-event #$schedule) #$schedule) (command - (list - ;; We go through bash, instead of executing - ;; restic-guix directly, because the login shell - ;; gives us the correct user environment that some - ;; backends require, such as rclone. - (string-append #+bash-minimal "/bin/bash") - "-l" "-c" - (string-append "restic-guix backup " #$name)) - #:user #$user - #:group #$group - #:environment-variables - (list - (string-append - "HOME=" (passwd:dir (getpwnam #$user))))) + #$(restic-backup-job-command + name files #:home-service? home-service?) + #$@(if home-service? '() (list #:user user)) + #$@(if home-service? '() (list #:group group)) + #$@(if home-service? '() + (list + #:environment-variables + #~(list + (string-append + "HOME=" (passwd:dir (getpwnam #$user))))))) #:log-file #$log-file #:wait-for-termination? #$wait-for-termination? #:max-duration #$(and (maybe-value-set? max-duration) max-duration))) (stop #~(make-timer-destructor)) - (actions (list shepherd-trigger-action))))) + (actions (list (shepherd-action + (inherit shepherd-trigger-action) + (documentation "Manually trigger a backup, +without waiting for the scheduled time."))))))) (define (restic-guix-wrapper-package jobs) (package @@ -283,26 +355,19 @@ (define restic-backup-service-profile (restic-guix-wrapper-package jobs)) '()))) -(define (restic-backup-activation config) - #~(for-each - (lambda (log-file) - (mkdir-p (dirname log-file))) - (list #$@(map restic-job-log-file - (restic-backup-configuration-jobs config))))) - (define restic-backup-service-type (service-type (name 'restic-backup) (extensions (list - (service-extension activation-service-type - restic-backup-activation) (service-extension profile-service-type restic-backup-service-profile) (service-extension shepherd-root-service-type - (lambda (config) - (map restic-backup-job->shepherd-service - (restic-backup-configuration-jobs - config)))))) + (match-record-lambda <restic-backup-configuration> + (jobs home-service?) + (map (lambda (job) + (restic-backup-job->shepherd-service + job #:home-service? home-service?)) + jobs))))) (compose concatenate) (extend (lambda (config jobs) base-commit: ec95c71c01144fcae1a3d079e0d0aec6087b9d2a -- 2.49.0
andrew@HIDDEN, gabriel@HIDDEN, hako@HIDDEN, janneke@HIDDEN, ludo@HIDDEN, maxim.cournoyer@HIDDEN, tanguy@HIDDEN, guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 7 May 2025 00:28:08 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Tue May 06 20:28:08 2025 Received: from localhost ([127.0.0.1]:35983 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1uCSds-0000wT-8n for submit <at> debbugs.gnu.org; Tue, 06 May 2025 20:28:08 -0400 Received: from confino.investici.org ([2a11:7980:1::2:0]:42823) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1uCSdo-0000vq-LS for 76169 <at> debbugs.gnu.org; Tue, 06 May 2025 20:28:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1746577681; bh=Li1QUp4BLv118HRKxzsAHYzDefzTh1rPFg/GjNNERRw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=GwBwPaLBOqBe33+d1RcQOeJhzDnbrQ9EBIjPhfUbh5owabkZ0m6DwYTGe/HQdQQXz AGkAOi/ZTqImJxEywjHbcXyRSOUc5TyasxdVb6j1zDKlYOKkOuVV6ubO/w/+3Lel6n DOIV9juYMgO8SjK8kk9A9CjdHbzXTLyHNCCtQ9B8= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4ZsbhK3FhLz11JR; Wed, 7 May 2025 00:28:01 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4ZsbhK0V3pz11JN; Wed, 7 May 2025 00:28:01 +0000 (UTC) Message-ID: <aed14445-c307-400f-9034-35b974d8cfe1@HIDDEN> Date: Wed, 7 May 2025 02:28:00 +0200 MIME-Version: 1.0 User-Agent: Icedove Daily Subject: Re: [bug#76169] [PATCH v7] home: Add home-restic-backup service. To: =?UTF-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN> References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <db3dd3414e09ae715bdeb84efe3beef39939c5c6.1745886178.git.goodoldpaul@HIDDEN> <87plgmvzj2.fsf@HIDDEN> Content-Language: en-US From: paul <goodoldpaul@HIDDEN> In-Reply-To: <87plgmvzj2.fsf@HIDDEN> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 76169 Cc: Tanguy Le Carrour <tanguy@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Andrew Tropin <andrew@HIDDEN>, Hilton Chain <hako@HIDDEN>, 76169 <at> debbugs.gnu.org, Janneke Nieuwenhuizen <janneke@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) Hi Ludo’ , Next revision (v8) should apply to master (currently is ec95c71c01144fcae1a3d079e0d0aec6087b9d2a). cheers, giacomo
guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 6 May 2025 10:30:53 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Tue May 06 06:30:53 2025 Received: from localhost ([127.0.0.1]:52840 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1uCFZc-0001hf-S1 for submit <at> debbugs.gnu.org; Tue, 06 May 2025 06:30:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54376) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <ludo@HIDDEN>) id 1uCFZY-0001gX-0I for 76169 <at> debbugs.gnu.org; Tue, 06 May 2025 06:30:48 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <ludo@HIDDEN>) id 1uCFZQ-0003TM-Nt; Tue, 06 May 2025 06:30:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=SPB1ZAoGsW/2BzOnAtgMZYsRB3PKu9XN6YXEaVIy3W4=; b=iiZiD99YUz8ErrlYf9mL 5Q7viEdP7tC34HiUuufP31STXpeULxGSulIOcGc+Cbjwb8cfNisAK1/IsQmP+2fcHUsKUlgtaAHlS wCt138Jzcv1Wbvt2o+TRD54FoIP0m1+1aRSCth66epjoc3XBYPIab6aIN0b7OlNKXIyBwM13XmDpW n3W8muFaNMNcy2h06e0izPYEzwaissxL/zNOM0Mi5KAEMSikF4UgDtZaQfCuAHtj2BzNebGUDPQQH DQl6jCSYIfmcx48GAHv1KuNFRlT20vI5iJTE6iPeMxTICCCxhaeZTt3iqnFJdCfHpqDwHrPwtTmck 6qEBbkTbBNnFUA==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN> To: Giacomo Leidi <goodoldpaul@HIDDEN> Subject: Re: [bug#76169] [PATCH v7] home: Add home-restic-backup service. In-Reply-To: <db3dd3414e09ae715bdeb84efe3beef39939c5c6.1745886178.git.goodoldpaul@HIDDEN> (Giacomo Leidi's message of "Tue, 29 Apr 2025 02:22:58 +0200") References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <db3dd3414e09ae715bdeb84efe3beef39939c5c6.1745886178.git.goodoldpaul@HIDDEN> User-Agent: mu4e 1.12.9; emacs 29.4 X-URL: https://people.bordeaux.inria.fr/lcourtes/ X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu X-Revolutionary-Date: Septidi 17 =?utf-8?Q?Flor=C3=A9al?= an 233 de la =?utf-8?Q?R=C3=A9volution=2C?= jour de la Pimprenelle Date: Tue, 06 May 2025 11:50:25 +0200 Message-ID: <87plgmvzj2.fsf@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 76169 Cc: Tanguy Le Carrour <tanguy@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Andrew Tropin <andrew@HIDDEN>, Hilton Chain <hako@HIDDEN>, 76169 <at> debbugs.gnu.org, Janneke Nieuwenhuizen <janneke@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -3.3 (---) Hi Giacomo, Giacomo Leidi <goodoldpaul@HIDDEN> writes: > * gnu/services/backup.scm (restic-backup-configuration): Reimplement > with (guix records); > (restic-backup-job-{logfile,command,requirement,modules}): Add new > procedures and add support for Guix Home environments; > (restic-backup-job->shepherd-service): Add support for Guix Home > environments; > (restic-backup-service-activation): Drop procedure as now the Shepherd > takes care of creating directories for timers logs. > * gnu/home/services/backup.scm: New file. > * gnu/local.mk: Add this. > * doc/guix.texi: Document this. > > Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be This patch doesn=E2=80=99t want to be applied: it=E2=80=99s not applicable = on top of eab097c682ed31efd8668f46fce8de8f73b92849. I don=E2=80=99t know, what should we do? :-) Thanks, Ludo=E2=80=99.
guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 29 Apr 2025 00:23:18 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 28 20:23:18 2025 Received: from localhost ([127.0.0.1]:40041 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1u9Ykn-0004Lg-3H for submit <at> debbugs.gnu.org; Mon, 28 Apr 2025 20:23:18 -0400 Received: from confino.investici.org ([93.190.126.19]:39291) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1u9Ykg-0004KX-1i for 76169 <at> debbugs.gnu.org; Mon, 28 Apr 2025 20:23:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1745886189; bh=vR+MOzxrlMpQJ973YQlt8Pm6Jssvs2FnQXnDrWZzsDI=; h=From:To:Cc:Subject:Date:From; b=YnD8vvE9zyxpL1mC5zp/08fgGHB1r0TipBOLzQCNs1MpIvlbrleN7Zd7V+jRvnK7+ MgYoL0bNIAuiPg0DVmiQ1Gt8HjipKuNN2ikuMBWf6Z56MdsYSHXe8ZNkGcW5I3+vkC VIB7Dku98DK13YzCwiuWFO1CjIjTMiwZWwBWgSXw= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4ZmgyP0Bqkz114L; Tue, 29 Apr 2025 00:23:09 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4ZmgyN68Qxz114C; Tue, 29 Apr 2025 00:23:08 +0000 (UTC) From: Giacomo Leidi <goodoldpaul@HIDDEN> To: 76169 <at> debbugs.gnu.org Subject: [PATCH v7] home: Add home-restic-backup service. Date: Tue, 29 Apr 2025 02:22:58 +0200 Message-ID: <db3dd3414e09ae715bdeb84efe3beef39939c5c6.1745886178.git.goodoldpaul@HIDDEN> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 X-Debbugs-Cc: Andrew Tropin <andrew@HIDDEN>, Hilton Chain <hako@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 76169 Cc: Giacomo Leidi <goodoldpaul@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.7 (-) * gnu/services/backup.scm (restic-backup-configuration): Reimplement with (guix records); (restic-backup-job-{logfile,command,requirement,modules}): Add new procedures and add support for Guix Home environments; (restic-backup-job->shepherd-service): Add support for Guix Home environments; (restic-backup-service-activation): Drop procedure as now the Shepherd takes care of creating directories for timers logs. * gnu/home/services/backup.scm: New file. * gnu/local.mk: Add this. * doc/guix.texi: Document this. Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be --- doc/guix.texi | 73 ++++++++++++++++++++++++++ gnu/home/services/backup.scm | 38 ++++++++++++++ gnu/local.mk | 1 + gnu/services/backup.scm | 99 ++++++++++++++++++++++-------------- 4 files changed, 173 insertions(+), 38 deletions(-) create mode 100644 gnu/home/services/backup.scm diff --git a/doc/guix.texi b/doc/guix.texi index 7b418a40892..84e2c9f0970 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -463,6 +463,7 @@ Top * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -48677,6 +48678,7 @@ Home Services * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -50267,6 +50269,77 @@ Guix Home Services @end lisp @end defvar +@node Backup Home Services +@subsection Backup Services + +The @code{(gnu home services backup)} module offers services for backing up +file system trees. For now, it provides the @code{home-restic-backup-service-type}. + +With @code{home-restic-backup-service-type}, you can periodically back up +directories and files with @uref{https://restic.net/, Restic}, which +supports end-to-end encryption and deduplication. Consider the +following configuration: + +@lisp +(use-modules (gnu home services backup) ;for 'restic-backup-job', 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (simple-service 'backup-jobs + home-restic-backup-service-type + (list (restic-backup-job + (name "remote-ftp") + (repository "rclone:remote-ftp:backup/restic") + (password-file "/home/alice/.restic") + ;; Every day at 23. + (schedule "0 23 * * *") + (files '("/home/alice/.restic" + "/home/alice/.config/rclone" + "/home/alice/Pictures")))))))) +@end lisp + +In general it is preferrable to extend the @code{home-restic-backup-service-type}, +as shown in the example above. This is because it takes care of wrapping everything +with @code{for-home}, which enables the @code{home-restic-backup-service-type} and +@code{restic-backup-service-type} to share the same codebase. + +For a custom configuration, wrap your @code{restic-backup-configuration} in +@code{for-home}, as in this example: + +@lisp +(use-modules (gnu services) ;for 'for-home' + (gnu services backup) ;for 'restic-backup-job' and 'restic-backup-configuration' + (gnu home services backup) ;for 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (service home-restic-backup-service-type + (for-home + (restic-backup-configuration + (jobs (list @dots{})))))))) +@end lisp + +You can refer to @pxref{Miscellaneous Services, +@code{restic-backup-service-type}} for details about +@code{restic-backup-configuration} and @code{restic-backup-job}. +The only difference is that the @code{home-restic-backup-service-type} +will ignore the @code{user} and @code{group} field of +@code{restic-backup-job}. + @node Fonts Home Services @subsection Fonts Home Services diff --git a/gnu/home/services/backup.scm b/gnu/home/services/backup.scm new file mode 100644 index 00000000000..ac977f835b6 --- /dev/null +++ b/gnu/home/services/backup.scm @@ -0,0 +1,38 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2025 Giacomo Leidi <goodoldpaul@HIDDEN> +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. + +(define-module (gnu home services backup) + #:use-module (gnu services) + #:use-module (gnu services backup) + #:use-module (gnu home services) + #:use-module (gnu home services shepherd) + #:export (home-restic-backup-service-type) + #:re-export (restic-backup-configuration + restic-backup-job)) + +(define home-restic-backup-service-type + (service-type + (inherit (system->home-service-type restic-backup-service-type)) + (extend + (lambda (config jobs) + (for-home + (restic-backup-configuration + (inherit config) + (jobs (append (restic-backup-configuration-jobs config) + jobs)))))) + (default-value (for-home (restic-backup-configuration))))) diff --git a/gnu/local.mk b/gnu/local.mk index cc57222a91b..b57b9fb4fb7 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -103,6 +103,7 @@ GNU_SYSTEM_MODULES = \ %D%/home.scm \ %D%/home/services.scm \ %D%/home/services/admin.scm \ + %D%/home/services/backup.scm \ %D%/home/services/desktop.scm \ %D%/home/services/dict.scm \ %D%/home/services/dotfiles.scm \ diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm index 4fff815e168..3cc199a23bd 100644 --- a/gnu/services/backup.scm +++ b/gnu/services/backup.scm @@ -28,6 +28,7 @@ (define-module (gnu services backup) #:prefix license:) #:use-module (guix modules) #:use-module (guix packages) + #:use-module (guix records) #:use-module (srfi srfi-1) #:export (restic-backup-job restic-backup-job? @@ -51,7 +52,6 @@ (define-module (gnu services backup) restic-backup-configuration restic-backup-configuration? - restic-backup-configuration-fields restic-backup-configuration-jobs restic-program @@ -134,13 +134,18 @@ (define-configuration/no-serialization restic-backup-job "A list of values that are lowered to strings. These will be passed as command-line arguments to the current job @command{restic backup} invocation.")) -(define list-of-restic-backup-jobs? - (list-of restic-backup-job?)) +;; (for-home (restic-backup-configuration ...)) is not able to replace for-home? with #t, +;; pk prints #f. Once for-home will be able to work with (gnu services configuration) the +;; record can be migrated back to define-configuration. +(define-record-type* <restic-backup-configuration> + restic-backup-configuration + make-restic-backup-configuration + restic-backup-configuration? + this-restic-backup-configuration -(define-configuration/no-serialization restic-backup-configuration - (jobs - (list-of-restic-backup-jobs '()) - "The list of backup jobs for the current system.")) + (jobs restic-backup-configuration-jobs (default '())) ; list of restic-backup-job + (home-service? restic-backup-configuration-home-service? + (default for-home?) (innate))) (define (lower-restic-backup-job config) (let ((restic @@ -192,31 +197,41 @@ (define (restic-backup config) (apply restic-exec `("backup" ,@job))))) -(define (restic-backup-job-log-file job) +(define* (restic-backup-job-log-file job #:key (home-service? #f)) (let ((name (restic-backup-job-name job)) (log-file (restic-backup-job-log-file job))) (if (maybe-value-set? log-file) log-file - (string-append "/var/log/restic-backup/" name ".log")))) + (if home-service? + #~(string-append %user-log-dir "/restic-backup/" #$name ".log") + (string-append "/var/log/restic-backup/" name ".log"))))) -(define (restic-backup-job-command config) - ;; We go through bash, instead of executing - ;; restic-guix directly, because the login shell - ;; gives us the correct user environment that some - ;; backends require, such as rclone. - #~(list - (string-append #$bash-minimal "/bin/bash") - "-l" "-c" - (string-join (list #$(restic-backup config)) - " "))) +(define* (restic-backup-job-command config #:key (home-service? #f)) + (if home-service? + ;; Home Shepherd sets the right environment, so no + ;; bash is needed + #~(list #$(restic-backup config)) + ;; We go through bash, instead of executing + ;; restic-guix directly, because the login shell + ;; gives us the correct user environment that some + ;; backends require, such as rclone. + #~(list + (string-append #$bash-minimal "/bin/bash") + "-l" "-c" #$(restic-backup config)))) -(define (restic-backup-job-requirement requirement) - (append '(user-processes file-systems) requirement)) +(define* (restic-backup-job-requirement requirement #:key (home-service? #f)) + (if home-service? + requirement + (append '(user-processes file-systems) requirement))) -(define (restic-backup-job-modules) - `((shepherd service timer))) +(define* (restic-backup-job-modules #:key (home-service? #f)) + `((shepherd service timer) + ,@(if home-service? + ;;for %user-log-dir + '((shepherd support)) + '()))) -(define (restic-backup-job->shepherd-service config) +(define* (restic-backup-job->shepherd-service config #:key (home-service? #f)) (let ((schedule (restic-backup-job-schedule config)) (name (restic-backup-job-name config)) (files (restic-backup-job-files config)) @@ -224,28 +239,34 @@ (define (restic-backup-job->shepherd-service config) (group (restic-backup-job-group config)) (max-duration (restic-backup-job-max-duration config)) (wait-for-termination? (restic-backup-job-wait-for-termination? config)) - (log-file (restic-backup-job-log-file config)) + (log-file (restic-backup-job-log-file + config #:home-service? home-service?)) (requirement (restic-backup-job-requirement - (restic-backup-job-requirement config)))) + (restic-backup-job-requirement config) + #:home-service? home-service?))) (shepherd-service (provision `(,(string->symbol name))) (requirement requirement) (documentation "Run restic backed backups on a regular basis.") - (modules (restic-backup-job-modules)) + (modules (restic-backup-job-modules + #:home-service? home-service?)) (start #~(make-timer-constructor (if (string? #$schedule) (cron-string->calendar-event #$schedule) #$schedule) (command - #$(restic-backup-job-command config) - #:user #$user - #:group #$group - #:environment-variables - (list - (string-append - "HOME=" (passwd:dir (getpwnam #$user))))) + #$(restic-backup-job-command + config #:home-service? home-service?) + #$@(if home-service? '() (list #:user user)) + #$@(if home-service? '() (list #:group group)) + #$@(if home-service? '() + (list + #:environment-variables + #~(list + (string-append + "HOME=" (passwd:dir (getpwnam #$user))))))) #:log-file #$log-file #:wait-for-termination? #$wait-for-termination? #:max-duration #$(and (maybe-value-set? max-duration) @@ -263,10 +284,12 @@ (define restic-backup-service-type (extensions (list (service-extension shepherd-root-service-type - (lambda (config) - (map restic-backup-job->shepherd-service - (restic-backup-configuration-jobs - config)))))) + (match-record-lambda <restic-backup-configuration> + (jobs home-service?) + (map (lambda (job) + (restic-backup-job->shepherd-service + job #:home-service? home-service?)) + jobs))))) (compose concatenate) (extend (lambda (config jobs) base-commit: 25dac960ce99c32cf53cdf010351b7355f072fa1 -- 2.49.0
andrew@HIDDEN, hako@HIDDEN, janneke@HIDDEN, ludo@HIDDEN, maxim.cournoyer@HIDDEN, tanguy@HIDDEN, guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 29 Apr 2025 00:21:54 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Mon Apr 28 20:21:54 2025 Received: from localhost ([127.0.0.1]:40018 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1u9YjS-0004Bv-2P for submit <at> debbugs.gnu.org; Mon, 28 Apr 2025 20:21:54 -0400 Received: from confino.investici.org ([93.190.126.19]:58927) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1u9YjK-0004AH-7R for 76169 <at> debbugs.gnu.org; Mon, 28 Apr 2025 20:21:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1745886104; bh=THgbAkBz1f40GV15NYCZpL8koEqbca15Vfn6JhnVUoo=; h=Date:Subject:From:To:Cc:References:In-Reply-To:From; b=uQh115hAquIU+5mOFEdYeJ84/dSx8+WEdDeQ8CvguKrNisWCShwFh7hb67WQzUWw+ sRJKFIFeHBCycBeDy6PMuwU8cC3SIA5HV2vpotfIOhPemMWblitGcdrHE0XTyiy0kv GlXVtL31KGj200Nmc61q2xoJofliVyT6Mc6q2a/U= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4Zmgwm3jFcz114L; Tue, 29 Apr 2025 00:21:44 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4Zmgwm1TdMz114C; Tue, 29 Apr 2025 00:21:39 +0000 (UTC) Message-ID: <64f812a1-3fe4-4602-be30-69a29939549e@HIDDEN> Date: Tue, 29 Apr 2025 02:21:39 +0200 MIME-Version: 1.0 User-Agent: Icedove Daily Subject: Re: bug#76169: home: Add home-restic-backup service. From: paul <goodoldpaul@HIDDEN> To: 76169 <at> debbugs.gnu.org References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <5f470034ff56eb23a7dc2e0a32f2a238e82a0f18.1741217283.git.goodoldpaul@HIDDEN> <874j03tqxf.fsf_-_@HIDDEN> <69e1df16-165b-47b4-a8be-6f13a478b9ad@HIDDEN> Content-Language: en-US In-Reply-To: <69e1df16-165b-47b4-a8be-6f13a478b9ad@HIDDEN> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 76169 Cc: =?UTF-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Andrew Tropin <andrew@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.7 (-) Hi I'm sending a new revision (v7) base on revision 9 of 72803, which drops the restic-guix packge. Thank you for your help, cheers, giacomo
guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 8 Mar 2025 17:41:11 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 08 12:41:11 2025 Received: from localhost ([127.0.0.1]:56686 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tqyAg-0003GL-9U for submit <at> debbugs.gnu.org; Sat, 08 Mar 2025 12:41:11 -0500 Received: from confino.investici.org ([2a11:7980:1::2:0]:41747) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1tqyAc-0003FV-6W for 76169 <at> debbugs.gnu.org; Sat, 08 Mar 2025 12:41:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1741455663; bh=uPUnrPFd/Tp9XiztQgzL10nWnkmnD9st9ljHgqpV/20=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SwfU7hV9lqFkmZlwduA/ILd/+rTw5dHHx5uDO6ok0Pauig/rvbvakUyv0O9/5aIma dNAJLVZCI4kpG4xTVPSajJYvWviTZps72ypGPCrwTa+G7tM/AmxgmV1JgBnnCi6pfD 3rKFcyQ5GHkKgH7pVGi7rfdE5XlhmuFFsS/QPFrc= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4Z99Rz2sjtz11Q4; Sat, 8 Mar 2025 17:41:03 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4Z99Rz1kwtz10xY; Sat, 8 Mar 2025 17:41:03 +0000 (UTC) From: Giacomo Leidi <goodoldpaul@HIDDEN> To: 76169 <at> debbugs.gnu.org Subject: [PATCH v6 2/2] home: Add home-restic-backup service. Date: Sat, 8 Mar 2025 18:40:24 +0100 Message-ID: <2dd98bb474bf22628ba83cc316acaa1c0f0fbdf3.1741455624.git.goodoldpaul@HIDDEN> X-Mailer: git-send-email 2.48.1 In-Reply-To: <3dbfa227b49e6f0cd7634d5d42fac38a549c0062.1741455624.git.goodoldpaul@HIDDEN> References: <3dbfa227b49e6f0cd7634d5d42fac38a549c0062.1741455624.git.goodoldpaul@HIDDEN> MIME-Version: 1.0 X-Debbugs-Cc: Andrew Tropin <andrew@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 76169 Cc: Giacomo Leidi <goodoldpaul@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) * gnu/services/backup.scm (restic-backup-configuration): Reimplement with (guix records); (restic-backup-job-{logfile,command,requirement,modules}): Add new procedures and add support for Guix Home environments; (restic-backup-job->shepherd-service): Add support for Guix Home environments; (restic-backup-service-activation): Drop procedure as now the Shepherd takes care of creating directories for timers logs. * gnu/home/services/backup.scm: New file. * gnu/local.mk: Add this. * doc/guix.texi: Document this. Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be --- doc/guix.texi | 76 ++++++++++++++++++++++ gnu/home/services/backup.scm | 38 +++++++++++ gnu/local.mk | 1 + gnu/services/backup.scm | 119 +++++++++++++++++++++-------------- 4 files changed, 186 insertions(+), 48 deletions(-) create mode 100644 gnu/home/services/backup.scm diff --git a/doc/guix.texi b/doc/guix.texi index 321c312fa83..a56bfdddea7 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -463,6 +463,7 @@ Top * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -47766,6 +47767,7 @@ Home Services * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -49312,6 +49314,80 @@ Guix Home Services @end lisp @end defvar +@node Backup Home Services +@subsection Backup Services + +The @code{(gnu home services backup)} module offers services for backing up +file system trees. For now, it provides the @code{home-restic-backup-service-type}. + +With @code{home-restic-backup-service-type}, you can periodically back up +directories and files with @uref{https://restic.net/, Restic}, which +supports end-to-end encryption and deduplication. Consider the +following configuration: + +@lisp +(use-modules (gnu home services backup) ;for 'restic-backup-job', 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (simple-service 'backup-jobs + home-restic-backup-service-type + (list (restic-backup-job + (name "remote-ftp") + (repository "rclone:remote-ftp:backup/restic") + (password-file "/home/alice/.restic") + ;; Every day at 23. + (schedule "0 23 * * *") + (files '("/home/alice/.restic" + "/home/alice/.config/rclone" + "/home/alice/Pictures")))))))) +@end lisp + +In general it is preferrable to extend the @code{home-restic-backup-service-type}, +as shown in the example above. This is because it takes care of wrapping everything +with @code{for-home}, which enables the @code{home-restic-backup-service-type} and +@code{restic-backup-service-type} to share the same codebase. + +For a custom configuration, wrap your @code{restic-backup-configuration} in +@code{for-home}, as in this example: + +@lisp +(use-modules (gnu services) ;for 'for-home' + (gnu services backup) ;for 'restic-backup-job' and 'restic-backup-configuration' + (gnu home services backup) ;for 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (service home-restic-backup-service-type + (for-home + (restic-backup-configuration + (jobs (list @dots{})))))))) +@end lisp + +You can refer to @pxref{Miscellaneous Services, +@code{restic-backup-service-type}} for details about +@code{restic-backup-configuration} and @code{restic-backup-job}. +The only difference is that the @code{home-restic-backup-service-type} +will ignore the @code{user} and @code{group} field of +@code{restic-backup-job}. + +It will also install the @command{restic-guix} package to the user's Home +profile. + @node Fonts Home Services @subsection Fonts Home Services diff --git a/gnu/home/services/backup.scm b/gnu/home/services/backup.scm new file mode 100644 index 00000000000..ac977f835b6 --- /dev/null +++ b/gnu/home/services/backup.scm @@ -0,0 +1,38 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2025 Giacomo Leidi <goodoldpaul@HIDDEN> +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. + +(define-module (gnu home services backup) + #:use-module (gnu services) + #:use-module (gnu services backup) + #:use-module (gnu home services) + #:use-module (gnu home services shepherd) + #:export (home-restic-backup-service-type) + #:re-export (restic-backup-configuration + restic-backup-job)) + +(define home-restic-backup-service-type + (service-type + (inherit (system->home-service-type restic-backup-service-type)) + (extend + (lambda (config jobs) + (for-home + (restic-backup-configuration + (inherit config) + (jobs (append (restic-backup-configuration-jobs config) + jobs)))))) + (default-value (for-home (restic-backup-configuration))))) diff --git a/gnu/local.mk b/gnu/local.mk index be1e32571cf..5a0be62b97f 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -103,6 +103,7 @@ GNU_SYSTEM_MODULES = \ %D%/home.scm \ %D%/home/services.scm \ %D%/home/services/admin.scm \ + %D%/home/services/backup.scm \ %D%/home/services/desktop.scm \ %D%/home/services/dict.scm \ %D%/home/services/dotfiles.scm \ diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm index dc095593432..3c092629774 100644 --- a/gnu/services/backup.scm +++ b/gnu/services/backup.scm @@ -28,6 +28,7 @@ (define-module (gnu services backup) #:prefix license:) #:use-module (guix modules) #:use-module (guix packages) + #:use-module (guix records) #:use-module (srfi srfi-1) #:export (restic-backup-job restic-backup-job? @@ -49,7 +50,6 @@ (define-module (gnu services backup) restic-backup-configuration restic-backup-configuration? - restic-backup-configuration-fields restic-backup-configuration-jobs restic-program @@ -57,7 +57,6 @@ (define-module (gnu services backup) restic-guix restic-guix-wrapper-package restic-backup-service-profile - restic-backup-service-activation restic-backup-service-type)) (define (gexp-or-string? value) @@ -132,13 +131,18 @@ (define-configuration/no-serialization restic-backup-job "A list of values that are lowered to strings. These will be passed as command-line arguments to the current @command{restic} invocation.")) -(define list-of-restic-backup-jobs? - (list-of restic-backup-job?)) +;; (for-home (restic-backup-configuration ...)) is not able to replace for-home? with #t, +;; pk prints #f. Once for-home will be able to work with (gnu services configuration) the +;; record can be migrated back to define-configuration. +(define-record-type* <restic-backup-configuration> + restic-backup-configuration + make-restic-backup-configuration + restic-backup-configuration? + this-restic-backup-configuration -(define-configuration/no-serialization restic-backup-configuration - (jobs - (list-of-restic-backup-jobs '()) - "The list of backup jobs for the current system.")) + (jobs restic-backup-configuration-jobs (default '())) ; list of restic-backup-job + (home-service? restic-backup-configuration-home-service? + (default for-home?) (innate))) (define %restic-guix-supported-actions '("backup" "list" "ls" "mount" "prune" "restore" "snapshots" "unlock")) @@ -244,53 +248,79 @@ (define* (restic-guix config #:key (supported-actions (main (command-line))))) -(define (restic-job-log-file job) +(define* (restic-backup-job-log-file job #:key (home-service? #f)) (let ((name (restic-backup-job-name job)) (log-file (restic-backup-job-log-file job))) (if (maybe-value-set? log-file) log-file - (string-append "/var/log/restic-backup/" name ".log")))) + (if home-service? + #~(begin + (use-modules (shepherd support)) + (string-append %user-log-dir "/restic-backup/" #$name ".log")) + (string-append "/var/log/restic-backup/" name ".log"))))) -(define (restic-backup-job->shepherd-service config) +(define* (restic-backup-job-command name files #:key (home-service? #f)) + (if home-service? + #~(list + "restic-guix" "backup" #$name #$@files) + #~(list + (string-append #+bash-minimal "/bin/bash") + "-l" "-c" + (string-append + "restic-guix backup " #$name " " + #$(string-join + (map (lambda (f) (string-append "'" f "'")) + files) + " "))))) + +(define* (restic-backup-job-requirement requirement #:key (home-service? #f)) + (if home-service? + requirement + (append '(user-processes file-systems) requirement))) + +(define* (restic-backup-job-modules #:key (home-service? #f)) + `((shepherd service timer) + ,@(if home-service? + ;;for %user-log-dir + '((shepherd support)) + '()))) + +(define* (restic-backup-job->shepherd-service config #:key (home-service? #f)) (let ((schedule (restic-backup-job-schedule config)) (name (restic-backup-job-name config)) - (files (string-join - (map (lambda (f) (string-append "'" f "'")) - (restic-backup-job-files config)) - " ")) + (files (restic-backup-job-files config)) (user (restic-backup-job-user config)) (group (restic-backup-job-group config)) (max-duration (restic-backup-job-max-duration config)) (wait-for-termination? (restic-backup-job-wait-for-termination? config)) - (log-file (restic-job-log-file config)) - (requirement (restic-backup-job-requirement config))) + (log-file (restic-backup-job-log-file + config #:home-service? home-service?)) + (requirement + (restic-backup-job-requirement + (restic-backup-job-requirement config) + #:home-service? home-service?))) (shepherd-service (provision `(,(string->symbol name))) - (requirement - `(user-processes file-systems ,@requirement)) + (requirement requirement) (documentation "Run @code{restic} backed backups on a regular basis.") - (modules '((shepherd service timer))) + (modules (restic-backup-job-modules + #:home-service? home-service?)) (start #~(make-timer-constructor (if (string? #$schedule) (cron-string->calendar-event #$schedule) #$schedule) (command - (list - ;; We go through bash, instead of executing - ;; restic-guix directly, because the login shell - ;; gives us the correct user environment that some - ;; backends require, such as rclone. - (string-append #+bash-minimal "/bin/bash") - "-l" "-c" - (string-append - "restic-guix backup " #$name " " #$files)) - #:user #$user - #:group #$group - #:environment-variables - (list - (string-append - "HOME=" (passwd:dir (getpwnam #$user))))) + #$(restic-backup-job-command + name files #:home-service? home-service?) + #$@(if home-service? '() (list #:user user)) + #$@(if home-service? '() (list #:group group)) + #$@(if home-service? '() + (list + #:environment-variables + #~(list + (string-append + "HOME=" (passwd:dir (getpwnam #$user))))))) #:log-file #$log-file #:wait-for-termination? #$wait-for-termination? #:max-duration #$(and (maybe-value-set? max-duration) @@ -329,26 +359,19 @@ (define restic-backup-service-profile (restic-guix-wrapper-package config)) '()))) -(define (restic-backup-service-activation config) - #~(for-each - (lambda (log-file) - (mkdir-p (dirname log-file))) - (list #$@(map restic-job-log-file - (restic-backup-configuration-jobs config))))) - (define restic-backup-service-type (service-type (name 'restic-backup) (extensions (list - (service-extension activation-service-type - restic-backup-service-activation) (service-extension profile-service-type restic-backup-service-profile) (service-extension shepherd-root-service-type - (lambda (config) - (map restic-backup-job->shepherd-service - (restic-backup-configuration-jobs - config)))))) + (match-record-lambda <restic-backup-configuration> + (jobs home-service?) + (map (lambda (job) + (restic-backup-job->shepherd-service + job #:home-service? home-service?)) + jobs))))) (compose concatenate) (extend (lambda (config jobs) -- 2.48.1
andrew@HIDDEN, janneke@HIDDEN, ludo@HIDDEN, maxim.cournoyer@HIDDEN, tanguy@HIDDEN, guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 8 Mar 2025 17:41:07 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 08 12:41:07 2025 Received: from localhost ([127.0.0.1]:56683 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tqyAc-0003G0-BH for submit <at> debbugs.gnu.org; Sat, 08 Mar 2025 12:41:07 -0500 Received: from confino.investici.org ([93.190.126.19]:42163) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1tqyAZ-0003FO-T5 for 76169 <at> debbugs.gnu.org; Sat, 08 Mar 2025 12:41:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1741455663; bh=ltLfXlcnMdEJ+3XpsJANQe9oZu7kEJ/0yjn/ESxMOxU=; h=From:To:Cc:Subject:Date:From; b=pgPDyJQehl5F+xFh982ItyRpcwflR8OTCf61jg7ihUpkv7ma03FiHpmveZY1Lmcvz d4azeJa60WoNL+XSccVo4GaCDQ+9NK4olHHEduHvqldBttWq2e4QeRcqqxQ1M5xjtS em/BoK1xFgy8JZs0+ynVMvhXIiZzB/5ZMhN/ZAJQ= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4Z99Rz00rZz11Pv; Sat, 8 Mar 2025 17:41:02 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4Z99Ry5xrnz10xY; Sat, 8 Mar 2025 17:41:02 +0000 (UTC) From: Giacomo Leidi <goodoldpaul@HIDDEN> To: 76169 <at> debbugs.gnu.org Subject: [PATCH v6 1/2] services: restic-backup: Add more restic commands to the restic-guix package. Date: Sat, 8 Mar 2025 18:40:23 +0100 Message-ID: <3dbfa227b49e6f0cd7634d5d42fac38a549c0062.1741455624.git.goodoldpaul@HIDDEN> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-Debbugs-Cc: Ludovic Courtès <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN> Content-Transfer-Encoding: 8bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 76169 Cc: Giacomo Leidi <goodoldpaul@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.7 (-) This patch refactors the way restic commands can be added to the restic-guix package with a more general approach. This way new subcommands for restic-guix can be added more easily. * gnu/services/backup.scm (restic-backup-job-program): Generalize to restic-program; (restic-guix): allow for multiple actions. * doc/guix.texi: Document it. Change-Id: Ib2b5d74bebc51e35f1ae6e1aa32cedee0da59697 --- doc/guix.texi | 20 +++++- gnu/services/backup.scm | 138 ++++++++++++++++++++++++++-------------- 2 files changed, 108 insertions(+), 50 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 6529865c090..321c312fa83 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -43798,6 +43798,23 @@ Miscellaneous Services sudo herd trigger remote-ftp @end example +The @code{restic-backup-service-type} installs as well @code{restic-guix} +to the system profile, a @code{restic} utility wrapper that allows for easier +interaction with the Guix configured backup jobs. For example the following +could be used to list all the shapshots available on a given job's repository: + +@example +restic-guix snapshots remote-ftp +@end example + +All arguments passed after the job name will be passed to the underlying +@code{restic} command, together with the @code{extra-flags} field from the +@code{restic-backup-job} record: + +@example +restic-guix restore remote-ftp -t `pwd`/restored -i .config/guix/channels.scm latest +@end example + @c %start of fragment @deftp {Data Type} restic-backup-configuration @@ -43871,8 +43888,7 @@ Miscellaneous Services @item @code{extra-flags} (default: @code{'()}) (type: list-of-lowerables) A list of values that are lowered to strings. These will be passed as -command-line arguments to the current job @command{restic backup} -invocation. +command-line arguments to the current @command{restic} invocation. @end table diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm index 4d8cf167f04..dc095593432 100644 --- a/gnu/services/backup.scm +++ b/gnu/services/backup.scm @@ -52,11 +52,12 @@ (define-module (gnu services backup) restic-backup-configuration-fields restic-backup-configuration-jobs - restic-backup-job-program - restic-backup-job->mcron-job + restic-program + restic-backup-job->shepherd-service restic-guix restic-guix-wrapper-package restic-backup-service-profile + restic-backup-service-activation restic-backup-service-type)) (define (gexp-or-string? value) @@ -129,7 +130,7 @@ (define-configuration/no-serialization restic-backup-job (extra-flags (list-of-lowerables '()) "A list of values that are lowered to strings. These will be passed as -command-line arguments to the current job @command{restic backup} invocation.")) +command-line arguments to the current @command{restic} invocation.")) (define list-of-restic-backup-jobs? (list-of restic-backup-job?)) @@ -139,71 +140,107 @@ (define-configuration/no-serialization restic-backup-configuration (list-of-restic-backup-jobs '()) "The list of backup jobs for the current system.")) -(define (restic-backup-job-program config) +(define %restic-guix-supported-actions + '("backup" "list" "ls" "mount" "prune" "restore" "snapshots" "unlock")) + +(define (restic-backup-job->kv config) (let ((restic (file-append (restic-backup-job-restic config) "/bin/restic")) + (name + (restic-backup-job-name config)) (repository (restic-backup-job-repository config)) (password-file (restic-backup-job-password-file config)) - (files - (restic-backup-job-files config)) (extra-flags (restic-backup-job-extra-flags config)) - (verbose + (verbose? (if (restic-backup-job-verbose? config) '("--verbose") '()))) - (program-file - "restic-backup-job.scm" - #~(begin - (use-modules (ice-9 popen) - (ice-9 rdelim)) - (setenv "RESTIC_PASSWORD" - (with-input-from-file #$password-file read-line)) + #~(list #$name (list #$restic #$repository #$password-file + (list #$@verbose?) (list #$@extra-flags))))) + +(define (restic-program config) + #~(lambda* (action action-args job-restic repository password-file verbose? extra-flags) + (use-modules (ice-9 format) + (ice-9 popen) + (ice-9 rdelim)) + ;; This can be extended later, i.e. to have a + ;; centrally defined restic package. + ;; See https://issues.guix.gnu.org/71639 + (define restic job-restic) + + (define command + `(,restic ,@verbose? + "-r" ,repository + ,@extra-flags + ,action ,@action-args)) + + (setenv "RESTIC_PASSWORD" + (with-input-from-file password-file read-line)) - (execlp #$restic #$restic #$@verbose - "-r" #$repository - #$@extra-flags - "backup" #$@files))))) + (when (> (length verbose?) 0) + (format #t "Running~{ ~a~}~%" command)) -(define (restic-guix jobs) + (apply execlp `(,restic ,@command)))) + +(define* (restic-guix config #:key (supported-actions + %restic-guix-supported-actions)) (program-file "restic-guix" #~(begin (use-modules (ice-9 match) (srfi srfi-1)) - (define names '#$(map restic-backup-job-name jobs)) - (define programs '#$(map restic-backup-job-program jobs)) - - (define (get-program name) - (define idx - (list-index (lambda (n) (string=? n name)) names)) - (unless idx - (error (string-append "Unknown job name " name "\n\n" - "Possible job names are: " - (string-join names " ")))) - (list-ref programs idx)) + (define jobs + (list + #$@(map restic-backup-job->kv + (restic-backup-configuration-jobs config)))) + (define names (map first jobs)) + (define (get-job key) + (first + (filter-map + (match-lambda + ((k v) + (and (string=? key k) v))) + jobs))) - (define (backup args) - (define name (third args)) - (define program (get-program name)) - (execlp program program)) + (define restic-exec + #$(restic-program config)) (define (validate-args args) - (when (not (>= (length args) 3)) - (error (string-append "Usage: " (basename (car args)) - " backup NAME")))) + (unless (>= (length args) 2) + (error (string-append "Usage: " (basename (first args)) + " ACTION [ARGS]\n\nSupported actions are: " + #$(string-join supported-actions ", ") "."))) + (unless (member (second args) '#$supported-actions) + (error (string-append "Unknown action: " (second args) ". Supported" + "actions are: " + #$(string-join supported-actions ", ") ".")))) + + (define (validate-action-args action args) + (define argc (length args)) + (when (not (>= argc 3)) + (error (string-append "Usage: " (basename (first args)) + " " action " JOB_NAME [ARGS]\n\nPossible job " + "names are: " (string-join names ", ") "."))) + (define job-name (third args)) + (unless (member job-name names) + (error (string-append "Unknown job name: " job-name ". Possible job " + "names are: " (string-join names ", ") "."))) + (let ((job (get-job job-name)) + (action-args + (if (> argc 3) + (take-right args (- argc 3)) + '()))) + (values job action-args))) (define (main args) (validate-args args) (define action (second args)) - (match action - ("backup" - (backup args)) - (_ - (error (string-append "Unknown action: " action))))) + (define-values (job action-args) (validate-action-args action args)) + (apply restic-exec `(,action ,action-args ,@job))) (main (command-line))))) @@ -217,6 +254,10 @@ (define (restic-job-log-file job) (define (restic-backup-job->shepherd-service config) (let ((schedule (restic-backup-job-schedule config)) (name (restic-backup-job-name config)) + (files (string-join + (map (lambda (f) (string-append "'" f "'")) + (restic-backup-job-files config)) + " ")) (user (restic-backup-job-user config)) (group (restic-backup-job-group config)) (max-duration (restic-backup-job-max-duration config)) @@ -242,7 +283,8 @@ (define (restic-backup-job->shepherd-service config) ;; backends require, such as rclone. (string-append #+bash-minimal "/bin/bash") "-l" "-c" - (string-append "restic-guix backup " #$name)) + (string-append + "restic-guix backup " #$name " " #$files)) #:user #$user #:group #$group #:environment-variables @@ -261,11 +303,11 @@ (define (restic-backup-job->shepherd-service config) without waiting for the scheduled time.") (procedure #~trigger-timer))))))) -(define (restic-guix-wrapper-package jobs) +(define (restic-guix-wrapper-package config) (package (name "restic-backup-service-wrapper") (version "0.0.0") - (source (restic-guix jobs)) + (source (restic-guix config)) (build-system copy-build-system) (arguments (list #:install-plan #~'(("./" "/bin")))) @@ -284,10 +326,10 @@ (define restic-backup-service-profile (define jobs (restic-backup-configuration-jobs config)) (if (> (length jobs) 0) (list - (restic-guix-wrapper-package jobs)) + (restic-guix-wrapper-package config)) '()))) -(define (restic-backup-activation config) +(define (restic-backup-service-activation config) #~(for-each (lambda (log-file) (mkdir-p (dirname log-file))) @@ -299,7 +341,7 @@ (define restic-backup-service-type (extensions (list (service-extension activation-service-type - restic-backup-activation) + restic-backup-service-activation) (service-extension profile-service-type restic-backup-service-profile) (service-extension shepherd-root-service-type base-commit: be49b0f4435cf1d9275cbbc9cac3a84fa4478ff9 -- 2.48.1
ludo@HIDDEN, maxim.cournoyer@HIDDEN, guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 8 Mar 2025 17:40:03 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 08 12:40:03 2025 Received: from localhost ([127.0.0.1]:56658 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tqy9b-000370-7E for submit <at> debbugs.gnu.org; Sat, 08 Mar 2025 12:40:03 -0500 Received: from confino.investici.org ([93.190.126.19]:25965) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1tqy9Y-00036F-Sv for 76169 <at> debbugs.gnu.org; Sat, 08 Mar 2025 12:40:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1741455599; bh=XQ55ybLk7jR25eWAuwtOXLaZvWMnQXy2TXeAxbH3gow=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=iMd29GchH75eOEu5StdYaR1gvObHABLgNaNtkan1my6Elp/heOY5L3Ymn1/RCCnEh UP09UMyt4pSTT/vNHJ/mD1kzeTnf9ItbDHoVXeWOO9ialnCUhwedkavD2RfxnVJYZ1 9vSOli8Uyw652Yl+XVp9rE9Vpv9DQ1gIipJWQsCo= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4Z99Ql1wb4z11Pv; Sat, 8 Mar 2025 17:39:59 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4Z99Qk6Vxvz10xY; Sat, 8 Mar 2025 17:39:58 +0000 (UTC) Message-ID: <69e1df16-165b-47b4-a8be-6f13a478b9ad@HIDDEN> Date: Sat, 8 Mar 2025 18:39:58 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily Subject: Re: bug#76169: home: Add home-restic-backup service. To: =?UTF-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN> References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <5f470034ff56eb23a7dc2e0a32f2a238e82a0f18.1741217283.git.goodoldpaul@HIDDEN> <874j03tqxf.fsf_-_@HIDDEN> Content-Language: en-US From: paul <goodoldpaul@HIDDEN> In-Reply-To: <874j03tqxf.fsf_-_@HIDDEN> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 76169 Cc: Tanguy Le Carrour <tanguy@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, 76169 <at> debbugs.gnu.org, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Andrew Tropin <andrew@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.7 (-) Hi Ludo’, On 3/8/25 17:42, Ludovic Courtès wrote: > Giacomo Leidi <goodoldpaul@HIDDEN> skribis: > >> * gnu/services/backup.scm (restic-backup-configuration): Reimplement >> with (guix records); >> (restic-backup-job-{logfile,command,requirement,modules}): Add new >> procedures and add support for Guix Home environments; >> (restic-backup-job->shepherd-service): Add support for Guix Home >> environments; >> (restic-backup-service-activation): Drop procedure as now the Shepherd >> takes care of creating directories for timers logs. >> * gnu/home/services/backup.scm: New file. >> * gnu/local.mk: Add this. >> * doc/guix.texi: Document this. >> >> Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be > Hi! It LGTM, but it doesn’t apply on top of > a8db2cb547f93f915726eae8ebae7646a4361094: It is because this patch depends on changes to the restic-guix command from issue #72803 revision 8, I'm sending a rebased patchset (v6) which will apply on top of current master (be49b0f4435cf1d9275cbbc9cac3a84fa4478ff9) but is additionally including changes from #72803. The dependency is due to the additional features introduced by #72803, which are required in the home service to correctly run backups. Please let me know if I can clarify further, thank you for your work! giacomo
guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 8 Mar 2025 16:42:34 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 08 11:42:34 2025 Received: from localhost ([127.0.0.1]:56345 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tqxFy-0002Sn-6N for submit <at> debbugs.gnu.org; Sat, 08 Mar 2025 11:42:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34818) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <ludo@HIDDEN>) id 1tqxFv-0002SY-12 for 76169 <at> debbugs.gnu.org; Sat, 08 Mar 2025 11:42:31 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <ludo@HIDDEN>) id 1tqxFn-000736-QQ; Sat, 08 Mar 2025 11:42:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=bXWC/Du/uJCTUdWQGsoYtSngZV0PY4Q69kfUm29E+Oc=; b=Z+G8uoWZfE5ey0G2yfCp mPeEDjFcYu867m3E9wuUB09VagWBbbZ42A0QTXxkAZT87OY4ciMLiZIKpROaDAKC725xUHieeOx1h ms/m74FwTIwHq6kZmUEPuy23kAtUQph+0uy9vKySqwJFwdoy3QkCatqbqIf289cWFKNAb2TcYggcF Myyd2zsA/w5JadmrNgeQVtJ9lfIxE1SU5YdAH03gLs9+qihzTN3AmYqJ9sAxvECOGpiuewgSNyLP1 hEIb5BtBqD+70O7RqXbNWcICmEXe9cat8BZJRIr8Z8ObyqeC1aqHfNQUuAZNoiuGD23is8ooKw/+m bAtUAxR3Ti9D1w==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN> To: Giacomo Leidi <goodoldpaul@HIDDEN> Subject: Re: bug#76169: home: Add home-restic-backup service. In-Reply-To: <5f470034ff56eb23a7dc2e0a32f2a238e82a0f18.1741217283.git.goodoldpaul@HIDDEN> (Giacomo Leidi's message of "Thu, 6 Mar 2025 00:28:03 +0100") References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <5f470034ff56eb23a7dc2e0a32f2a238e82a0f18.1741217283.git.goodoldpaul@HIDDEN> Date: Sat, 08 Mar 2025 17:42:20 +0100 Message-ID: <874j03tqxf.fsf_-_@HIDDEN> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 76169 Cc: Tanguy Le Carrour <tanguy@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, 76169 <at> debbugs.gnu.org, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Andrew Tropin <andrew@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -3.3 (---) Giacomo Leidi <goodoldpaul@HIDDEN> skribis: > * gnu/services/backup.scm (restic-backup-configuration): Reimplement > with (guix records); > (restic-backup-job-{logfile,command,requirement,modules}): Add new > procedures and add support for Guix Home environments; > (restic-backup-job->shepherd-service): Add support for Guix Home > environments; > (restic-backup-service-activation): Drop procedure as now the Shepherd > takes care of creating directories for timers logs. > * gnu/home/services/backup.scm: New file. > * gnu/local.mk: Add this. > * doc/guix.texi: Document this. > > Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be Hi! It LGTM, but it doesn=E2=80=99t apply on top of a8db2cb547f93f915726eae8ebae7646a4361094: --8<---------------cut here---------------start------------->8--- patching file gnu/services/backup.scm Hunk #2 succeeded at 50 with fuzz 1. Hunk #3 FAILED at 57. Hunk #4 succeeded at 131 with fuzz 2 (offset -1 lines). Hunk #5 FAILED at 249. Hunk #6 FAILED at 334. 3 out of 6 hunks FAILED -- saving rejects to file gnu/services/backup.scm.r= ej --8<---------------cut here---------------end--------------->8--- Ludo=E2=80=99.
guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 5 Mar 2025 23:28:48 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Wed Mar 05 18:28:48 2025 Received: from localhost ([127.0.0.1]:40329 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tpyAO-0001TQ-Aq for submit <at> debbugs.gnu.org; Wed, 05 Mar 2025 18:28:48 -0500 Received: from confino.investici.org ([93.190.126.19]:50725) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1tpyAL-0001TG-Al for 76169 <at> debbugs.gnu.org; Wed, 05 Mar 2025 18:28:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1741217320; bh=uYaWDnYTCZMFOpjdPTUF+R8g81FVrnk4EtMQZxgLlWY=; h=From:To:Cc:Subject:Date:From; b=OWYsFoakmM6Bk0ks1cPd1jtrcT9DXS2F1x6GxoVxscOb1balXmvApkyYBXYnj7Q8s K5Yx2PCVXvPgG/sN2j5LZd43nUTv7zAeANi4RxMIq2X4mvlqETpGwr2r59gnPy8wsa 4/ZTBc6BjlxNJm70posYYQoCE/9JeTp4UF3kzPOo= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4Z7TJS2CRbz11J6; Wed, 5 Mar 2025 23:28:40 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4Z7TJS18TMz11HF; Wed, 5 Mar 2025 23:28:40 +0000 (UTC) From: Giacomo Leidi <goodoldpaul@HIDDEN> To: 76169 <at> debbugs.gnu.org Subject: [PATCH v5] home: Add home-restic-backup service. Date: Thu, 6 Mar 2025 00:28:03 +0100 Message-ID: <5f470034ff56eb23a7dc2e0a32f2a238e82a0f18.1741217283.git.goodoldpaul@HIDDEN> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-Debbugs-Cc: Andrew Tropin <andrew@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 76169 Cc: Giacomo Leidi <goodoldpaul@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.7 (-) * gnu/services/backup.scm (restic-backup-configuration): Reimplement with (guix records); (restic-backup-job-{logfile,command,requirement,modules}): Add new procedures and add support for Guix Home environments; (restic-backup-job->shepherd-service): Add support for Guix Home environments; (restic-backup-service-activation): Drop procedure as now the Shepherd takes care of creating directories for timers logs. * gnu/home/services/backup.scm: New file. * gnu/local.mk: Add this. * doc/guix.texi: Document this. Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be --- doc/guix.texi | 76 ++++++++++++++++++++++ gnu/home/services/backup.scm | 38 +++++++++++ gnu/local.mk | 1 + gnu/services/backup.scm | 119 +++++++++++++++++++++-------------- 4 files changed, 186 insertions(+), 48 deletions(-) create mode 100644 gnu/home/services/backup.scm diff --git a/doc/guix.texi b/doc/guix.texi index e4c5c86e91f..9708bd13646 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -463,6 +463,7 @@ Top * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -47677,6 +47678,7 @@ Home Services * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -49223,6 +49225,80 @@ Guix Home Services @end lisp @end defvar +@node Backup Home Services +@subsection Backup Services + +The @code{(gnu home services backup)} module offers services for backing up +file system trees. For now, it provides the @code{home-restic-backup-service-type}. + +With @code{home-restic-backup-service-type}, you can periodically back up +directories and files with @uref{https://restic.net/, Restic}, which +supports end-to-end encryption and deduplication. Consider the +following configuration: + +@lisp +(use-modules (gnu home services backup) ;for 'restic-backup-job', 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (simple-service 'backup-jobs + home-restic-backup-service-type + (list (restic-backup-job + (name "remote-ftp") + (repository "rclone:remote-ftp:backup/restic") + (password-file "/home/alice/.restic") + ;; Every day at 23. + (schedule "0 23 * * *") + (files '("/home/alice/.restic" + "/home/alice/.config/rclone" + "/home/alice/Pictures")))))))) +@end lisp + +In general it is preferrable to extend the @code{home-restic-backup-service-type}, +as shown in the example above. This is because it takes care of wrapping everything +with @code{for-home}, which enables the @code{home-restic-backup-service-type} and +@code{restic-backup-service-type} to share the same codebase. + +For a custom configuration, wrap your @code{restic-backup-configuration} in +@code{for-home}, as in this example: + +@lisp +(use-modules (gnu services) ;for 'for-home' + (gnu services backup) ;for 'restic-backup-job' and 'restic-backup-configuration' + (gnu home services backup) ;for 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (service home-restic-backup-service-type + (for-home + (restic-backup-configuration + (jobs (list @dots{})))))))) +@end lisp + +You can refer to @pxref{Miscellaneous Services, +@code{restic-backup-service-type}} for details about +@code{restic-backup-configuration} and @code{restic-backup-job}. +The only difference is that the @code{home-restic-backup-service-type} +will ignore the @code{user} and @code{group} field of +@code{restic-backup-job}. + +It will also install the @command{restic-guix} package to the user's Home +profile. + @node Fonts Home Services @subsection Fonts Home Services diff --git a/gnu/home/services/backup.scm b/gnu/home/services/backup.scm new file mode 100644 index 00000000000..ac977f835b6 --- /dev/null +++ b/gnu/home/services/backup.scm @@ -0,0 +1,38 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2025 Giacomo Leidi <goodoldpaul@HIDDEN> +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. + +(define-module (gnu home services backup) + #:use-module (gnu services) + #:use-module (gnu services backup) + #:use-module (gnu home services) + #:use-module (gnu home services shepherd) + #:export (home-restic-backup-service-type) + #:re-export (restic-backup-configuration + restic-backup-job)) + +(define home-restic-backup-service-type + (service-type + (inherit (system->home-service-type restic-backup-service-type)) + (extend + (lambda (config jobs) + (for-home + (restic-backup-configuration + (inherit config) + (jobs (append (restic-backup-configuration-jobs config) + jobs)))))) + (default-value (for-home (restic-backup-configuration))))) diff --git a/gnu/local.mk b/gnu/local.mk index 997b7344fff..ea93dc904de 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -103,6 +103,7 @@ GNU_SYSTEM_MODULES = \ %D%/home.scm \ %D%/home/services.scm \ %D%/home/services/admin.scm \ + %D%/home/services/backup.scm \ %D%/home/services/desktop.scm \ %D%/home/services/dict.scm \ %D%/home/services/dotfiles.scm \ diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm index dc095593432..3c092629774 100644 --- a/gnu/services/backup.scm +++ b/gnu/services/backup.scm @@ -28,6 +28,7 @@ (define-module (gnu services backup) #:prefix license:) #:use-module (guix modules) #:use-module (guix packages) + #:use-module (guix records) #:use-module (srfi srfi-1) #:export (restic-backup-job restic-backup-job? @@ -49,7 +50,6 @@ (define-module (gnu services backup) restic-backup-configuration restic-backup-configuration? - restic-backup-configuration-fields restic-backup-configuration-jobs restic-program @@ -57,7 +57,6 @@ (define-module (gnu services backup) restic-guix restic-guix-wrapper-package restic-backup-service-profile - restic-backup-service-activation restic-backup-service-type)) (define (gexp-or-string? value) @@ -132,13 +131,18 @@ (define-configuration/no-serialization restic-backup-job "A list of values that are lowered to strings. These will be passed as command-line arguments to the current @command{restic} invocation.")) -(define list-of-restic-backup-jobs? - (list-of restic-backup-job?)) +;; (for-home (restic-backup-configuration ...)) is not able to replace for-home? with #t, +;; pk prints #f. Once for-home will be able to work with (gnu services configuration) the +;; record can be migrated back to define-configuration. +(define-record-type* <restic-backup-configuration> + restic-backup-configuration + make-restic-backup-configuration + restic-backup-configuration? + this-restic-backup-configuration -(define-configuration/no-serialization restic-backup-configuration - (jobs - (list-of-restic-backup-jobs '()) - "The list of backup jobs for the current system.")) + (jobs restic-backup-configuration-jobs (default '())) ; list of restic-backup-job + (home-service? restic-backup-configuration-home-service? + (default for-home?) (innate))) (define %restic-guix-supported-actions '("backup" "list" "ls" "mount" "prune" "restore" "snapshots" "unlock")) @@ -244,53 +248,79 @@ (define* (restic-guix config #:key (supported-actions (main (command-line))))) -(define (restic-job-log-file job) +(define* (restic-backup-job-log-file job #:key (home-service? #f)) (let ((name (restic-backup-job-name job)) (log-file (restic-backup-job-log-file job))) (if (maybe-value-set? log-file) log-file - (string-append "/var/log/restic-backup/" name ".log")))) + (if home-service? + #~(begin + (use-modules (shepherd support)) + (string-append %user-log-dir "/restic-backup/" #$name ".log")) + (string-append "/var/log/restic-backup/" name ".log"))))) -(define (restic-backup-job->shepherd-service config) +(define* (restic-backup-job-command name files #:key (home-service? #f)) + (if home-service? + #~(list + "restic-guix" "backup" #$name #$@files) + #~(list + (string-append #+bash-minimal "/bin/bash") + "-l" "-c" + (string-append + "restic-guix backup " #$name " " + #$(string-join + (map (lambda (f) (string-append "'" f "'")) + files) + " "))))) + +(define* (restic-backup-job-requirement requirement #:key (home-service? #f)) + (if home-service? + requirement + (append '(user-processes file-systems) requirement))) + +(define* (restic-backup-job-modules #:key (home-service? #f)) + `((shepherd service timer) + ,@(if home-service? + ;;for %user-log-dir + '((shepherd support)) + '()))) + +(define* (restic-backup-job->shepherd-service config #:key (home-service? #f)) (let ((schedule (restic-backup-job-schedule config)) (name (restic-backup-job-name config)) - (files (string-join - (map (lambda (f) (string-append "'" f "'")) - (restic-backup-job-files config)) - " ")) + (files (restic-backup-job-files config)) (user (restic-backup-job-user config)) (group (restic-backup-job-group config)) (max-duration (restic-backup-job-max-duration config)) (wait-for-termination? (restic-backup-job-wait-for-termination? config)) - (log-file (restic-job-log-file config)) - (requirement (restic-backup-job-requirement config))) + (log-file (restic-backup-job-log-file + config #:home-service? home-service?)) + (requirement + (restic-backup-job-requirement + (restic-backup-job-requirement config) + #:home-service? home-service?))) (shepherd-service (provision `(,(string->symbol name))) - (requirement - `(user-processes file-systems ,@requirement)) + (requirement requirement) (documentation "Run @code{restic} backed backups on a regular basis.") - (modules '((shepherd service timer))) + (modules (restic-backup-job-modules + #:home-service? home-service?)) (start #~(make-timer-constructor (if (string? #$schedule) (cron-string->calendar-event #$schedule) #$schedule) (command - (list - ;; We go through bash, instead of executing - ;; restic-guix directly, because the login shell - ;; gives us the correct user environment that some - ;; backends require, such as rclone. - (string-append #+bash-minimal "/bin/bash") - "-l" "-c" - (string-append - "restic-guix backup " #$name " " #$files)) - #:user #$user - #:group #$group - #:environment-variables - (list - (string-append - "HOME=" (passwd:dir (getpwnam #$user))))) + #$(restic-backup-job-command + name files #:home-service? home-service?) + #$@(if home-service? '() (list #:user user)) + #$@(if home-service? '() (list #:group group)) + #$@(if home-service? '() + (list + #:environment-variables + #~(list + (string-append + "HOME=" (passwd:dir (getpwnam #$user))))))) #:log-file #$log-file #:wait-for-termination? #$wait-for-termination? #:max-duration #$(and (maybe-value-set? max-duration) @@ -329,26 +359,19 @@ (define restic-backup-service-profile (restic-guix-wrapper-package config)) '()))) -(define (restic-backup-service-activation config) - #~(for-each - (lambda (log-file) - (mkdir-p (dirname log-file))) - (list #$@(map restic-job-log-file - (restic-backup-configuration-jobs config))))) - (define restic-backup-service-type (service-type (name 'restic-backup) (extensions (list - (service-extension activation-service-type - restic-backup-service-activation) (service-extension profile-service-type restic-backup-service-profile) (service-extension shepherd-root-service-type - (lambda (config) - (map restic-backup-job->shepherd-service - (restic-backup-configuration-jobs - config)))))) + (match-record-lambda <restic-backup-configuration> + (jobs home-service?) + (map (lambda (job) + (restic-backup-job->shepherd-service + job #:home-service? home-service?)) + jobs))))) (compose concatenate) (extend (lambda (config jobs) base-commit: eacc927e82941220e5d4bd1f8737e7edbe5b712f -- 2.48.1
andrew@HIDDEN, janneke@HIDDEN, ludo@HIDDEN, maxim.cournoyer@HIDDEN, tanguy@HIDDEN, guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 5 Mar 2025 23:27:39 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Wed Mar 05 18:27:39 2025 Received: from localhost ([127.0.0.1]:40318 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tpy9L-0001Qt-D0 for submit <at> debbugs.gnu.org; Wed, 05 Mar 2025 18:27:39 -0500 Received: from confino.investici.org ([93.190.126.19]:22105) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1tpy9I-0001Qh-Tm for 76169 <at> debbugs.gnu.org; Wed, 05 Mar 2025 18:27:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1741217255; bh=T7uOTbRMS0esYxeEOjEJhx8KICRqOH++tqjcugEuF4w=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=a8BB5DwoY6VPmoMJ5HU8JZKF1wsYoHkgr0Y0UvYgTx4PilQCJwylom7b8WIntEcDZ Ssi0m77Wz5ueEGEnWHOak5xw22X75UGhqNAPvw4Kkh3zdyWdKI1i/5DG1t/70G040p nRVV3XsUVuqNIyI6arR77uNIasACvBN9HymLWf14= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4Z7THC0bxWz11Gp; Wed, 5 Mar 2025 23:27:35 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4Z7THB5ndJz11Fj; Wed, 5 Mar 2025 23:27:34 +0000 (UTC) Content-Type: multipart/alternative; boundary="------------iC8UzoCwv9H0tcYeMDK4JDFm" Message-ID: <b620d6de-b5d7-4ef8-a89a-07c5dc53e59e@HIDDEN> Date: Thu, 6 Mar 2025 00:27:34 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily Subject: Re: bug#76169: home: Add home-restic-backup service. To: =?UTF-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN> References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <3b94261d3f3c6746038e9f28158dc7292ba3958d.1740612555.git.goodoldpaul@HIDDEN> <8734frz5dg.fsf_-_@HIDDEN> Content-Language: en-US From: paul <goodoldpaul@HIDDEN> In-Reply-To: <8734frz5dg.fsf_-_@HIDDEN> X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 76169 Cc: Tanguy Le Carrour <tanguy@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, 76169 <at> debbugs.gnu.org, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Andrew Tropin <andrew@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.7 (-) This is a multi-part message in MIME format. --------------iC8UzoCwv9H0tcYeMDK4JDFm Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi, On 3/5/25 19:42, Ludovic Courtès wrote: > Overall LGTM. However the patch no longer applies; could you send an > updated patch? I should have addressed all your comments, if you are trying to apply this directly to master it will probably fail as it depends on issue #72803 revision 8. I'm sending a v5 rebased on revision 8 of 72803. thank you for your help, cheers giacomo --------------iC8UzoCwv9H0tcYeMDK4JDFm Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <p>Hi,<br> </p> <div class="moz-cite-prefix">On 3/5/25 19:42, Ludovic Courtès wrote:<span style="white-space: pre-wrap"> </span></div> <blockquote type="cite" cite="mid:8734frz5dg.fsf_-_@HIDDEN"> <pre class="moz-quote-pre" wrap="">Overall LGTM. However the patch no longer applies; could you send an updated patch? </pre> </blockquote> <p>I should have addressed all your comments, if you are trying to apply this directly to master it will probably fail as it depends on issue #72803 revision 8. I'm sending a v5 rebased on revision 8 of 72803.</p> <p>thank you for your help,</p> <p>cheers</p> <p>giacomo<br> </p> </body> </html> --------------iC8UzoCwv9H0tcYeMDK4JDFm--
guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 5 Mar 2025 18:42:30 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Wed Mar 05 13:42:29 2025 Received: from localhost ([127.0.0.1]:39832 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tpthN-0007ij-JK for submit <at> debbugs.gnu.org; Wed, 05 Mar 2025 13:42:29 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:58530) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <ludo@HIDDEN>) id 1tpthL-0007iV-CG for 76169 <at> debbugs.gnu.org; Wed, 05 Mar 2025 13:42:27 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id BE1D44C6; Wed, 5 Mar 2025 19:42:20 +0100 (CET) Authentication-Results: hera.aquilenet.fr; none X-Virus-Scanned: Debian amavis at hera.aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavis, port 10024) with ESMTP id ozyHL9vG8c1y; Wed, 5 Mar 2025 19:42:20 +0100 (CET) Received: from ribbon (91-160-117-201.subs.proxad.net [91.160.117.201]) by hera.aquilenet.fr (Postfix) with ESMTPSA id C7B572BB; Wed, 5 Mar 2025 19:42:19 +0100 (CET) From: =?utf-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN> To: Giacomo Leidi <goodoldpaul@HIDDEN> Subject: Re: bug#76169: home: Add home-restic-backup service. In-Reply-To: <3b94261d3f3c6746038e9f28158dc7292ba3958d.1740612555.git.goodoldpaul@HIDDEN> (Giacomo Leidi's message of "Thu, 27 Feb 2025 00:29:15 +0100") References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <3b94261d3f3c6746038e9f28158dc7292ba3958d.1740612555.git.goodoldpaul@HIDDEN> Date: Wed, 05 Mar 2025 19:42:19 +0100 Message-ID: <8734frz5dg.fsf_-_@HIDDEN> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: hera X-Rspamd-Queue-Id: BE1D44C6 X-Spamd-Result: default: False [6.40 / 15.00]; SPAM_FLAG(5.00)[]; BAYES_HAM(-3.00)[100.00%]; NEURAL_SPAM(3.00)[1.000]; SUSPICIOUS_RECIPS(1.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[debbugs.gnu.org,trop.in,gnu.org,gmail.com,bioneland.org]; MID_RHS_MATCH_FROM(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TAGGED_RCPT(0.00)[]; ARC_NA(0.00)[] X-Spamd-Bar: ++++++ X-Rspamd-Action: add header X-Spam-Level: ****** X-Spam: Yes X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 76169 Cc: Tanguy Le Carrour <tanguy@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, 76169 <at> debbugs.gnu.org, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Andrew Tropin <andrew@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -0.0 (/) Hi, Giacomo Leidi <goodoldpaul@HIDDEN> skribis: > * gnu/services/backup.scm (restic-backup-configuration): Reimplement > with (guix records); > (restic-backup-job-{logfile,command,requirement,modules}): Add new > procedures and add support for Guix Home environments; > (restic-backup-job->shepherd-service): Add support for Guix Home > environments; > (restic-backup-service-activation): Drop procedure as now the Shepherd > takes care of creating directories for timers logs. > * gnu/home/services/backup.scm: New file. > * gnu/local.mk: Add this. > * doc/guix.texi: Document this. > > Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be Overall LGTM. However the patch no longer applies; could you send an updated patch? Minor comments: > +@node Backup Home Services > +@subsection Backup Home Services The node name is good (it has to be unique), but the subsection name could simply be =E2=80=9CBackup Services=E2=80=9D. > +@lisp > +(use-modules (gnu services backup) ;for 'restic-backup-job' I would suggest #:re-export=E2=80=99ing the commonly needed bits from (gnu = home services backup), to reduce the amount of boilerplate needed, similar to what (gnu home services dict) does, for example. > -(define list-of-restic-backup-jobs? > - (list-of restic-backup-job?)) > +(define-record-type* <restic-backup-configuration> You can add a short comment right above to explain, as you proposed, why =E2=80=98define-configuration=E2=80=99 is not used. Thanks, Ludo=E2=80=99.
guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 26 Feb 2025 23:29:43 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 26 18:29:43 2025 Received: from localhost ([127.0.0.1]:56157 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tnQqR-0002L2-Q4 for submit <at> debbugs.gnu.org; Wed, 26 Feb 2025 18:29:43 -0500 Received: from confino.investici.org ([93.190.126.19]:50899) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1tnQqP-0002Kr-8R for 76169 <at> debbugs.gnu.org; Wed, 26 Feb 2025 18:29:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1740612576; bh=3cpuz3NqsxGX7ELpTotQGGlGYY8Hu+BhpdAYyXLic7g=; h=From:To:Cc:Subject:Date:From; b=VzAsq8B5oY3XondzwH8NWhezcl4E8Rk1U4lAF5FRBvxsvuud8cb6O3eGsrGB+bsAu 2vD+HKgSscH/3hPvexv5NLg8Y14Zq/hNSXSYYSTCFq6ssjCZHKkiWVZDjsRpj+4ipl xCElxePNFsuGIYuHmwkxYDmBIrkHy5gyN9X7DCFc= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4Z39fm2WfWz111s; Wed, 26 Feb 2025 23:29:36 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4Z39fm1VHgz111x; Wed, 26 Feb 2025 23:29:36 +0000 (UTC) From: Giacomo Leidi <goodoldpaul@HIDDEN> To: 76169 <at> debbugs.gnu.org Subject: [PATCH v4] home: Add home-restic-backup service. Date: Thu, 27 Feb 2025 00:29:15 +0100 Message-ID: <3b94261d3f3c6746038e9f28158dc7292ba3958d.1740612555.git.goodoldpaul@HIDDEN> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-Debbugs-Cc: Andrew Tropin <andrew@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 76169 Cc: Giacomo Leidi <goodoldpaul@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.7 (-) * gnu/services/backup.scm (restic-backup-configuration): Reimplement with (guix records); (restic-backup-job-{logfile,command,requirement,modules}): Add new procedures and add support for Guix Home environments; (restic-backup-job->shepherd-service): Add support for Guix Home environments; (restic-backup-service-activation): Drop procedure as now the Shepherd takes care of creating directories for timers logs. * gnu/home/services/backup.scm: New file. * gnu/local.mk: Add this. * doc/guix.texi: Document this. Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be --- doc/guix.texi | 77 +++++++++++++++++++++++ gnu/home/services/backup.scm | 36 +++++++++++ gnu/local.mk | 1 + gnu/services/backup.scm | 116 ++++++++++++++++++++--------------- 4 files changed, 182 insertions(+), 48 deletions(-) create mode 100644 gnu/home/services/backup.scm diff --git a/doc/guix.texi b/doc/guix.texi index 60ed003c82d..b53443ae7cb 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -463,6 +463,7 @@ Top * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -47245,6 +47246,7 @@ Home Services * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -48791,6 +48793,81 @@ Guix Home Services @end lisp @end defvar +@node Backup Home Services +@subsection Backup Home Services + +The @code{(gnu home services backup)} module offers services for backing up +file system trees. For now, it provides the @code{home-restic-backup-service-type}. + +With @code{home-restic-backup-service-type}, you can periodically back up +directories and files with @uref{https://restic.net/, Restic}, which +supports end-to-end encryption and deduplication. Consider the +following configuration: + +@lisp +(use-modules (gnu services backup) ;for 'restic-backup-job' + (gnu home services backup) ;for 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (simple-service 'backup-jobs + home-restic-backup-service-type + (list (restic-backup-job + (name "remote-ftp") + (repository "rclone:remote-ftp:backup/restic") + (password-file "/home/alice/.restic") + ;; Every day at 23. + (schedule "0 23 * * *") + (files '("/home/alice/.restic" + "/home/alice/.config/rclone" + "/home/alice/Pictures")))))))) +@end lisp + +In general it is preferrable to extend the @code{home-restic-backup-service-type}, +as shown in the example above. This is because it takes care of wrapping everything +with @code{for-home}, which enables the @code{home-restic-backup-service-type} and +@code{restic-backup-service-type} to share the same codebase. + +For a custom configuration, wrap your @code{restic-backup-configuration} in +@code{for-home}, as in this example: + +@lisp +(use-modules (gnu services) ;for 'for-home' + (gnu services backup) ;for 'restic-backup-job' and 'restic-backup-configuration' + (gnu home services backup) ;for 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (service home-restic-backup-service-type + (for-home + (restic-backup-configuration + (jobs (list @dots{})))))))) +@end lisp + +You can refer to @pxref{Miscellaneous Services, +@code{restic-backup-service-type}} for details about +@code{restic-backup-configuration} and @code{restic-backup-job}. +The only difference is that the @code{home-restic-backup-service-type} +will ignore the @code{user} and @code{group} field of +@code{restic-backup-job}. + +It will also install the @command{restic-guix} package to the user's Home +profile. + @node Fonts Home Services @subsection Fonts Home Services diff --git a/gnu/home/services/backup.scm b/gnu/home/services/backup.scm new file mode 100644 index 00000000000..7a30538bc06 --- /dev/null +++ b/gnu/home/services/backup.scm @@ -0,0 +1,36 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2025 Giacomo Leidi <goodoldpaul@HIDDEN> +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. + +(define-module (gnu home services backup) + #:use-module (gnu services) + #:use-module (gnu services backup) + #:use-module (gnu home services) + #:use-module (gnu home services shepherd) + #:export (home-restic-backup-service-type)) + +(define home-restic-backup-service-type + (service-type + (inherit (system->home-service-type restic-backup-service-type)) + (extend + (lambda (config jobs) + (for-home + (restic-backup-configuration + (inherit config) + (jobs (append (restic-backup-configuration-jobs config) + jobs)))))) + (default-value (for-home (restic-backup-configuration))))) diff --git a/gnu/local.mk b/gnu/local.mk index c8a29bf98b5..678e318f899 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -102,6 +102,7 @@ GNU_SYSTEM_MODULES = \ %D%/home.scm \ %D%/home/services.scm \ %D%/home/services/admin.scm \ + %D%/home/services/backup.scm \ %D%/home/services/desktop.scm \ %D%/home/services/dict.scm \ %D%/home/services/dotfiles.scm \ diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm index dc095593432..ae6d9bea82b 100644 --- a/gnu/services/backup.scm +++ b/gnu/services/backup.scm @@ -28,6 +28,7 @@ (define-module (gnu services backup) #:prefix license:) #:use-module (guix modules) #:use-module (guix packages) + #:use-module (guix records) #:use-module (srfi srfi-1) #:export (restic-backup-job restic-backup-job? @@ -49,7 +50,6 @@ (define-module (gnu services backup) restic-backup-configuration restic-backup-configuration? - restic-backup-configuration-fields restic-backup-configuration-jobs restic-program @@ -57,7 +57,6 @@ (define-module (gnu services backup) restic-guix restic-guix-wrapper-package restic-backup-service-profile - restic-backup-service-activation restic-backup-service-type)) (define (gexp-or-string? value) @@ -132,13 +131,15 @@ (define-configuration/no-serialization restic-backup-job "A list of values that are lowered to strings. These will be passed as command-line arguments to the current @command{restic} invocation.")) -(define list-of-restic-backup-jobs? - (list-of restic-backup-job?)) +(define-record-type* <restic-backup-configuration> + restic-backup-configuration + make-restic-backup-configuration + restic-backup-configuration? + this-restic-backup-configuration -(define-configuration/no-serialization restic-backup-configuration - (jobs - (list-of-restic-backup-jobs '()) - "The list of backup jobs for the current system.")) + (jobs restic-backup-configuration-jobs (default '())) ; list of restic-backup-job + (home-service? restic-backup-configuration-home-service? + (default for-home?) (innate))) (define %restic-guix-supported-actions '("backup" "list" "ls" "mount" "prune" "restore" "snapshots" "unlock")) @@ -244,53 +245,79 @@ (define* (restic-guix config #:key (supported-actions (main (command-line))))) -(define (restic-job-log-file job) +(define* (restic-backup-job-log-file job #:key (home-service? #f)) (let ((name (restic-backup-job-name job)) (log-file (restic-backup-job-log-file job))) (if (maybe-value-set? log-file) log-file - (string-append "/var/log/restic-backup/" name ".log")))) + (if home-service? + #~(begin + (use-modules (shepherd support)) + (string-append %user-log-dir "/restic-backup/" #$name ".log")) + (string-append "/var/log/restic-backup/" name ".log"))))) -(define (restic-backup-job->shepherd-service config) +(define* (restic-backup-job-command name files #:key (home-service? #f)) + (if home-service? + #~(list + "restic-guix" "backup" #$name #$@files) + #~(list + (string-append #+bash-minimal "/bin/bash") + "-l" "-c" + (string-append + "restic-guix backup " #$name " " + #$(string-join + (map (lambda (f) (string-append "'" f "'")) + files) + " "))))) + +(define* (restic-backup-job-requirement requirement #:key (home-service? #f)) + (if home-service? + requirement + (append '(user-processes file-systems) requirement))) + +(define* (restic-backup-job-modules #:key (home-service? #f)) + `((shepherd service timer) + ,@(if home-service? + ;;for %user-log-dir + '((shepherd support)) + '()))) + +(define* (restic-backup-job->shepherd-service config #:key (home-service? #f)) (let ((schedule (restic-backup-job-schedule config)) (name (restic-backup-job-name config)) - (files (string-join - (map (lambda (f) (string-append "'" f "'")) - (restic-backup-job-files config)) - " ")) + (files (restic-backup-job-files config)) (user (restic-backup-job-user config)) (group (restic-backup-job-group config)) (max-duration (restic-backup-job-max-duration config)) (wait-for-termination? (restic-backup-job-wait-for-termination? config)) - (log-file (restic-job-log-file config)) - (requirement (restic-backup-job-requirement config))) + (log-file (restic-backup-job-log-file + config #:home-service? home-service?)) + (requirement + (restic-backup-job-requirement + (restic-backup-job-requirement config) + #:home-service? home-service?))) (shepherd-service (provision `(,(string->symbol name))) - (requirement - `(user-processes file-systems ,@requirement)) + (requirement requirement) (documentation "Run @code{restic} backed backups on a regular basis.") - (modules '((shepherd service timer))) + (modules (restic-backup-job-modules + #:home-service? home-service?)) (start #~(make-timer-constructor (if (string? #$schedule) (cron-string->calendar-event #$schedule) #$schedule) (command - (list - ;; We go through bash, instead of executing - ;; restic-guix directly, because the login shell - ;; gives us the correct user environment that some - ;; backends require, such as rclone. - (string-append #+bash-minimal "/bin/bash") - "-l" "-c" - (string-append - "restic-guix backup " #$name " " #$files)) - #:user #$user - #:group #$group - #:environment-variables - (list - (string-append - "HOME=" (passwd:dir (getpwnam #$user))))) + #$(restic-backup-job-command + name files #:home-service? home-service?) + #$@(if home-service? '() (list #:user user)) + #$@(if home-service? '() (list #:group group)) + #$@(if home-service? '() + (list + #:environment-variables + #~(list + (string-append + "HOME=" (passwd:dir (getpwnam #$user))))))) #:log-file #$log-file #:wait-for-termination? #$wait-for-termination? #:max-duration #$(and (maybe-value-set? max-duration) @@ -329,26 +356,19 @@ (define restic-backup-service-profile (restic-guix-wrapper-package config)) '()))) -(define (restic-backup-service-activation config) - #~(for-each - (lambda (log-file) - (mkdir-p (dirname log-file))) - (list #$@(map restic-job-log-file - (restic-backup-configuration-jobs config))))) - (define restic-backup-service-type (service-type (name 'restic-backup) (extensions (list - (service-extension activation-service-type - restic-backup-service-activation) (service-extension profile-service-type restic-backup-service-profile) (service-extension shepherd-root-service-type - (lambda (config) - (map restic-backup-job->shepherd-service - (restic-backup-configuration-jobs - config)))))) + (match-record-lambda <restic-backup-configuration> + (jobs home-service?) + (map (lambda (job) + (restic-backup-job->shepherd-service + job #:home-service? home-service?)) + jobs))))) (compose concatenate) (extend (lambda (config jobs) base-commit: 18d01434cd56e2fce39362745bb8cb355d3356d9 -- 2.48.1
andrew@HIDDEN, janneke@HIDDEN, ludo@HIDDEN, maxim.cournoyer@HIDDEN, tanguy@HIDDEN, guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 26 Feb 2025 23:28:29 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 26 18:28:29 2025 Received: from localhost ([127.0.0.1]:56153 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tnQpJ-0002Il-4h for submit <at> debbugs.gnu.org; Wed, 26 Feb 2025 18:28:29 -0500 Received: from confino.investici.org ([93.190.126.19]:46719) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1tnQpF-0002IW-8v for 76169 <at> debbugs.gnu.org; Wed, 26 Feb 2025 18:28:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1740612503; bh=zS+vTAVWuhL9Xq0gS32C/rUPfLP6hKrHRjSDhlPJuHE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=kWejKjZz2pIgnwR4xUzkBY7Stt0WT1G9H4YwqtgmQT2E8IKyUM74fpco+gigyICoq n5A8jVZwgLpSHPEopqN6sUjZ98yZVXSfWSdEJ7vXMvnPZLc5qNN8ILzTk+ivr55Bef +n/7BdE9rVV5xS8iDs898KS9o6hvxcAsl/2Od2ZY= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4Z39dM3zRHz111x; Wed, 26 Feb 2025 23:28:23 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4Z39dM23fpz111s; Wed, 26 Feb 2025 23:28:23 +0000 (UTC) Content-Type: multipart/alternative; boundary="------------NDecM9Ziekk2zLmKy0z2glJG" Message-ID: <1ce0ba92-9e79-42d8-8b16-3cb8936fa101@HIDDEN> Date: Thu, 27 Feb 2025 00:28:22 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily Subject: Re: bug#76169: home: Add home-restic-backup service. To: =?UTF-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN> References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <d2544a068e6751d3983e0a58950cde674cadae13.1739146002.git.goodoldpaul@HIDDEN> <87seoi2hhp.fsf_-_@HIDDEN> <601921ab-c69f-41e4-ac74-3031fb0a46e8@HIDDEN> <87frk77510.fsf_-_@HIDDEN> Content-Language: en-US From: paul <goodoldpaul@HIDDEN> In-Reply-To: <87frk77510.fsf_-_@HIDDEN> X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 76169 Cc: 76169 <at> debbugs.gnu.org, Andrew Tropin <andrew@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.7 (-) This is a multi-part message in MIME format. --------------NDecM9Ziekk2zLmKy0z2glJG Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Ludo’, On 2/21/25 15:20, Ludovic Courtès wrote: > Hi, > > paul<goodoldpaul@HIDDEN> skribis: > >> It's a good idea, but I was not able to make for-home work with (gnu >> services configuration) so I changed restic-backup-configuration to a >> record type from (guix records). It does not impact end user configs >> in my tests. > Oh, is it because ‘define-configuration’ does not let you mark fields as > “innate”? I'm not sure, from experimentation (calling pk on the field that had for-home? as a default value) (for-home (oci-configuration is not able to replace for-home? with #t and pk prints #f. I didn't go deep enough to figure out why that is. I can put a comment stating that once for-home will be able to work with (gnu services configuration) the record can be migrated to define-configuration, if you don't find this is a blocking issue . I'm sending a new revision rebased on 72803 rebased on current master. cheers, giacomo --------------NDecM9Ziekk2zLmKy0z2glJG Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <p>Hi Ludo’,<br> </p> <div class="moz-cite-prefix">On 2/21/25 15:20, Ludovic Courtès wrote:<br> </div> <blockquote type="cite" cite="mid:87frk77510.fsf_-_@HIDDEN"> <pre class="moz-quote-pre" wrap="">Hi, paul <a class="moz-txt-link-rfc2396E" href="mailto:goodoldpaul@HIDDEN"><goodoldpaul@HIDDEN></a> skribis: </pre> <blockquote type="cite"> <pre class="moz-quote-pre" wrap="">It's a good idea, but I was not able to make for-home work with (gnu services configuration) so I changed restic-backup-configuration to a record type from (guix records). It does not impact end user configs in my tests. </pre> </blockquote> <pre class="moz-quote-pre" wrap=""> Oh, is it because ‘define-configuration’ does not let you mark fields as “innate”?</pre> </blockquote> <p><span style="white-space: pre-wrap">I'm not sure, from experimentation (calling pk on the field that had for-home? as a default value) (for-home (oci-configuration is not able to replace for-home? with #t and pk prints #f. I didn't go deep enough to figure out why that is. I can put a comment stating that once for-home will be able to work with (gnu services configuration) the record can be migrated to define-configuration, if you don't find this is a blocking issue . I'm sending a new revision rebased on 72803 rebased on current master. cheers,</span></p> <p><span style="white-space: pre-wrap">giacomo </span></p> </body> </html> --------------NDecM9Ziekk2zLmKy0z2glJG--
guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 21 Feb 2025 14:21:29 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Fri Feb 21 09:21:29 2025 Received: from localhost ([127.0.0.1]:57870 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tlTuC-00067I-3M for submit <at> debbugs.gnu.org; Fri, 21 Feb 2025 09:21:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55572) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <ludo@HIDDEN>) id 1tlTu9-00066D-QX for 76169 <at> debbugs.gnu.org; Fri, 21 Feb 2025 09:21:26 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <ludo@HIDDEN>) id 1tlTu2-0007la-Gw; Fri, 21 Feb 2025 09:21:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=m8VMHG+tkY//yCX1zUeE3IwFAcdtt4VG6kMFJqZ2e2Q=; b=JvjBLx+3Z2b1rooTE0Jx ZYUKaqe2m/2+LnX5Unz74T1TKUBsw51Og8WGkci+m2p+ckcUmXg2dMkItS23Uy/k/qZ2WXN7aGBcl BKvm8RmqZtLZFxnEpxf6J7Uf+O0PRduQvmA9ybfxH53fqE/xy7vdpQWJl86YO9uspeS4QgWgwD0Ek SxUzHhxiknnFy92k6VPgSxF5AMgNIRCq5JQ4AVGJeNMBu8MXr46kXIR27dzv30chJdjhxecn8zjQF +WvANcf/2KqyHr4mOJoUJ7AiEQYPWlq6KGfFDrV9u4t7W2p4T0aODp9qi7GGVJPkbha7JEpGt6Ala J4pL65CehOHL0g==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN> To: paul <goodoldpaul@HIDDEN> Subject: Re: bug#76169: home: Add home-restic-backup service. In-Reply-To: <601921ab-c69f-41e4-ac74-3031fb0a46e8@HIDDEN> (paul's message of "Thu, 13 Feb 2025 23:37:04 +0100") References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <d2544a068e6751d3983e0a58950cde674cadae13.1739146002.git.goodoldpaul@HIDDEN> <87seoi2hhp.fsf_-_@HIDDEN> <601921ab-c69f-41e4-ac74-3031fb0a46e8@HIDDEN> Date: Fri, 21 Feb 2025 15:20:59 +0100 Message-ID: <87frk77510.fsf_-_@HIDDEN> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 76169 Cc: 76169 <at> debbugs.gnu.org, Andrew Tropin <andrew@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -3.3 (---) Hi, paul <goodoldpaul@HIDDEN> skribis: > It's a good idea, but I was not able to make for-home work with (gnu > services configuration) so I changed restic-backup-configuration to a > record type from (guix records). It does not impact end user configs > in my tests. Oh, is it because =E2=80=98define-configuration=E2=80=99 does not let you m= ark fields as =E2=80=9Cinnate=E2=80=9D? Ludo=E2=80=99.
guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 13 Feb 2025 23:27:58 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 13 18:27:58 2025 Received: from localhost ([127.0.0.1]:46128 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tiicf-0002rv-AR for submit <at> debbugs.gnu.org; Thu, 13 Feb 2025 18:27:58 -0500 Received: from confino.investici.org ([93.190.126.19]:43927) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1tiicc-0002rk-Lo for 76169 <at> debbugs.gnu.org; Thu, 13 Feb 2025 18:27:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1739489273; bh=cg4KXEgmUKzPSYoNIdxSKicbVGjrKTuUYCf64WTF76w=; h=From:To:Cc:Subject:Date:From; b=i8K9QPrcbDPLT66NhvQf/ZQVHix3zVqdNIzQTjQtB3rDXQ8EwSFPdJqwowQy7F83R xwD09Z6bnFIeKSdThXqBTgs4X/2e8oAOD69uZ/E0uSNqBFN3e3m1tjA7cjEP3jsl0S Wq1TV0eZEaaDOavkgenOknm2mCxIwBno98YFyAgw= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4YvBDn2XnBz112W; Thu, 13 Feb 2025 23:27:53 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4YvBDn1X6vz112S; Thu, 13 Feb 2025 23:27:53 +0000 (UTC) From: Giacomo Leidi <goodoldpaul@HIDDEN> To: 76169 <at> debbugs.gnu.org Subject: [PATCH v3] home: Add home-restic-backup service. Date: Fri, 14 Feb 2025 00:27:49 +0100 Message-ID: <72b1f57b0c9d7e395f0041f4545123f9ae2b7d7b.1739489269.git.goodoldpaul@HIDDEN> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-Debbugs-Cc: Andrew Tropin <andrew@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 76169 Cc: Giacomo Leidi <goodoldpaul@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.7 (-) * gnu/services/backup.scm (restic-backup-configuration): Reimplement with (guix records); (restic-backup-job-{logfile,command,requirement,modules}): Add new procedures and add support for Guix Home environments; (restic-backup-job->shepherd-service): Add support for Guix Home environments; (restic-backup-service-activation): Drop procedure as now the Shepherd takes care of creating directories for timers logs. * gnu/home/services/backup.scm: New file. * gnu/local.mk: Add this. * doc/guix.texi: Document this. Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be --- doc/guix.texi | 77 +++++++++++++++++++++++ gnu/home/services/backup.scm | 40 ++++++++++++ gnu/local.mk | 1 + gnu/services/backup.scm | 116 ++++++++++++++++++++--------------- 4 files changed, 186 insertions(+), 48 deletions(-) create mode 100644 gnu/home/services/backup.scm diff --git a/doc/guix.texi b/doc/guix.texi index cdabe030953..96d400fee8c 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -462,6 +462,7 @@ Top * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -46753,6 +46754,7 @@ Home Services * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -48299,6 +48301,81 @@ Guix Home Services @end lisp @end defvar +@node Backup Home Services +@subsection Backup Home Services + +The @code{(gnu home services backup)} module offers services for backing up +file system trees. For now, it provides the @code{home-restic-backup-service-type}. + +With @code{home-restic-backup-service-type}, you can periodically back up +directories and files with @uref{https://restic.net/, Restic}, which +supports end-to-end encryption and deduplication. Consider the +following configuration: + +@lisp +(use-modules (gnu services backup) ;for 'restic-backup-job' + (gnu home services backup) ;for 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (simple-service 'backup-jobs + home-restic-backup-service-type + (list (restic-backup-job + (name "remote-ftp") + (repository "rclone:remote-ftp:backup/restic") + (password-file "/home/alice/.restic") + ;; Every day at 23. + (schedule "0 23 * * *") + (files '("/home/alice/.restic" + "/home/alice/.config/rclone" + "/home/alice/Pictures")))))))) +@end lisp + +In general it is preferrable to extend the @code{home-restic-backup-service-type}, +as shown in the example above. This is because it takes care of wrapping everything +with @code{for-home}, which enables the @code{home-restic-backup-service-type} and +@code{restic-backup-service-type} to share the same codebase. + +For a custom configuration, wrap your @code{restic-backup-configuration} in +@code{for-home}, as in this example: + +@lisp +(use-modules (gnu services) ;for 'for-home' + (gnu services backup) ;for 'restic-backup-job' and 'restic-backup-configuration' + (gnu home services backup) ;for 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (service home-restic-backup-service-type + (for-home + (restic-backup-configuration + (jobs (list @dots{})))))))) +@end lisp + +You can refer to @pxref{Miscellaneous Services, +@code{restic-backup-service-type}} for details about +@code{restic-backup-configuration} and @code{restic-backup-job}. +The only difference is that the @code{home-restic-backup-service-type} +will ignore the @code{user} and @code{group} field of +@code{restic-backup-job}. + +It will also install the @command{restic-guix} package to the user's Home +profile. + @node Fonts Home Services @subsection Fonts Home Services diff --git a/gnu/home/services/backup.scm b/gnu/home/services/backup.scm new file mode 100644 index 00000000000..658db30246d --- /dev/null +++ b/gnu/home/services/backup.scm @@ -0,0 +1,40 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2025 Giacomo Leidi <goodoldpaul@HIDDEN> +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. + +(define-module (gnu home services backup) + #:use-module (guix gexp) + #:use-module (guix packages) + #:use-module (gnu services) + #:use-module (gnu services backup) + #:use-module (gnu services configuration) + #:use-module (gnu home services) + #:use-module (gnu home services shepherd) + #:use-module (srfi srfi-1) + #:export (home-restic-backup-service-type)) + +(define home-restic-backup-service-type + (service-type + (inherit (system->home-service-type restic-backup-service-type)) + (extend + (lambda (config jobs) + (for-home + (restic-backup-configuration + (inherit config) + (jobs (append (restic-backup-configuration-jobs config) + jobs)))))) + (default-value (for-home (restic-backup-configuration))))) diff --git a/gnu/local.mk b/gnu/local.mk index fbca6d4ce83..fe7aa9261e7 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -102,6 +102,7 @@ GNU_SYSTEM_MODULES = \ %D%/home.scm \ %D%/home/services.scm \ %D%/home/services/admin.scm \ + %D%/home/services/backup.scm \ %D%/home/services/desktop.scm \ %D%/home/services/dict.scm \ %D%/home/services/dotfiles.scm \ diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm index dcbed890e13..97c12a5a480 100644 --- a/gnu/services/backup.scm +++ b/gnu/services/backup.scm @@ -28,6 +28,7 @@ (define-module (gnu services backup) #:prefix license:) #:use-module (guix modules) #:use-module (guix packages) + #:use-module (guix records) #:use-module (srfi srfi-1) #:export (restic-backup-job restic-backup-job? @@ -49,7 +50,6 @@ (define-module (gnu services backup) restic-backup-configuration restic-backup-configuration? - restic-backup-configuration-fields restic-backup-configuration-jobs restic-program @@ -57,7 +57,6 @@ (define-module (gnu services backup) restic-guix restic-guix-wrapper-package restic-backup-service-profile - restic-backup-service-activation restic-backup-service-type)) (define (gexp-or-string? value) @@ -132,13 +131,15 @@ (define-configuration/no-serialization restic-backup-job "A list of values that are lowered to strings. These will be passed as command-line arguments to the current @command{restic} invokation.")) -(define list-of-restic-backup-jobs? - (list-of restic-backup-job?)) +(define-record-type* <restic-backup-configuration> + restic-backup-configuration + make-restic-backup-configuration + restic-backup-configuration? + this-restic-backup-configuration -(define-configuration/no-serialization restic-backup-configuration - (jobs - (list-of-restic-backup-jobs '()) - "The list of backup jobs for the current system.")) + (jobs restic-backup-configuration-jobs (default '())) ; list of restic-backup-job + (home-service? restic-backup-configuration-home-service? + (default for-home?) (innate))) (define %restic-guix-supported-actions '("backup" "mount" "prune" "restore" "snapshots" "unlock")) @@ -244,53 +245,79 @@ (define* (restic-guix config #:key (supported-actions (main (command-line))))) -(define (restic-job-log-file job) +(define* (restic-backup-job-log-file job #:key (home-service? #f)) (let ((name (restic-backup-job-name job)) (log-file (restic-backup-job-log-file job))) (if (maybe-value-set? log-file) log-file - (string-append "/var/log/restic-backup/" name ".log")))) + (if home-service? + #~(begin + (use-modules (shepherd support)) + (string-append %user-log-dir "/restic-backup/" #$name ".log")) + (string-append "/var/log/restic-backup/" name ".log"))))) -(define (restic-backup-job->shepherd-service config) +(define* (restic-backup-job-command name files #:key (home-service? #f)) + (if home-service? + #~(list + "restic-guix" "backup" #$name #$@files) + #~(list + (string-append #+bash-minimal "/bin/bash") + "-l" "-c" + (string-append + "restic-guix backup " #$name " " + #$(string-join + (map (lambda (f) (string-append "'" f "'")) + files) + " "))))) + +(define* (restic-backup-job-requirement requirement #:key (home-service? #f)) + (if home-service? + requirement + (append '(user-processes file-systems) requirement))) + +(define* (restic-backup-job-modules #:key (home-service? #f)) + `((shepherd service timer) + ,@(if home-service? + ;;for %user-log-dir + '((shepherd support)) + '()))) + +(define* (restic-backup-job->shepherd-service config #:key (home-service? #f)) (let ((schedule (restic-backup-job-schedule config)) (name (restic-backup-job-name config)) - (files (string-join - (map (lambda (f) (string-append "'" f "'")) - (restic-backup-job-files config)) - " ")) + (files (restic-backup-job-files config)) (user (restic-backup-job-user config)) (group (restic-backup-job-group config)) (max-duration (restic-backup-job-max-duration config)) (wait-for-termination? (restic-backup-job-wait-for-termination? config)) - (log-file (restic-job-log-file config)) - (requirement (restic-backup-job-requirement config))) + (log-file (restic-backup-job-log-file + config #:home-service? home-service?)) + (requirement + (restic-backup-job-requirement + (restic-backup-job-requirement config) + #:home-service? home-service?))) (shepherd-service (provision `(,(string->symbol name))) - (requirement - `(user-processes file-systems ,@requirement)) + (requirement requirement) (documentation "Run @code{restic} backed backups on a regular basis.") - (modules '((shepherd service timer))) + (modules (restic-backup-job-modules + #:home-service? home-service?)) (start #~(make-timer-constructor (if (string? #$schedule) (cron-string->calendar-event #$schedule) #$schedule) (command - (list - ;; We go through bash, instead of executing - ;; restic-guix directly, because the login shell - ;; gives us the correct user environment that some - ;; backends require, such as rclone. - (string-append #+bash-minimal "/bin/bash") - "-l" "-c" - (string-append - "restic-guix backup " #$name " " #$files)) - #:user #$user - #:group #$group - #:environment-variables - (list - (string-append - "HOME=" (passwd:dir (getpwnam #$user))))) + #$(restic-backup-job-command + name files #:home-service? home-service?) + #$@(if home-service? '() (list #:user user)) + #$@(if home-service? '() (list #:group group)) + #$@(if home-service? '() + (list + #:environment-variables + #~(list + (string-append + "HOME=" (passwd:dir (getpwnam #$user))))))) #:log-file #$log-file #:wait-for-termination? #$wait-for-termination? #:max-duration #$(and (maybe-value-set? max-duration) @@ -329,26 +356,19 @@ (define restic-backup-service-profile (restic-guix-wrapper-package config)) '()))) -(define (restic-backup-service-activation config) - #~(for-each - (lambda (log-file) - (mkdir-p (dirname log-file))) - (list #$@(map restic-job-log-file - (restic-backup-configuration-jobs config))))) - (define restic-backup-service-type (service-type (name 'restic-backup) (extensions (list - (service-extension activation-service-type - restic-backup-service-activation) (service-extension profile-service-type restic-backup-service-profile) (service-extension shepherd-root-service-type - (lambda (config) - (map restic-backup-job->shepherd-service - (restic-backup-configuration-jobs - config)))))) + (match-record-lambda <restic-backup-configuration> + (jobs home-service?) + (map (lambda (job) + (restic-backup-job->shepherd-service + job #:home-service? home-service?)) + jobs))))) (compose concatenate) (extend (lambda (config jobs) base-commit: 3854375d83b8a549513c93fd379af22dc753c1d9 -- 2.48.1
andrew@HIDDEN, janneke@HIDDEN, ludo@HIDDEN, maxim.cournoyer@HIDDEN, tanguy@HIDDEN, guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 13 Feb 2025 23:26:50 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 13 18:26:50 2025 Received: from localhost ([127.0.0.1]:46124 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tiibZ-0002q3-SJ for submit <at> debbugs.gnu.org; Thu, 13 Feb 2025 18:26:50 -0500 Received: from confino.investici.org ([2a11:7980:1::2:0]:34215) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1tiibW-0002pr-G0 for 76169 <at> debbugs.gnu.org; Thu, 13 Feb 2025 18:26:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1739489204; bh=Z1UFitBSAi4loC3AiNxc+ALtTg1Dg6cTF2MhpsXxVh4=; h=Date:Subject:From:To:Cc:References:In-Reply-To:From; b=QgqOBvrnm7YW82YIOqlW/o0WC1bssvo6NIq2fgHYrzxXS+wtVUd5tbMSSjXHuVEEQ yMbG+Wnytp9QGdWxyYny+t64GtHWMoflS6chxdyUGwjtR1izcPzoPN4VrWZ/0CVS+L mEUvV4uoFSpYmkaNUuS6wdmyWmNdPvaUG4VLQiPU= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4YvBCS3Lzgz112t; Thu, 13 Feb 2025 23:26:44 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4YvBCS1YMvz112S; Thu, 13 Feb 2025 23:26:44 +0000 (UTC) Message-ID: <05849e25-d9a9-43bc-ac5c-4deb47fa4f2a@HIDDEN> Date: Fri, 14 Feb 2025 00:26:43 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily Subject: Re: bug#76169: home: Add home-restic-backup service. From: paul <goodoldpaul@HIDDEN> To: =?UTF-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN> References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <d2544a068e6751d3983e0a58950cde674cadae13.1739146002.git.goodoldpaul@HIDDEN> <87seoi2hhp.fsf_-_@HIDDEN> <601921ab-c69f-41e4-ac74-3031fb0a46e8@HIDDEN> Content-Language: en-US In-Reply-To: <601921ab-c69f-41e4-ac74-3031fb0a46e8@HIDDEN> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 76169 Cc: Tanguy Le Carrour <tanguy@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, 76169 <at> debbugs.gnu.org, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Andrew Tropin <andrew@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) Hi, I'm sending a v3 with a minor fix for the (command ...) invokation. Thank you for your time, giacomo
guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 13 Feb 2025 23:01:15 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 13 18:01:15 2025 Received: from localhost ([127.0.0.1]:46063 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tiiCo-0001j6-Eo for submit <at> debbugs.gnu.org; Thu, 13 Feb 2025 18:01:15 -0500 Received: from confino.investici.org ([93.190.126.19]:32693) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1tiiCk-0001io-Lw for 76169 <at> debbugs.gnu.org; Thu, 13 Feb 2025 18:01:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1739487668; bh=94nD4HjyDvWYy0mSwba34ePSMc33Df6ixavceyMWl0c=; h=From:To:Cc:Subject:Date:From; b=ouJzLLcY5eMW5CHbnbtDn7XKkAu/3SdsRdZs3fkRYHgRokQiA6ggU+Xi6hZyjSIHD 0I7ctpB6YU8spS0EFpgOs+4r0Y9So9HxDZs21l4fB8xdh+1QtqBhEsbeCQswTe00vY JAMRrH2PeTGufZfR6OxNpGs3FPYiEj0B3YCb9HTg= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4Yv9dw5K0Kz112W; Thu, 13 Feb 2025 23:01:08 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4Yv9dw4FRLz112S; Thu, 13 Feb 2025 23:01:08 +0000 (UTC) From: Giacomo Leidi <goodoldpaul@HIDDEN> To: 76169 <at> debbugs.gnu.org Subject: [PATCH v2] home: Add home-restic-backup service. Date: Fri, 14 Feb 2025 00:00:36 +0100 Message-ID: <b85abb2a1395b92458ee8c05e6ba4ea972278a96.1739487636.git.goodoldpaul@HIDDEN> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-Debbugs-Cc: Andrew Tropin <andrew@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 76169 Cc: Giacomo Leidi <goodoldpaul@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.7 (-) * gnu/services/backup.scm (restic-backup-configuration): Reimplement with (guix records); (restic-backup-job-{logfile,command,requirement,modules}): Add new procedures and add support for Guix Home environments; (restic-backup-job->shepherd-service): Add support for Guix Home environments; (restic-backup-service-activation): Drop procedure as now the Shepherd takes care of creating directories for timers logs. * gnu/home/services/backup.scm: New file. * gnu/local.mk: Add this. * doc/guix.texi: Document this. Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be --- doc/guix.texi | 77 +++++++++++++++++++++++ gnu/home/services/backup.scm | 40 ++++++++++++ gnu/local.mk | 1 + gnu/services/backup.scm | 116 ++++++++++++++++++++--------------- 4 files changed, 186 insertions(+), 48 deletions(-) create mode 100644 gnu/home/services/backup.scm diff --git a/doc/guix.texi b/doc/guix.texi index cdabe030953..96d400fee8c 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -462,6 +462,7 @@ Top * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -46753,6 +46754,7 @@ Home Services * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -48299,6 +48301,81 @@ Guix Home Services @end lisp @end defvar +@node Backup Home Services +@subsection Backup Home Services + +The @code{(gnu home services backup)} module offers services for backing up +file system trees. For now, it provides the @code{home-restic-backup-service-type}. + +With @code{home-restic-backup-service-type}, you can periodically back up +directories and files with @uref{https://restic.net/, Restic}, which +supports end-to-end encryption and deduplication. Consider the +following configuration: + +@lisp +(use-modules (gnu services backup) ;for 'restic-backup-job' + (gnu home services backup) ;for 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (simple-service 'backup-jobs + home-restic-backup-service-type + (list (restic-backup-job + (name "remote-ftp") + (repository "rclone:remote-ftp:backup/restic") + (password-file "/home/alice/.restic") + ;; Every day at 23. + (schedule "0 23 * * *") + (files '("/home/alice/.restic" + "/home/alice/.config/rclone" + "/home/alice/Pictures")))))))) +@end lisp + +In general it is preferrable to extend the @code{home-restic-backup-service-type}, +as shown in the example above. This is because it takes care of wrapping everything +with @code{for-home}, which enables the @code{home-restic-backup-service-type} and +@code{restic-backup-service-type} to share the same codebase. + +For a custom configuration, wrap your @code{restic-backup-configuration} in +@code{for-home}, as in this example: + +@lisp +(use-modules (gnu services) ;for 'for-home' + (gnu services backup) ;for 'restic-backup-job' and 'restic-backup-configuration' + (gnu home services backup) ;for 'home-restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + @dots{} + (service home-restic-backup-service-type + (for-home + (restic-backup-configuration + (jobs (list @dots{})))))))) +@end lisp + +You can refer to @pxref{Miscellaneous Services, +@code{restic-backup-service-type}} for details about +@code{restic-backup-configuration} and @code{restic-backup-job}. +The only difference is that the @code{home-restic-backup-service-type} +will ignore the @code{user} and @code{group} field of +@code{restic-backup-job}. + +It will also install the @command{restic-guix} package to the user's Home +profile. + @node Fonts Home Services @subsection Fonts Home Services diff --git a/gnu/home/services/backup.scm b/gnu/home/services/backup.scm new file mode 100644 index 00000000000..658db30246d --- /dev/null +++ b/gnu/home/services/backup.scm @@ -0,0 +1,40 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2025 Giacomo Leidi <goodoldpaul@HIDDEN> +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. + +(define-module (gnu home services backup) + #:use-module (guix gexp) + #:use-module (guix packages) + #:use-module (gnu services) + #:use-module (gnu services backup) + #:use-module (gnu services configuration) + #:use-module (gnu home services) + #:use-module (gnu home services shepherd) + #:use-module (srfi srfi-1) + #:export (home-restic-backup-service-type)) + +(define home-restic-backup-service-type + (service-type + (inherit (system->home-service-type restic-backup-service-type)) + (extend + (lambda (config jobs) + (for-home + (restic-backup-configuration + (inherit config) + (jobs (append (restic-backup-configuration-jobs config) + jobs)))))) + (default-value (for-home (restic-backup-configuration))))) diff --git a/gnu/local.mk b/gnu/local.mk index fbca6d4ce83..fe7aa9261e7 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -102,6 +102,7 @@ GNU_SYSTEM_MODULES = \ %D%/home.scm \ %D%/home/services.scm \ %D%/home/services/admin.scm \ + %D%/home/services/backup.scm \ %D%/home/services/desktop.scm \ %D%/home/services/dict.scm \ %D%/home/services/dotfiles.scm \ diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm index dcbed890e13..60c289d516e 100644 --- a/gnu/services/backup.scm +++ b/gnu/services/backup.scm @@ -28,6 +28,7 @@ (define-module (gnu services backup) #:prefix license:) #:use-module (guix modules) #:use-module (guix packages) + #:use-module (guix records) #:use-module (srfi srfi-1) #:export (restic-backup-job restic-backup-job? @@ -49,7 +50,6 @@ (define-module (gnu services backup) restic-backup-configuration restic-backup-configuration? - restic-backup-configuration-fields restic-backup-configuration-jobs restic-program @@ -57,7 +57,6 @@ (define-module (gnu services backup) restic-guix restic-guix-wrapper-package restic-backup-service-profile - restic-backup-service-activation restic-backup-service-type)) (define (gexp-or-string? value) @@ -132,13 +131,15 @@ (define-configuration/no-serialization restic-backup-job "A list of values that are lowered to strings. These will be passed as command-line arguments to the current @command{restic} invokation.")) -(define list-of-restic-backup-jobs? - (list-of restic-backup-job?)) +(define-record-type* <restic-backup-configuration> + restic-backup-configuration + make-restic-backup-configuration + restic-backup-configuration? + this-restic-backup-configuration -(define-configuration/no-serialization restic-backup-configuration - (jobs - (list-of-restic-backup-jobs '()) - "The list of backup jobs for the current system.")) + (jobs restic-backup-configuration-jobs (default '())) ; list of restic-backup-job + (home-service? restic-backup-configuration-home-service? + (default for-home?) (innate))) (define %restic-guix-supported-actions '("backup" "mount" "prune" "restore" "snapshots" "unlock")) @@ -244,53 +245,79 @@ (define* (restic-guix config #:key (supported-actions (main (command-line))))) -(define (restic-job-log-file job) +(define* (restic-backup-job-log-file job #:key (home-service? #f)) (let ((name (restic-backup-job-name job)) (log-file (restic-backup-job-log-file job))) (if (maybe-value-set? log-file) log-file - (string-append "/var/log/restic-backup/" name ".log")))) + (if home-service? + #~(begin + (use-modules (shepherd support)) + (string-append %user-log-dir "/restic-backup/" #$name ".log")) + (string-append "/var/log/restic-backup/" name ".log"))))) -(define (restic-backup-job->shepherd-service config) +(define* (restic-backup-job-command name files #:key (home-service? #f)) + (if home-service? + #~(list + "restic-guix" "backup" #$name #$@files) + #~(list + (string-append #+bash-minimal "/bin/bash") + "-l" "-c" + (string-append + "restic-guix backup " #$name " " + #$(string-join + (map (lambda (f) (string-append "'" f "'")) + files) + " "))))) + +(define* (restic-backup-job-requirement requirement #:key (home-service? #f)) + (if home-service? + requirement + (append '(user-processes file-systems) requirement))) + +(define* (restic-backup-job-modules #:key (home-service? #f)) + `((shepherd service timer) + ,@(if home-service? + ;;for %user-log-dir + '((shepherd support)) + '()))) + +(define* (restic-backup-job->shepherd-service config #:key (home-service? #f)) (let ((schedule (restic-backup-job-schedule config)) (name (restic-backup-job-name config)) - (files (string-join - (map (lambda (f) (string-append "'" f "'")) - (restic-backup-job-files config)) - " ")) + (files (restic-backup-job-files config)) (user (restic-backup-job-user config)) (group (restic-backup-job-group config)) (max-duration (restic-backup-job-max-duration config)) (wait-for-termination? (restic-backup-job-wait-for-termination? config)) - (log-file (restic-job-log-file config)) - (requirement (restic-backup-job-requirement config))) + (log-file (restic-backup-job-log-file + config #:home-service? home-service?)) + (requirement + (restic-backup-job-requirement + (restic-backup-job-requirement config) + #:home-service? home-service?))) (shepherd-service (provision `(,(string->symbol name))) - (requirement - `(user-processes file-systems ,@requirement)) + (requirement requirement) (documentation "Run @code{restic} backed backups on a regular basis.") - (modules '((shepherd service timer))) + (modules (restic-backup-job-modules + #:home-service? home-service?)) (start #~(make-timer-constructor (if (string? #$schedule) (cron-string->calendar-event #$schedule) #$schedule) (command - (list - ;; We go through bash, instead of executing - ;; restic-guix directly, because the login shell - ;; gives us the correct user environment that some - ;; backends require, such as rclone. - (string-append #+bash-minimal "/bin/bash") - "-l" "-c" - (string-append - "restic-guix backup " #$name " " #$files)) - #:user #$user - #:group #$group - #:environment-variables - (list - (string-append - "HOME=" (passwd:dir (getpwnam #$user))))) + #$(restic-backup-job-command + name files #:home-service? home-service?)) + #$@(if home-service? '() (list #:user user)) + #$@(if home-service? '() (list #:group group)) + #$@(if home-service? '() + (list + #:environment-variables + #~(list + (string-append + "HOME=" (passwd:dir (getpwnam #$user)))))) #:log-file #$log-file #:wait-for-termination? #$wait-for-termination? #:max-duration #$(and (maybe-value-set? max-duration) @@ -329,26 +356,19 @@ (define restic-backup-service-profile (restic-guix-wrapper-package config)) '()))) -(define (restic-backup-service-activation config) - #~(for-each - (lambda (log-file) - (mkdir-p (dirname log-file))) - (list #$@(map restic-job-log-file - (restic-backup-configuration-jobs config))))) - (define restic-backup-service-type (service-type (name 'restic-backup) (extensions (list - (service-extension activation-service-type - restic-backup-service-activation) (service-extension profile-service-type restic-backup-service-profile) (service-extension shepherd-root-service-type - (lambda (config) - (map restic-backup-job->shepherd-service - (restic-backup-configuration-jobs - config)))))) + (match-record-lambda <restic-backup-configuration> + (jobs home-service?) + (map (lambda (job) + (restic-backup-job->shepherd-service + job #:home-service? home-service?)) + jobs))))) (compose concatenate) (extend (lambda (config jobs) base-commit: 3854375d83b8a549513c93fd379af22dc753c1d9 -- 2.48.1
andrew@HIDDEN, janneke@HIDDEN, ludo@HIDDEN, maxim.cournoyer@HIDDEN, tanguy@HIDDEN, guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 13 Feb 2025 22:37:12 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 13 17:37:12 2025 Received: from localhost ([127.0.0.1]:46018 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tihpY-0000dG-DZ for submit <at> debbugs.gnu.org; Thu, 13 Feb 2025 17:37:12 -0500 Received: from confino.investici.org ([2a11:7980:1::2:0]:28649) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1tihpV-0000d3-Fy for 76169 <at> debbugs.gnu.org; Thu, 13 Feb 2025 17:37:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1739486226; bh=rIECEa253IpyHPUtJf2QBwjHmr8eeTYLsQ4HASHbjNU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ZDrcDYuf+dHyPg7jk92r0jB8Ajo4oPFcpQ3glTOQv36wbO4T1ip0yavGQl2LaoTRl u35ADWZGlKWggQPn26s/Uln4ETDh3REnU+7xkVGEDP6jETk4yb5crPF9Su72hsYjeJ BGgOB91K1o8On230BExUmqa/KO+vjoWAk1+7O2hk= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4Yv96B2Y2Mz112Z; Thu, 13 Feb 2025 22:37:06 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4Yv96B0W02z112g; Thu, 13 Feb 2025 22:37:05 +0000 (UTC) Message-ID: <601921ab-c69f-41e4-ac74-3031fb0a46e8@HIDDEN> Date: Thu, 13 Feb 2025 23:37:04 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily Subject: Re: bug#76169: home: Add home-restic-backup service. To: =?UTF-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN> References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <d2544a068e6751d3983e0a58950cde674cadae13.1739146002.git.goodoldpaul@HIDDEN> <87seoi2hhp.fsf_-_@HIDDEN> Content-Language: en-US From: paul <goodoldpaul@HIDDEN> In-Reply-To: <87seoi2hhp.fsf_-_@HIDDEN> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 76169 Cc: Tanguy Le Carrour <tanguy@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, 76169 <at> debbugs.gnu.org, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Andrew Tropin <andrew@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) Hi, It's a good idea, but I was not able to make for-home work with (gnu services configuration) so I changed restic-backup-configuration to a record type from (guix records). It does not impact end user configs in my tests. I'm sending a v2, thank you for your help! giacomo
guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 13 Feb 2025 11:48:37 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Thu Feb 13 06:48:37 2025 Received: from localhost ([127.0.0.1]:41037 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1tiXht-0002So-2L for submit <at> debbugs.gnu.org; Thu, 13 Feb 2025 06:48:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44892) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <ludo@HIDDEN>) id 1tiXhq-0002SU-Ej for 76169 <at> debbugs.gnu.org; Thu, 13 Feb 2025 06:48:35 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <ludo@HIDDEN>) id 1tiXhi-0005uU-Ht; Thu, 13 Feb 2025 06:48:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=ZzI/r+ybBWmUXcBeqboK59vzfgmQuNmI54FVMWPnyLY=; b=aLFz43ShTtX4pCNrWcw0 G14y4COQqVvhD028tzY5jdOleNjPa5tcQ7bb7maPK202el07lxTJlWPsajchrwvGPt8Hk/ofA5Siu hY57FjnDrrMZ3/7Sdv0a/KDAFPZKIhas9D60pBZ7NuptdahWoDdvSBY32YoLW01sl5x33iudXi3ks tZSiSitA4ycz9RtriOJSlcI6t7OiZgIrI8VP25AS9sJuu6JF2pK8/N1WuRdgeZwy2ACY3LT5MGF4Y jRvJAafvTu15R8zwhnV6yqZNEODtlXHQquKk87zIGs2YT6HepYol5LWyshOM4CDsil/y8rj5Off68 rNqTNR0W11hDmQ==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN> To: Giacomo Leidi <goodoldpaul@HIDDEN> Subject: Re: bug#76169: home: Add home-restic-backup service. In-Reply-To: <d2544a068e6751d3983e0a58950cde674cadae13.1739146002.git.goodoldpaul@HIDDEN> (Giacomo Leidi's message of "Mon, 10 Feb 2025 01:06:42 +0100") References: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> <d2544a068e6751d3983e0a58950cde674cadae13.1739146002.git.goodoldpaul@HIDDEN> Date: Thu, 13 Feb 2025 12:48:02 +0100 Message-ID: <87seoi2hhp.fsf_-_@HIDDEN> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 76169 Cc: Tanguy Le Carrour <tanguy@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, 76169 <at> debbugs.gnu.org, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Andrew Tropin <andrew@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -3.3 (---) Hi, Giacomo Leidi <goodoldpaul@HIDDEN> skribis: > +(define (restic-backup-job->home-shepherd-service config) > + (let ((schedule (restic-backup-job-schedule config)) > + (name (restic-backup-job-name config)) > + (files (restic-backup-job-files config)) > + (max-duration (restic-backup-job-max-duration config)) > + (wait-for-termination? (restic-backup-job-wait-for-termination? = config)) > + (log-file (home-restic-job-log-file config)) > + (requirement (restic-backup-job-requirement config))) > + (shepherd-service (provision `(,(string->symbol name))) > + (requirement > + `(,@requirement)) > + (documentation > + "Run @code{restic} backed backups on a regular ba= sis.") > + (modules '((shepherd service timer) > + ;;for %user-log-dir > + (shepherd support))) > + (start > + #~(make-timer-constructor > + (if (string? #$schedule) > + (cron-string->calendar-event #$schedule) > + #$schedule) Instead of duplicating the whole thing, I=E2=80=99d suggest using =E2=80=98= for-home?=E2=80=99 as is done for example with =E2=80=98home-dicod-service-type=E2=80=99. That w= ay, we end up with a single source that works for both system and home services. Ludo=E2=80=99.
guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.paul <goodoldpaul@HIDDEN>
to control <at> debbugs.gnu.org
.
Full text available.Received: (at 76169) by debbugs.gnu.org; 10 Feb 2025 00:07:32 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 09 19:07:32 2025 Received: from localhost ([127.0.0.1]:46934 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1thHKl-0008Ho-H7 for submit <at> debbugs.gnu.org; Sun, 09 Feb 2025 19:07:32 -0500 Received: from confino.investici.org ([93.190.126.19]:20075) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1thHKh-0008Ha-Aa for 76169 <at> debbugs.gnu.org; Sun, 09 Feb 2025 19:07:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1739146045; bh=eC4oukd9SZzDOVNKbcRFycPV70B3SPnn2nMr5ZFASZQ=; h=From:To:Cc:Subject:Date:From; b=qnZZvxl/Ao4sBAJ6v/sCvoWhvm/qCBh1/EKbkIgxUYUA9C64eGklS3tsA1f/6S5nJ 8TiJOrR3fB93ZLOmnA3CbOV5u3y4Y/Ir71/bzMuOVfBy2ASMuNS+f6O7abgdLbkZWy 9P16WElGoRMxvzddILtgJ/3Zs8pwMedhN57Dhhts= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4YrlJF5s0Wz110V; Mon, 10 Feb 2025 00:07:25 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4YrlJF4spBz110G; Mon, 10 Feb 2025 00:07:25 +0000 (UTC) From: Giacomo Leidi <goodoldpaul@HIDDEN> To: 76169 <at> debbugs.gnu.org Subject: [PATCH] home: Add home-restic-backup service. Date: Mon, 10 Feb 2025 01:06:42 +0100 Message-ID: <d2544a068e6751d3983e0a58950cde674cadae13.1739146002.git.goodoldpaul@HIDDEN> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-Debbugs-Cc: Andrew Tropin <andrew@HIDDEN>, Janneke Nieuwenhuizen <janneke@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Maxim Cournoyer <maxim.cournoyer@HIDDEN>, Tanguy Le Carrour <tanguy@HIDDEN> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 76169 Cc: Giacomo Leidi <goodoldpaul@HIDDEN> X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.7 (-) * gnu/home/services/backup.scm: New file. * gnu/local.mk: Add this. * doc/guix.texi: Document this. Change-Id: Ied1c0a5756b715fba176a0e42ea154246089e6be --- doc/guix.texi | 49 ++++++++++++++++ gnu/home/services/backup.scm | 107 +++++++++++++++++++++++++++++++++++ gnu/local.mk | 1 + 3 files changed, 157 insertions(+) create mode 100644 gnu/home/services/backup.scm diff --git a/doc/guix.texi b/doc/guix.texi index 86582fb4785..f8ad6769306 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -462,6 +462,7 @@ Top * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -46729,6 +46730,7 @@ Home Services * GPG: GNU Privacy Guard. Setting up GPG and related tools. * Desktop: Desktop Home Services. Services for graphical environments. * Guix: Guix Home Services. Services for Guix. +* Backup: Backup Home Services. Services for backing up User's files. * Fonts: Fonts Home Services. Services for managing User's fonts. * Sound: Sound Home Services. Dealing with audio. * Mail: Mail Home Services. Services for managing mail. @@ -48275,6 +48277,53 @@ Guix Home Services @end lisp @end defvar +@node Backup Home Services +@subsection Backup Home Services + +The @code{(gnu services backup)} module offers services for backing up +file system trees. For now, it provides the @code{restic-backup-service-type}. + +With @code{restic-backup-service-type}, you can periodically back up +directories and files with @uref{https://restic.net/, Restic}, which +supports end-to-end encryption and deduplication. Consider the +following configuration: + +@lisp +(use-modules (gnu services backup) ;for 'restic-backup-job' and 'restic-backup-configuration' + (gnu home services backup) ;for 'restic-backup-service-type' + (gnu packages sync) ;for 'rclone' + @dots{}) + +(home-environment + + (packages (list rclone ;for use by restic + @dots{})) + (services + (list + (service home-restic-backup-service-type + (restic-backup-configuration + (jobs + (list (restic-backup-job + (name "remote-ftp") + (repository "rclone:remote-ftp:backup/restic") + (password-file "/home/alice/.restic") + ;; Every day at 23. + (schedule "0 23 * * *") + (files '("/home/alice/.restic" + "/home/alice/.config/rclone" + "/home/alice/Pictures")))))))))) +@end lisp + +You can refer to @pxref{Miscellaneous Services, +@code{restic-backup-service-type}} for details about +@code{restic-backup-configuration} and @code{restic-job-configuration}. +The only difference is that the @code{home-restic-backup-service-type} +will ignore the @code{user} and @code{group} field of +@code{restic-job-configuration}. + +It will also install the @command{restic-guix} package to the user's Home +profile. + @node Fonts Home Services @subsection Fonts Home Services diff --git a/gnu/home/services/backup.scm b/gnu/home/services/backup.scm new file mode 100644 index 00000000000..421737eef74 --- /dev/null +++ b/gnu/home/services/backup.scm @@ -0,0 +1,107 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2025 Giacomo Leidi <goodoldpaul@HIDDEN> +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. + +(define-module (gnu home services backup) + #:use-module (guix gexp) + #:use-module (guix packages) + #:use-module (gnu services) + #:use-module (gnu services backup) + #:use-module (gnu services configuration) + #:use-module (gnu home services) + #:use-module (gnu home services shepherd) + #:use-module (srfi srfi-1) + #:export (home-restic-backup-service-type)) + +(define (home-restic-job-log-file job) + (let ((name (restic-backup-job-name job)) + (log-file (restic-backup-job-log-file job))) + (and (maybe-value-set? log-file) log-file))) + +(define (restic-backup-job->home-shepherd-service config) + (let ((schedule (restic-backup-job-schedule config)) + (name (restic-backup-job-name config)) + (files (restic-backup-job-files config)) + (max-duration (restic-backup-job-max-duration config)) + (wait-for-termination? (restic-backup-job-wait-for-termination? config)) + (log-file (home-restic-job-log-file config)) + (requirement (restic-backup-job-requirement config))) + (shepherd-service (provision `(,(string->symbol name))) + (requirement + `(,@requirement)) + (documentation + "Run @code{restic} backed backups on a regular basis.") + (modules '((shepherd service timer) + ;;for %user-log-dir + (shepherd support))) + (start + #~(make-timer-constructor + (if (string? #$schedule) + (cron-string->calendar-event #$schedule) + #$schedule) + (command + (list + "restic-guix" "backup" #$name #$@files)) + #:log-file (if (string? #$log-file) + #$log-file + (string-append %user-log-dir "/restic-backup/" #$name ".log")) + #:wait-for-termination? #$wait-for-termination? + #:max-duration #$(and (maybe-value-set? max-duration) + max-duration))) + (stop + #~(make-timer-destructor)) + (actions (list (shepherd-action + (name 'trigger) + (documentation "Manually trigger a backup, +without waiting for the scheduled time.") + (procedure #~trigger-timer))))))) + +(define (home-restic-backup-activation config) + #~(begin + (use-modules (shepherd support)) + (mkdir-p (string-append %user-log-dir "/restic-backup/")) + (for-each + (lambda (log-file) + (when (string? log-file) + (mkdir-p (dirname log-file)))) + (list #$@(map home-restic-job-log-file + (restic-backup-configuration-jobs config)))))) + +(define home-restic-backup-service-type + (service-type (name 'home-restic-backup) + (extensions + (list + (service-extension home-activation-service-type + home-restic-backup-activation) + (service-extension home-profile-service-type + restic-backup-service-profile) + (service-extension home-shepherd-service-type + (lambda (config) + (map restic-backup-job->home-shepherd-service + (restic-backup-configuration-jobs + config)))))) + (compose concatenate) + (extend + (lambda (config jobs) + (restic-backup-configuration + (inherit config) + (jobs (append (restic-backup-configuration-jobs config) + jobs))))) + (default-value (restic-backup-configuration)) + (description + "This service configures Shepherd timers for running backups +with restic."))) diff --git a/gnu/local.mk b/gnu/local.mk index 117280fc11b..b78c6755f12 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -102,6 +102,7 @@ GNU_SYSTEM_MODULES = \ %D%/home.scm \ %D%/home/services.scm \ %D%/home/services/admin.scm \ + %D%/home/services/backup.scm \ %D%/home/services/desktop.scm \ %D%/home/services/dict.scm \ %D%/home/services/dotfiles.scm \ base-commit: a1fac696c4ef5e20d0412ec22ae6a0d77ea26682 -- 2.48.1
andrew@HIDDEN, janneke@HIDDEN, ludo@HIDDEN, maxim.cournoyer@HIDDEN, tanguy@HIDDEN, guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.Received: (at submit) by debbugs.gnu.org; 10 Feb 2025 00:05:29 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sun Feb 09 19:05:29 2025 Received: from localhost ([127.0.0.1]:46920 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1thHIm-0008DM-JN for submit <at> debbugs.gnu.org; Sun, 09 Feb 2025 19:05:28 -0500 Received: from lists.gnu.org ([2001:470:142::17]:41894) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from <goodoldpaul@HIDDEN>) id 1thHIk-0008D1-QG for submit <at> debbugs.gnu.org; Sun, 09 Feb 2025 19:05:27 -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 <goodoldpaul@HIDDEN>) id 1thHIY-0002cB-Sa for guix-patches@HIDDEN; Sun, 09 Feb 2025 19:05:15 -0500 Received: from confino.investici.org ([2a11:7980:1::2:0]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <goodoldpaul@HIDDEN>) id 1thHIW-0005al-Ox for guix-patches@HIDDEN; Sun, 09 Feb 2025 19:05:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1739145899; bh=xpChnk9gNSBKQT8leBcCgPhrZiP2UAKE//e+nT6GLJU=; h=Date:To:From:Subject:From; b=ih1G8vYMnFeRGkAJnhkogebFiUqDB8FPkbx5480yF116RdPC42YPD82Ok+84z/h+/ IgG1Z8Xu+DHR8eib4iBJGOi9qU72JFU3Notz6RaA82l6xBqJryGWEPcJhNd5rmwZIk vBjabyOK5Q/8zQQDXNJLlRQeY9FAjU5EETTlhqAk= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4YrlFR1K1Cz111Q for <guix-patches@HIDDEN>; Mon, 10 Feb 2025 00:04:59 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@HIDDEN) by localhost (Postfix) with ESMTPSA id 4YrlFR0nn2z110C for <guix-patches@HIDDEN>; Mon, 10 Feb 2025 00:04:59 +0000 (UTC) Message-ID: <76d82b80-722b-46de-8791-d6a19def8c85@HIDDEN> Date: Mon, 10 Feb 2025 01:04:58 +0100 MIME-Version: 1.0 User-Agent: Icedove Daily To: guix-patches@HIDDEN Content-Language: en-US From: paul <goodoldpaul@HIDDEN> Subject: home: Add home-restic-backup service. Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=2a11:7980:1::2:0; envelope-from=goodoldpaul@HIDDEN; helo=confino.investici.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.9 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -0.1 (/) Hi Guix, I'm sending a patch implementing a Home service for the restic-backup-service-type. This patch depends on https://issues.guix.gnu.org/72803 . Thank you for your work! giacomo
paul <goodoldpaul@HIDDEN>
:guix-patches@HIDDEN
.
Full text available.guix-patches@HIDDEN
:bug#76169
; Package guix-patches
.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.