From patchwork Sun Jan 24 02:13:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Csepp X-Patchwork-Id: 26591 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 A5BE527BC19; Sun, 24 Jan 2021 02:15:12 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 743AA27BC18 for ; Sun, 24 Jan 2021 02:15:10 +0000 (GMT) Received: from localhost ([::1]:56940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l3Uvl-0007jt-Fo for patchwork@mira.cbaines.net; Sat, 23 Jan 2021 21:15:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l3Uve-0007jZ-QA for guix-patches@gnu.org; Sat, 23 Jan 2021 21:15:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:52377) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l3Uve-0007Fd-IC for guix-patches@gnu.org; Sat, 23 Jan 2021 21:15:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l3Uve-0004O8-D6 for guix-patches@gnu.org; Sat, 23 Jan 2021 21:15:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#46063] [PATCH] WIP snapper fixes and snapperd service Resent-From: raingloom Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 24 Jan 2021 02:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 46063 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: "guix-devel@gnu.org" X-Debbugs-Original-Cc: mail@ambrevar.xyz, Guix Patches Received: via spool by submit@debbugs.gnu.org id=B.161145446316800 (code B ref -1); Sun, 24 Jan 2021 02:15:02 +0000 Received: (at submit) by debbugs.gnu.org; 24 Jan 2021 02:14:23 +0000 Received: from localhost ([127.0.0.1]:35690 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l3Uuv-0004Mn-Tc for submit@debbugs.gnu.org; Sat, 23 Jan 2021 21:14:23 -0500 Received: from lists.gnu.org ([209.51.188.17]:50386) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l3Uut-0004Mf-O2 for submit@debbugs.gnu.org; Sat, 23 Jan 2021 21:14:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:51814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l3Uus-0007Od-MU; Sat, 23 Jan 2021 21:14:14 -0500 Received: from mx1.riseup.net ([198.252.153.129]:46308) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l3Uun-0006zD-CV; Sat, 23 Jan 2021 21:14:14 -0500 Received: from fews1.riseup.net (unknown [10.0.1.83]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "Sectigo RSA Domain Validation Secure Server CA" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4DNc4Y36HYzFmHB; Sat, 23 Jan 2021 18:14:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1611454445; bh=eZw9Zn5i7+20bze14LqBIfBCOAnf0ElWquh+mglEHGY=; h=Date:From:To:Cc:Subject:From; b=lZncAY9zzzH5RSsBgwPz4nJdt65dVqLm1Qv9h/1OFQlvyP/ew+GV0Wu8tS8KFAdHk VsuhfBiTVJ6khZ9zpQfJTNv1TkBfI8itBP5fCQAcMcZks843nfHNcd47dZGmIz528v E8GafcYYgmnCzu5pvIwicOzo6Gu4r3JWQA+Q3cyQ= X-Riseup-User-ID: 6EC277314C56A2AD1DEB32F3C0FE7EEE9A9258CECA145A8679108D88E1BB361D Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews1.riseup.net (Postfix) with ESMTPSA id 4DNc4R0HLMz5vcX; Sat, 23 Jan 2021 18:13:56 -0800 (PST) Date: Sun, 24 Jan 2021 03:13:37 +0100 From: raingloom Message-ID: <20210124031337.72dfb12c@riseup.net> MIME-Version: 1.0 Received-SPF: pass client-ip=198.252.153.129; envelope-from=raingloom@riseup.net; helo=mx1.riseup.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Cc: 46063@debbugs.gnu.org, mail@ambrevar.xyz Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Hi! I have a technically working but still only lightly tested and not very user friendly patch set for making Snapper work! Included is Pierre Neidhardt's original patch, followed by my patches. How to try it: Everything needs sudo for now, sorry about that. This could probably be changed so that users could administrate configs pertaining only to their home dirs, but it looks like ading new configs will require sudo no matter what. 0. Have a BTRFS file system mounted somewhere. You may have heard that other setups (like ext4 or thin LVM) also works, but based on issue tracker activity, it looks very much like they don't, or aren't maintained and can break at any time. ``` # Create new subvolume btrfs subvolume create # Attempt to create a new config without understanding what you're getting into: sudo snapper -c my-config-name create-config path/to/subvolume # This will show informative messages like `Failure (error.something).` # Obviously this is because you haven't populated the relevant parts of # /etc. Duh. So do this, and think about how fun it must have been to # track down the sources of these messages. sudo cp -r $(./pre-inst-env guix build snapper)/etc/snapper /etc/snapper sudo install -D -m 644 $(./pre-inst-env guix build --source snapper)/data/sysconfig.snapper /etc/sysconfig/snapper # Add snapper-service-type to an operating-system. I assume you know how to do it on your own. # If anything breaks: sudo herd status snapperd # It sometimes stops for some reason? Just enable it and restart. # Anyways, now you can create a configuration. :D sudo snapper -c my-config-name create-config path/to/subvolume ``` Now just continue trying stuff from one of the many Snapper tutorials around the net, like the Arch Wiki one. Yay! Was that unnecessarily hard? It was. That's why this is a WIP patchset and why I need some tips on making it work better. * Should snapper be configured to use something other than /etc/sysconfig? The sysconfig subdirectory doesn't really make sense on Guix, but maybe it's not worth bikeshedding. * (How) should homes be converted to BTRFS subvolumes? * Snapshot scheduling is still TODO. * Should /etc/snapper even be mutable? How to handle the configuration data type? TLDR: I have some ideas on how to proceed, but would welcome some input from people who have some experience setting up backups and snapshotting, either on Guix, or Nix, or some traditional distro. From 2fb7a62710d17cee87c5cf4c73df49fdee3b668f Mon Sep 17 00:00:00 2001 From: raingloom Date: Fri, 8 Jan 2021 23:02:01 +0100 Subject: [PATCH 3/3] WIP: gnu: services: Added basics of snapper service. --- gnu/packages/linux.scm | 7 ++++- gnu/services/linux.scm | 60 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm index 16279e50c3..dca77e2fa4 100644 --- a/gnu/packages/linux.scm +++ b/gnu/packages/linux.scm @@ -5083,6 +5083,10 @@ obviously it can be shared with files outside our set).") (license license:gpl2+))) (define-public snapper + ;; TODO: create full system tests + ;; FIXME: client can't find "config template". what even is that. + ;; TODO: generate /etc/sysconfig/snapper from Guix + ;; TODO: snapperd should take a command line argument instead of hardcoding config path (package (name "snapper") (version "0.8.15") @@ -5146,7 +5150,8 @@ obviously it can be shared with files outside our set).") (("(pam_snapperdir = )/usr(/lib/pam_snapper)" _ before after) (string-append before out after))) (substitute* "data/Makefile.am" - (("\\$\\(DESTDIR\\)") out)) + (("\\$\\(DESTDIR\\)") out) + (("/usr/") "/")) (substitute* "pam/Makefile.am" (("(securelibdir = )\\$\\(shell echo /`basename \\$\\(libdir\\)`/security\\)" _ before) (string-append before out "/lib/security")))))) diff --git a/gnu/services/linux.scm b/gnu/services/linux.scm index 1046a7e0c2..7dfee8d9cd 100644 --- a/gnu/services/linux.scm +++ b/gnu/services/linux.scm @@ -24,6 +24,7 @@ #:use-module (guix modules) #:use-module (gnu services) #:use-module (gnu services base) + #:use-module (gnu services dbus) #:use-module (gnu services shepherd) #:use-module (gnu packages linux) #:use-module (srfi srfi-1) @@ -46,6 +47,11 @@ kernel-module-loader-service-type + snapper-configuration + snapper-configuration? + snapper-configuration-snapper + snapper-service-type + zram-device-configuration zram-device-configuration? zram-device-configuration-size @@ -187,6 +193,60 @@ representation." (extend append) (default-value '()))) + +;;; +;;; File system snapshotter +;;; + +;; TODO: other services might want to extend it with filters +;; TODO: extend PAM and snapshot home on login (see man pam_snapper) +;; TODO: convert pam_snapper_homeconvert.sh into a shepherd service +;; TODO: data type for snapper configs + +(define-record-type* + snapper-configuration make-snapper-configuration + snapper-configuration? + (snapper snapper-configuration-snapper + (default snapper))) + +(define (snapper-scm->config key) + (let* ((key-lo (string-downcase key)) + (maybe-scm-key (assoc-ref + '(("file-system-type" . "fstype") + ("quote-group" . "qgroup")) + key-lo))) + (string-upcase + (string-map + (lambda (c) + (if (eq? #\- c) + #\_ + c)) + (or maybe-scm-key key-lo))))) + +(define (snapper-shepherd-service config) + (shepherd-service + (documentation "Run the Snapper daemon (snapperd).") + (provision '(snapperd)) + (start #~(make-forkexec-constructor + '#$(list (file-append + (snapper-configuration-snapper config) + "/sbin/snapperd")) + #:log-file "/var/log/snapperd.log")) + (stop #~(make-kill-destructor)))) + +(define snapper-service-type + (service-type + (name 'snapper) + (extensions + (list + (service-extension shepherd-root-service-type + (compose list snapper-shepherd-service)) + (service-extension dbus-root-service-type + (compose list snapper-configuration-snapper)))) + (default-value (snapper-configuration)) + (description + "Create periodic snapshots on BTRFS subvolumes and thin LVM volumes"))) + ;;; ;;; Kernel module loader. -- 2.30.0