commit df9d3da612e9d11f3de247f0728cbc1f31ae984e (tree)
parent 50c84391ee2f23e9293420ede50f17ee98ef8e88
Author: Motiejus Jakštys <motiejus@jakstys.lt>
Date: Mon, 6 May 2024 05:55:27 +0300
btrfs-auto-snapshot
Diffstat:
5 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/flake.nix b/flake.nix
@@ -109,6 +109,7 @@
inherit (super.callPackage ./pkgs/compress-drv.nix {}) compressDrvWeb;
tmuxbash = super.callPackage ./pkgs/tmuxbash.nix {};
+ btrfs-auto-snapshot = super.callPackage ./pkgs/btrfs-auto-snapshot.nix {};
nicer = super.callPackage ./pkgs/nicer.nix {};
# TODO: copied from 24.05
diff --git a/hosts/mtworx/configuration.nix b/hosts/mtworx/configuration.nix
@@ -11,6 +11,7 @@ in {
../../modules
../../modules/profiles/desktop
../../modules/profiles/autorandr
+ ../../modules/profiles/btrfs
];
boot = {
diff --git a/hosts/vno1-op5p/configuration.nix b/hosts/vno1-op5p/configuration.nix
@@ -7,6 +7,9 @@
in {
imports = [
../../modules
+
+ ../../modules/profiles/btrfs
+
../../shared/platform/orangepi5plus.nix
];
diff --git a/modules/profiles/btrfs/default.nix b/modules/profiles/btrfs/default.nix
@@ -0,0 +1,5 @@
+{pkgs, ...}: {
+ boot.supportedFilesystems = ["btrfs"];
+
+ environment.systemPackages = [pkgs.btrfs-auto-snapshot];
+}
diff --git a/pkgs/btrfs-auto-snapshot.nix b/pkgs/btrfs-auto-snapshot.nix
@@ -0,0 +1,72 @@
+{
+ lib,
+ stdenv,
+ fetchFromGitHub,
+ makeWrapper,
+ coreutils,
+ getopt,
+ gnugrep,
+ gnused,
+ btrfs-progs,
+ syslogSupport ? true,
+ util-linux ? null,
+}:
+assert syslogSupport -> util-linux != null;
+ stdenv.mkDerivation rec {
+ version = "2.0.4";
+ pname = "btrfs-auto-snapshot";
+
+ src = fetchFromGitHub {
+ owner = "hunleyd";
+ repo = pname;
+ rev = "v${version}";
+ hash = "sha256-QpuwkGaYAkpu5hYyb360Mr5tHsZc2LzMlKtpS8CyyhI=";
+ };
+
+ dontBuild = true;
+
+ nativeBuildInputs = [makeWrapper];
+
+ installPhase = ''
+ install -Dm755 btrfs-auto-snapshot $out/bin/btrfs-auto-snapshot
+ '';
+
+ wrapperPath = with lib;
+ makeBinPath (
+ [
+ coreutils
+ getopt
+ gnugrep
+ gnused
+ btrfs-progs
+ ]
+ ++ optional syslogSupport util-linux
+ );
+
+ postFixup = ''
+ wrapProgram $out/bin/btrfs-auto-snapshot \
+ --prefix PATH : "${wrapperPath}"
+ '';
+
+ meta = with lib; {
+ description = "BTRFS Automatic Snapshot Service for Linux";
+ homepage = "https://github.com/hunleyd/btrfs-auto-snapshot";
+ license = licenses.gpl2;
+ mainProgram = "btrfs-auto-snapshot";
+ maintainers = with maintainers; [motiejus];
+ platforms = platforms.unix;
+
+ longDescription = ''
+ btrfs-auto-snapshot is a Bash script designed to bring as much of the
+ functionality of the wonderful ZFS snapshot tool zfs-auto-snapshot to
+ BTRFS as possible. Designed to run from cron (using
+ /etc/cron.{daily,hourly,weekly}) it automatically creates a snapshot of
+ the specified BTRFS filesystem (or, optionally, all of them) and then
+ automatically purges the oldest snapshots of that type (hourly, daily, et
+ al) based on a user-defined retention policy.
+
+ Snapshots are stored in a '.btrfs' directory at the root of the BTRFS
+ filesystem being snapped and are read-only by default.
+ '';
+ };
+ }