From patchwork Tue Jun 18 22:08:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Sent X-Patchwork-Id: 65480 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id F3CC127BBE2; Tue, 18 Jun 2024 23:10:41 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 8E48D27BBE9 for ; Tue, 18 Jun 2024 23:10:31 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJh1d-0005h9-Eu; Tue, 18 Jun 2024 18:10:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJh1c-0005gt-7U for guix-patches@gnu.org; Tue, 18 Jun 2024 18:10:00 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sJh1b-0003Bj-V9; Tue, 18 Jun 2024 18:09:59 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sJh1e-00034Q-FU; Tue, 18 Jun 2024 18:10:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#71639] [PATCH WIP 1/5] services: backup: Support bootstrapping an initial restic backup Resent-From: Richard Sent Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, ludo@gnu.org, matt@excalamus.com, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Tue, 18 Jun 2024 22:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71639 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 71639@debbugs.gnu.org Cc: ludo@gnu.org, Richard Sent , goodoldpaul@autistici.org, Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer Received: via spool by 71639-submit@debbugs.gnu.org id=B71639.171874856711656 (code B ref 71639); Tue, 18 Jun 2024 22:10:02 +0000 Received: (at 71639) by debbugs.gnu.org; 18 Jun 2024 22:09:27 +0000 Received: from localhost ([127.0.0.1]:53627 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJh14-00031t-IH for submit@debbugs.gnu.org; Tue, 18 Jun 2024 18:09:27 -0400 Received: from mail-108-mta227.mxroute.com ([136.175.108.227]:36689) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJh12-00031l-0F for 71639@debbugs.gnu.org; Tue, 18 Jun 2024 18:09:24 -0400 Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta227.mxroute.com (ZoneMTA) with ESMTPSA id 1902d65b3e000017a3.002 for <71639@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 18 Jun 2024 22:09:18 +0000 X-Zone-Loop: e7f3684c7a8d6b45121dcd13de1489fab24eddf7d436 X-Originating-IP: [136.175.111.3] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=mGC2u6AkPdw2TbKu3XSwToUFXRtmupACwqHDC9DtPuE=; b=eV5Ue2TnPuO+JHRwbrXr/VQmLF ukS/9YfAVuLqWFpn5Ac29ZGLUjVZv2AoZ5WIpc68esYPNme+Hq0I3dypmC4qSrQasl3+QVgStwUfa mE/hzPE1+tFFhXwGUZ7EAMxfHjaekou0CeytVcyV/Xg7fGkxczFFWwZCJlSSd3k5tVeYwoA8fuUeS g5I/9VxP42F+E5R35uUTtLDjR3B+dKS58ldVg4tzLP0T+OimGLbotKO4s7YSGqcVp/C1F6ySULUzE PWVGgLZDxjz+woKI/5/fouusJ6+Ovo+bgbiDiiiluRAef9fwmBrFgfG1AHiaXcYYLsOUkSAgb1BaC 7WU0YWNg==; From: Richard Sent Date: Tue, 18 Jun 2024 18:08:48 -0400 Message-ID: <88ce7267a59dfb3d80bd790e99b00a731e56835f.1718747513.git.richard@freakingpenguin.com> In-Reply-To: References: MIME-Version: 1.0 X-Authenticated-Id: richard@freakingpenguin.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/services/backup.scm: (restic-backup-job): Add init? field. (restic-backup-job-program): Initialize repository if init? is set and repository does not already exist. * doc/guix.texi (Miscellaneous Services): Document it. Change-Id: I71d0cbaac646b9d160e662b69286f229b9a9f64d --- doc/guix.texi | 4 ++++ gnu/services/backup.scm | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/doc/guix.texi b/doc/guix.texi index 0102fd0fad..63c9cbd1a7 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -41353,6 +41353,10 @@ Miscellaneous Services The list of files or directories to be backed up. It must be a list of values that can be lowered to strings. +@item @code{init?} (default: @code{#f}) (type: boolean) +Whether restic-backup-service should check and (if it does not exist) +initialize the repository before running the backup. + @item @code{verbose?} (default: @code{#f}) (type: boolean) Whether to enable verbose output for the current backup job. diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm index 555e9fc959..eeef11eae7 100644 --- a/gnu/services/backup.scm +++ b/gnu/services/backup.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2024 Giacomo Leidi +;;; Copyright © 2024 Richard Sent ;;; ;;; This file is part of GNU Guix. ;;; @@ -38,6 +39,7 @@ (define-module (gnu services backup) restic-backup-job-password-file restic-backup-job-schedule restic-backup-job-files + restic-backup-job-init? restic-backup-job-verbose? restic-backup-job-extra-flags @@ -94,6 +96,9 @@ (define-configuration/no-serialization restic-backup-job (verbose? (boolean #f) "Whether to enable verbose output for the current backup job.") + (init? + (boolean #f) + "Whether to attempt to initialize a new repository for automated bootstrap purposes.") (extra-flags (list-of-lowerables '()) "A list of values that are lowered to strings. These will be passed as @@ -118,6 +123,8 @@ (define (restic-backup-job-program config) (restic-backup-job-files config)) (extra-flags (restic-backup-job-extra-flags config)) + (init? + (restic-backup-job-init? config)) (verbose (if (restic-backup-job-verbose? config) '("--verbose") @@ -130,6 +137,19 @@ (define (restic-backup-job-program config) (setenv "RESTIC_PASSWORD" (with-input-from-file #$password-file read-line)) + (when #$init? + ;; Check if the repository exists. See + ;; https://github.com/restic/restic/issues/1690 and + ;; https://github.com/NixOS/nixpkgs/pull/307962. + ;; + ;; XXX: restic returns values other than 1 on failure. Use + ;; unless EXIT_SUCCESS instead of when EXIT_FAILURE. + (unless (equal? EXIT_SUCCESS (system* #$restic "cat" "config" + "-r" #$repository)) + ;; Initialize it. + (unless (equal? EXIT_SUCCESS (system* #$restic "init" + "-r" #$repository)) + (error "Failed to initialize restic repository: " #$repository)))) (execlp #$restic #$restic #$@verbose "-r" #$repository #$@extra-flags From patchwork Tue Jun 18 22:08:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sent X-Patchwork-Id: 65479 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 3369527BBED; Tue, 18 Jun 2024 23:10:38 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 0E5BE27BBEA for ; Tue, 18 Jun 2024 23:10:27 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJh1f-0005iD-II; Tue, 18 Jun 2024 18:10:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJh1d-0005h2-4e for guix-patches@gnu.org; Tue, 18 Jun 2024 18:10:01 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sJh1c-0003Bs-St; Tue, 18 Jun 2024 18:10:00 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sJh1f-00034o-JI; Tue, 18 Jun 2024 18:10:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#71639] [PATCH WIP 2/5] services: backup: Add password-command support to restic-service Resent-From: Richard Sent Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, ludo@gnu.org, matt@excalamus.com, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Tue, 18 Jun 2024 22:10:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71639 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 71639@debbugs.gnu.org Cc: ludo@gnu.org, Richard Sent , goodoldpaul@autistici.org, Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer Received: via spool by 71639-submit@debbugs.gnu.org id=B71639.171874857211692 (code B ref 71639); Tue, 18 Jun 2024 22:10:03 +0000 Received: (at 71639) by debbugs.gnu.org; 18 Jun 2024 22:09:32 +0000 Received: from localhost ([127.0.0.1]:53635 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJh19-00032Q-VW for submit@debbugs.gnu.org; Tue, 18 Jun 2024 18:09:32 -0400 Received: from mail-108-mta96.mxroute.com ([136.175.108.96]:35687) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJh17-000325-NN for 71639@debbugs.gnu.org; Tue, 18 Jun 2024 18:09:30 -0400 Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta96.mxroute.com (ZoneMTA) with ESMTPSA id 1902d65c5af00017a3.002 for <71639@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 18 Jun 2024 22:09:22 +0000 X-Zone-Loop: a6785a6d9facb99f9f55f23f5b5a0967bfa001671860 X-Originating-IP: [136.175.111.3] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=GRgk0YcfdnOlUM8vrZVXJwP2dkp9Z6VwaR5wZrbFuEI=; b=HW7eneh+kLX+dCqaomvyOr+SH9 LuOm19xVZUWxPIp1dJjUqFhYxHH/Qgpgefp3+0xsXWJGQ/io8DcWL7h9nNtTNP47dX3mWWN6Gl6rN /3RJaul5Dj8WU3ftYrpCBqZxhnlXHPKH8J4esc7oLDis5zfhkf4zSbZ68tBR7tUx9sqRwHDiT2VBI PuEJXzgYWKR/sWfAnSrG1Uo8lvWrw4KHKGZcM/M8CIXQp+z34mE2KmdTi2wn8D4Q11p0xHEFn3Kd7 lKJhNch1Eakcsx1p6v0Qk3d+s5wsxMsFWOBVGFX/Czxq01stNfhl1M40yEilobDtOlNf929TvZ5Oy RMFJYwfw==; From: Richard Sent Date: Tue, 18 Jun 2024 18:08:49 -0400 Message-ID: <388adecd6bae7d959392b862f1ccc234c0c24a6d.1718747513.git.richard@freakingpenguin.com> In-Reply-To: References: MIME-Version: 1.0 X-Authenticated-Id: richard@freakingpenguin.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/services/backup.scm (restic-backup-job): Add password-command. (verify-restic-backup-job-configuration): Create. (restic-backup-job-program): Set either RESTIC_PASSWORD or RESTIC_PASSWORD_COMMAND depending on what is configured. * doc/guix.texi (Miscellaneous Services): Document it. Change-Id: Ice9cf85d1ee4485a2737f515c63c969918219df0 --- doc/guix.texi | 7 +++++++ gnu/services/backup.scm | 42 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 63c9cbd1a7..f22d679023 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -41344,6 +41344,13 @@ Miscellaneous Services that will be used to set the @env{RESTIC_PASSWORD} environment variable for the current job. +@item @code{password-command} (type: file-like) +String path or file-like object representing the executable file that +prints password to stdout. If a file-like object is used, it is placed +in the store globally executable and in plain text. The executable +should be designed such that it does not compromise the password if an +unauthorized user runs it. + @item @code{schedule} (type: gexp-or-string) A string or a gexp that will be passed as time specification in the mcron job specification (@pxref{Syntax, mcron job specifications,, diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm index eeef11eae7..2471d0ea7b 100644 --- a/gnu/services/backup.scm +++ b/gnu/services/backup.scm @@ -66,6 +66,9 @@ (define (lowerable? value) (define list-of-lowerables? (list-of lowerable?)) +(define-maybe/no-serialization string) +(define-maybe/no-serialization file-like) + (define-configuration/no-serialization restic-backup-job (restic (package restic) @@ -80,10 +83,16 @@ (define-configuration/no-serialization restic-backup-job (string) "The restic repository target of this job.") (password-file - (string) + (maybe-string) "Name of the password file, readable by the configured @code{user}, that will be used to set the @code{RESTIC_PASSWORD} environment variable for the current job.") + (password-command + (maybe-file-like) + "Name of the password command that, when run, returns the password over +stdin. Due to the nature of the store this command will be globally executable +and should have external protections to ensure other users cannot retrieve the +password. This overrides password-file.") (schedule (gexp-or-string) "A string or a gexp that will be passed as time specification in the mcron @@ -104,6 +113,14 @@ (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} invokation.")) +(define (verify-restic-backup-job-configuration config) + (unless (or (maybe-value-set? (restic-backup-job-password-file config)) + (maybe-value-set? (restic-backup-job-password-command config))) + (error "either password-file or password-command must be configured.")) + (when (and (maybe-value-set? (restic-backup-job-password-file config)) + (maybe-value-set? (restic-backup-job-password-command config))) + (error "password-file and password-command can not be configured simultaneously."))) + (define list-of-restic-backup-jobs? (list-of restic-backup-job?)) @@ -113,12 +130,22 @@ (define-configuration/no-serialization restic-backup-configuration "The list of backup jobs for the current system.")) (define (restic-backup-job-program config) + (define (maybe-value-or-false maybe) + (if (maybe-value-set? maybe) + maybe + #f)) + + ;; TODO: Find a place to also verify restic-backup-configuration. Mainly that jobs >=1 + (verify-restic-backup-job-configuration config) + (let ((restic (file-append (restic-backup-job-restic config) "/bin/restic")) (repository (restic-backup-job-repository config)) (password-file - (restic-backup-job-password-file config)) + (maybe-value-or-false (restic-backup-job-password-file config))) + (password-command + (maybe-value-or-false (restic-backup-job-password-command config))) (files (restic-backup-job-files config)) (extra-flags @@ -134,9 +161,14 @@ (define (restic-backup-job-program config) #~(begin (use-modules (ice-9 popen) (ice-9 rdelim)) - (setenv "RESTIC_PASSWORD" - (with-input-from-file #$password-file read-line)) - + (or (and=> #$password-file (lambda (x) + (setenv "RESTIC_PASSWORD" + (with-input-from-file x read-line)))) + (and=> #$password-command (lambda (x) + (setenv "RESTIC_PASSWORD_COMMAND" x))) + ;; Have a backup error message in case + ;; verify-restic-backup-job-configuration is messed with + (error "Neither password-file or password-command set")) (when #$init? ;; Check if the repository exists. See ;; https://github.com/restic/restic/issues/1690 and From patchwork Tue Jun 18 22:08:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sent X-Patchwork-Id: 65482 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id ED00D27BBE9; Tue, 18 Jun 2024 23:10:42 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 81DC927BBF3 for ; Tue, 18 Jun 2024 23:10:32 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJh1g-0005iq-NS; Tue, 18 Jun 2024 18:10:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJh1e-0005hc-7i for guix-patches@gnu.org; Tue, 18 Jun 2024 18:10:02 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sJh1d-0003CI-UP; Tue, 18 Jun 2024 18:10:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sJh1e-00034b-UI; Tue, 18 Jun 2024 18:10:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#71639] [PATCH WIP 3/5] services: backup: Add extra-packages field to restic-backup-job Resent-From: Richard Sent Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, ludo@gnu.org, matt@excalamus.com, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Tue, 18 Jun 2024 22:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71639 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 71639@debbugs.gnu.org Cc: ludo@gnu.org, Richard Sent , goodoldpaul@autistici.org, Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer Received: via spool by 71639-submit@debbugs.gnu.org id=B71639.171874857211685 (code B ref 71639); Tue, 18 Jun 2024 22:10:02 +0000 Received: (at 71639) by debbugs.gnu.org; 18 Jun 2024 22:09:32 +0000 Received: from localhost ([127.0.0.1]:53633 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJh19-00032M-8d for submit@debbugs.gnu.org; Tue, 18 Jun 2024 18:09:31 -0400 Received: from mail-108-mta114.mxroute.com ([136.175.108.114]:46741) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJh17-000326-T6 for 71639@debbugs.gnu.org; Tue, 18 Jun 2024 18:09:30 -0400 Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta114.mxroute.com (ZoneMTA) with ESMTPSA id 1902d65cb7500017a3.002 for <71639@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 18 Jun 2024 22:09:24 +0000 X-Zone-Loop: e96ab436a84f242ce19376eba8c7f147e44e6d00a06e X-Originating-IP: [136.175.111.3] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Kp6UdaLafZCtMHopLCdbgRcFxUwyYsOPiJ26k1B1Afw=; b=SpgcITsdGm3r5gcBqaOitpwRi2 /8gtq6NnK8WTQLLOfF0Xg4d4WxYZDEC/J6PhAoMrhvDiub3k0YC+czTk+7ao3Si0EmZ9vPTP0AGid mx6slmzgS73OnbqWhL92Y9jUCJhaWZWk5hubvdZJlNu4CFeuxIQRzR++jhOUUuoHA+PtmHNOz5oZP XwNkbU+AKJiH4Y3gS4ECjC/4HTRqE7PAO42u7AsP/9rhM2Cv+ypsdbolt7yFLWDUwIyPllFGs9vyM 1Zj0Ftx2OFtedJ7JYxMup/M4DHxQWMDR39VkDfiSHFVOX2o7ogA6RGqV6UkQbowdz56/MJIRHr88c +NGOyytQ==; From: Richard Sent Date: Tue, 18 Jun 2024 18:08:50 -0400 Message-ID: <146d362c149771810d673e927b56d3ec44bc9bba.1718747513.git.richard@freakingpenguin.com> In-Reply-To: References: MIME-Version: 1.0 X-Authenticated-Id: richard@freakingpenguin.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/services/backup.scm (restic-backup-job): Create extra-packages. (restic-guix-wrapper-package): Add the extra-packages field of every job as inputs. * doc/guix.texi (Miscellaneous Services): Document it. Change-Id: I4f0b070bc6dc895553ba69256d14e45898291c02 --- doc/guix.texi | 4 ++++ gnu/services/backup.scm | 33 ++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index f22d679023..32ce0c86b9 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -41367,6 +41367,10 @@ Miscellaneous Services @item @code{verbose?} (default: @code{#f}) (type: boolean) Whether to enable verbose output for the current backup job. +@item @code{extra-packages} (default: @code{'()} (type: list-of-packages) +The list of extra packages needed for restic to run the current backup +job. + @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} diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm index 2471d0ea7b..a6d8404a5a 100644 --- a/gnu/services/backup.scm +++ b/gnu/services/backup.scm @@ -41,6 +41,7 @@ (define-module (gnu services backup) restic-backup-job-files restic-backup-job-init? restic-backup-job-verbose? + restic-backup-job-extra-packages restic-backup-job-extra-flags restic-backup-configuration @@ -102,6 +103,9 @@ (define-configuration/no-serialization restic-backup-job (list-of-lowerables '()) "The list of files or directories to be backed up. It must be a list of values that can be lowered to strings.") + (extra-packages + (list-of-packages '()) + "The list of extra packages needed for restic to run this backup job.") (verbose? (boolean #f) "Whether to enable verbose output for the current backup job.") @@ -239,22 +243,25 @@ (define (restic-backup-job->mcron-job config) #:user #$user))) (define (restic-guix-wrapper-package jobs) - (package - (name "restic-backup-service-wrapper") - (version "0.0.0") - (source (restic-guix jobs)) - (build-system copy-build-system) - (arguments - (list #:install-plan #~'(("./" "/bin")))) - (home-page "https://restic.net") - (synopsis - "Easily interact from the CLI with Guix configured backups") - (description - "This package provides a simple wrapper around @code{restic}, handled + (let ((extra-packages (append-map restic-backup-job-extra-packages + jobs))) + (package + (name "restic-backup-service-wrapper") + (version "0.0.0") + (source (restic-guix restic-package jobs)) + (build-system copy-build-system) + (arguments + (list #:install-plan #~'(("./" "/bin")))) + (home-page "https://restic.net") + (synopsis + "Easily interact from the CLI with Guix configured backups") + (description + "This package provides a simple wrapper around @code{restic}, handled by the @code{restic-backup-service-type}. It allows for easily interacting with Guix configured backup jobs, for example for manually triggering a backup without waiting for the scheduled job to run.") - (license license:gpl3+))) + (inputs extra-packages) + (license license:gpl3+)))) (define restic-backup-service-profile (lambda (config) From patchwork Tue Jun 18 22:08:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sent X-Patchwork-Id: 65481 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 47AFC27BBE2; Tue, 18 Jun 2024 23:10:42 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 6770827BBF1 for ; Tue, 18 Jun 2024 23:10:31 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJh1h-0005it-5I; Tue, 18 Jun 2024 18:10:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJh1f-0005iF-PQ for guix-patches@gnu.org; Tue, 18 Jun 2024 18:10:03 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sJh1f-0003KO-E7; Tue, 18 Jun 2024 18:10:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sJh1g-00034y-7J; Tue, 18 Jun 2024 18:10:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#71639] [PATCH WIP 4/5] services: backup: Move restic package to restic-configuration Resent-From: Richard Sent Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, ludo@gnu.org, matt@excalamus.com, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Tue, 18 Jun 2024 22:10:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71639 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 71639@debbugs.gnu.org Cc: ludo@gnu.org, Richard Sent , goodoldpaul@autistici.org, Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer Received: via spool by 71639-submit@debbugs.gnu.org id=B71639.171874857711724 (code B ref 71639); Tue, 18 Jun 2024 22:10:04 +0000 Received: (at 71639) by debbugs.gnu.org; 18 Jun 2024 22:09:37 +0000 Received: from localhost ([127.0.0.1]:53639 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJh1E-00032z-Gg for submit@debbugs.gnu.org; Tue, 18 Jun 2024 18:09:37 -0400 Received: from mail-108-mta24.mxroute.com ([136.175.108.24]:35981) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJh1B-00032e-VO for 71639@debbugs.gnu.org; Tue, 18 Jun 2024 18:09:34 -0400 Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta24.mxroute.com (ZoneMTA) with ESMTPSA id 1902d65d4ed00017a3.002 for <71639@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 18 Jun 2024 22:09:26 +0000 X-Zone-Loop: b0f797caa8b26b55f62ccc43adef6761ab86e5f6f5c1 X-Originating-IP: [136.175.111.3] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=PKqw4pzLvQWWJgeYjeiLEkGEn5gc6aE57W3QVB6MVzE=; b=lsqZl3daCbP2iR3NSryfK1JdwY RYqXKX/iGhu4p5/PZuYobhcabuspZIioL9wR4M6JVWs92FeSdALOK4pC5n4GzDXT7of0Z+UZMBOR8 gpbJwUZHOZ9oqDpK/vqlNFaQPcOOa/0XAW8caOtwb8wjTy/o501XZtvRH66Z9vSHN2SkoevulZrcx fPYQWUNjBuRO5/UidI9j7px+8U8Vxko0HaDs9mFbOAMpFnwrYlYMmUBO/hmtBDMKLBZgKMdaF/7/r Eg+L2m9Snblu9zIhoaEYHZ+vQ47nJs02JKX/shEpHt3duED73PNmuVAYTKrCZ/sL6nYbp7ETfTTpJ 2o/XkEKA==; From: Richard Sent Date: Tue, 18 Jun 2024 18:08:51 -0400 Message-ID: <7749ca0f06a80cf9accd24dc62fa8896cd35625d.1718747513.git.richard@freakingpenguin.com> In-Reply-To: References: MIME-Version: 1.0 X-Authenticated-Id: richard@freakingpenguin.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/services/backup.scm (restic-backup-configuration): Add restic field. (restic-backup-job-program): Add restic package to function signature. (restic-guix): Ditto. (restic-guix-wrapper-package): Ditto. Add restic package as package input. (restic-backup-service-profile): Remove excess lamba. * doc/guix.texi (Miscellaneous Services): Document it. Change-Id: I1e5f63c21cd072354225afe0ee270dca8d9d840b --- doc/guix.texi | 6 +++--- gnu/services/backup.scm | 38 ++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 32ce0c86b9..e4379c5e1c 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -41311,6 +41311,9 @@ Miscellaneous Services Available @code{restic-backup-configuration} fields are: @table @asis +@item @code{restic} (default: @code{restic}) (type: package) +The restic package to use for all jobs. + @item @code{jobs} (default: @code{'()}) (type: list-of-restic-backup-jobs) The list of backup jobs for the current system. @@ -41327,9 +41330,6 @@ Miscellaneous Services Available @code{restic-backup-job} fields are: @table @asis -@item @code{restic} (default: @code{restic}) (type: package) -The restic package to be used for the current job. - @item @code{user} (default: @code{"root"}) (type: string) The user used for running the current job. diff --git a/gnu/services/backup.scm b/gnu/services/backup.scm index a6d8404a5a..a59cf08c71 100644 --- a/gnu/services/backup.scm +++ b/gnu/services/backup.scm @@ -29,10 +29,10 @@ (define-module (gnu services backup) #:use-module (guix modules) #:use-module (guix packages) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) #:export (restic-backup-job restic-backup-job? restic-backup-job-fields - restic-backup-job-restic restic-backup-job-user restic-backup-job-name restic-backup-job-repository @@ -46,6 +46,7 @@ (define-module (gnu services backup) restic-backup-configuration restic-backup-configuration? + restic-backup-configuration-restic restic-backup-configuration-fields restic-backup-configuration-jobs @@ -71,9 +72,6 @@ (define-maybe/no-serialization string) (define-maybe/no-serialization file-like) (define-configuration/no-serialization restic-backup-job - (restic - (package restic) - "The restic package to be used for the current job.") (user (string "root") "The user used for running the current job.") @@ -129,11 +127,14 @@ (define list-of-restic-backup-jobs? (list-of restic-backup-job?)) (define-configuration/no-serialization restic-backup-configuration + (restic + (package restic) + "The restic package to be used.") (jobs (list-of-restic-backup-jobs '()) "The list of backup jobs for the current system.")) -(define (restic-backup-job-program config) +(define (restic-backup-job-program restic-package config) (define (maybe-value-or-false maybe) (if (maybe-value-set? maybe) maybe @@ -143,7 +144,7 @@ (define (restic-backup-job-program config) (verify-restic-backup-job-configuration config) (let ((restic - (file-append (restic-backup-job-restic config) "/bin/restic")) + (file-append restic-package "/bin/restic")) (repository (restic-backup-job-repository config)) (password-file @@ -191,7 +192,7 @@ (define (restic-backup-job-program config) #$@extra-flags "backup" #$@files))))) -(define (restic-guix jobs) +(define (restic-guix restic-package jobs) (program-file "restic-guix" #~(begin @@ -199,7 +200,7 @@ (define (restic-guix jobs) (srfi srfi-1)) (define names '#$(map restic-backup-job-name jobs)) - (define programs '#$(map restic-backup-job-program jobs)) + (define programs '#$(map (cut restic-backup-job-program restic-package <>) jobs)) (define (get-program name) (define idx @@ -242,13 +243,13 @@ (define (restic-backup-job->mcron-job config) #$(string-append "restic-guix backup " name) #:user #$user))) -(define (restic-guix-wrapper-package jobs) +(define (restic-guix-wrapper-package restic jobs) (let ((extra-packages (append-map restic-backup-job-extra-packages jobs))) (package (name "restic-backup-service-wrapper") (version "0.0.0") - (source (restic-guix restic-package jobs)) + (source (restic-guix restic jobs)) (build-system copy-build-system) (arguments (list #:install-plan #~'(("./" "/bin")))) @@ -260,16 +261,17 @@ (define (restic-guix-wrapper-package jobs) by the @code{restic-backup-service-type}. It allows for easily interacting with Guix configured backup jobs, for example for manually triggering a backup without waiting for the scheduled job to run.") - (inputs extra-packages) + (inputs (cons restic extra-packages)) (license license:gpl3+)))) -(define restic-backup-service-profile - (lambda (config) - (define jobs (restic-backup-configuration-jobs config)) - (if (> (length jobs) 0) - (list - (restic-guix-wrapper-package jobs)) - '()))) +(define (restic-backup-service-profile config) + (let ((jobs (restic-backup-configuration-jobs config)) + (restic (restic-backup-configuration-restic config))) + ;; Even if we provide a wrapper we need to add restic to the profile so + ;; the service works in containers and VMs which only see a subset of + ;; /gnu/store. https://issues.guix.gnu.org/70553. Ergo pass restic to + ;; the wrapper package so it is added as an input. + (list (restic-guix-wrapper-package restic jobs)))) (define restic-backup-service-type (service-type (name 'restic-backup) From patchwork Tue Jun 18 22:08:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Sent X-Patchwork-Id: 65483 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 2A56027BBEA; Tue, 18 Jun 2024 23:10:39 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 0451F27BBE2 for ; Tue, 18 Jun 2024 23:10:29 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sJh1g-0005iM-4r; Tue, 18 Jun 2024 18:10:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sJh1e-0005hb-3f for guix-patches@gnu.org; Tue, 18 Jun 2024 18:10:02 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sJh1d-0003CG-RF for guix-patches@gnu.org; Tue, 18 Jun 2024 18:10:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sJh1g-000357-Kk for guix-patches@gnu.org; Tue, 18 Jun 2024 18:10:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#71639] [PATCH WIP 5/5] tests: Add restic system test. Resent-From: Richard Sent Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 18 Jun 2024 22:10:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71639 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 71639@debbugs.gnu.org Cc: ludo@gnu.org, Richard Sent , goodoldpaul@autistici.org Received: via spool by 71639-submit@debbugs.gnu.org id=B71639.171874857711732 (code B ref 71639); Tue, 18 Jun 2024 22:10:04 +0000 Received: (at 71639) by debbugs.gnu.org; 18 Jun 2024 22:09:37 +0000 Received: from localhost ([127.0.0.1]:53641 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJh1F-000333-2c for submit@debbugs.gnu.org; Tue, 18 Jun 2024 18:09:37 -0400 Received: from mail-108-mta97.mxroute.com ([136.175.108.97]:45899) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sJh1B-00032f-Ri for 71639@debbugs.gnu.org; Tue, 18 Jun 2024 18:09:34 -0400 Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta97.mxroute.com (ZoneMTA) with ESMTPSA id 1902d65dda800017a3.002 for <71639@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Tue, 18 Jun 2024 22:09:29 +0000 X-Zone-Loop: d6e4ff4ee7c9d42ed7e0be8edd2dfc981f196448efac X-Originating-IP: [136.175.111.3] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ndeAEhgOmWt/RWqh6CBSsItSMi5TBX17zPJrwIfAoqQ=; b=qg7kXCfTvw33alVZkjc/qz7c0Z 0AipGSri43VBoQNwoD4GlA7vKt15qYix6yJXp4X8oWtvxdsszySdxwQTxjU/0LrwH37YES/gLut3Q 57LLcfdOrpCmlD0ZSsXARsIhBvhjFWaTIBPh9K2rklifTH80/lvnqNlNtXj2Bwd4gCTg8906PGDhf Gtl5jxLe9cuNPBVryj7Q3j8e9IOTK0Qom6APEOAGolEpXGMl5dHZMQL+F7qNoU0zQmSt2xwyBpq3B PJioooxas+MGZuedMR3iLKxg8MOOkrR4Qk2C7iPR9EEmr0UMWgC2uIJT7MmjA8rX+0t7X8S0An1H1 zc0pvtVA==; From: Richard Sent Date: Tue, 18 Jun 2024 18:08:52 -0400 Message-ID: <8efb248a6930d4e82d9f0e1e9cf77369c67780ca.1718747513.git.richard@freakingpenguin.com> In-Reply-To: References: MIME-Version: 1.0 X-Authenticated-Id: richard@freakingpenguin.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/tests/restic.scm: Create. Change-Id: Iad5472414c140b133d9b402855bb2f01e96bb0cc --- gnu/tests/restic.scm | 124 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 gnu/tests/restic.scm diff --git a/gnu/tests/restic.scm b/gnu/tests/restic.scm new file mode 100644 index 0000000000..f8ea76538e --- /dev/null +++ b/gnu/tests/restic.scm @@ -0,0 +1,124 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2024 Richard Sent . +;;; +;;; 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 . + +(define-module (gnu tests restic) + ;; TODO: Remove what I can from here. + #:use-module (gnu bootloader) + #:use-module (gnu bootloader grub) + #:use-module (gnu packages) + #:use-module (gnu packages sync) ;rclone + #:use-module (gnu packages xorg) + #:use-module (gnu services) + #:use-module (gnu services desktop) + #:use-module (gnu services backup) ;restic + #:use-module (gnu services xorg) + #:use-module (gnu system) + #:use-module (gnu system vm) + #:use-module (gnu tests) + #:use-module (guix gexp) + #:use-module (guix modules) + #:use-module (srfi srfi-1) + #:export (%test-restic)) + +(define password "password") + +(define password-file + (plain-file "password-file" password)) + +(define password-command + (program-file "password-command" #~(display #$password))) + +(define (run-restic-test) + "Run tests in %restic-os." + + (define os + (marionette-operating-system + (simple-operating-system (extra-special-file "/root/.restic-test" + (plain-file "restic-test" + "Hello world!")) + ;; restic-backup-service only takes a string to avoid putting + ;; plaintext entries in the store. Ergo, symlink it. + (extra-special-file "/root/password-file" + password-file) + (service restic-backup-service-type + (restic-backup-configuration + (jobs + (list (restic-backup-job + (name "password-file-backup") + (repository "/root/restic-password-file-repo") + (schedule #~'(next-second '(0 15 30 45))) + (password-file "/root/password-file") + (files '("/root/.restic-test")) + (init? #t)) + (restic-backup-job + (name "password-command-backup") + (repository "/root/restic-password-command-repo") + (schedule #~'(next-second '(0 15 30 45))) + (password-command password-command) + (files '("/root/.restic-test")) + (init? #t))))))) + #:imported-modules '((gnu services herd) + (guix combinators)))) + + (define vm (virtual-machine + (operating-system os) + ;; TODO: We might be able to lower this. + (memory-size 1024))) + + (define test + (with-imported-modules (source-module-closure + '((gnu build marionette))) + #~(begin + (use-modules (gnu build marionette) + (srfi srfi-26) + (srfi srfi-64)) + + (let ((marionette (make-marionette (list #$vm)))) + + (test-runner-current (system-test-runner #$output)) + (test-begin "restic") + + (test-assert "backup-file-created" + (wait-for-file "/root/.restic-test" marionette)) + + (test-assert "mcron running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (start-service 'mcron)) + marionette)) + + (test-assert "password-file backup completed" + (wait-for-file "/root/restic-password-file-repo/config" marionette + ;; Restic takes a second to run, give it a bit + ;; more time. + #:timeout 20)) + + (test-assert "password-comand backup completed" + (wait-for-file "/root/restic-password-file-repo/config" marionette + #:timeout 20)) + + (test-end))))) + + (gexp->derivation "restic-test" test)) + +(define %test-restic + (system-test + (name "restic") + (description "Basic tests for the restic service.") + (value (run-restic-test))))