From c9d23c27ffb3a1b0e161d6b44cf28741ac1c195a Mon Sep 17 00:00:00 2001 From: NAHO <90870942+trueNAHO@users.noreply.github.com> Date: Wed, 21 Feb 2024 18:20:18 +0100 Subject: [PATCH] fix(modules/nixos/services/btrbk): ensure the snapshot directory exists --- hosts/bluetop/default.nix | 6 ++++- hosts/masterplan/default.nix | 6 ++++- modules/nixos/services/btrbk/default.nix | 33 +++++++++++++++++------- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/hosts/bluetop/default.nix b/hosts/bluetop/default.nix index 0f0649f..7f13e2f 100644 --- a/hosts/bluetop/default.nix +++ b/hosts/bluetop/default.nix @@ -68,7 +68,11 @@ repo = "/mnt/borgbackup"; }; - btrbk.enable = true; + btrbk = { + enable = true; + snapshotDir = "/nix/btrbk"; + }; + openssh.enable = true; }; diff --git a/hosts/masterplan/default.nix b/hosts/masterplan/default.nix index ebef7d6..b5f1339 100644 --- a/hosts/masterplan/default.nix +++ b/hosts/masterplan/default.nix @@ -69,7 +69,11 @@ repo = "/mnt/borgbackup"; }; - btrbk.enable = true; + btrbk = { + enable = true; + snapshotDir = "/nix/btrbk"; + }; + openssh.enable = true; }; diff --git a/modules/nixos/services/btrbk/default.nix b/modules/nixos/services/btrbk/default.nix index 7fc3912..009443b 100644 --- a/modules/nixos/services/btrbk/default.nix +++ b/modules/nixos/services/btrbk/default.nix @@ -3,18 +3,31 @@ lib, ... }: { - options.modules.nixos.services.btrbk.enable = lib.mkEnableOption "btrbk"; + options.modules.nixos.services.btrbk = { + enable = lib.mkEnableOption "btrbk"; - config = lib.mkIf config.modules.nixos.services.btrbk.enable { - services.btrbk.instances.home = { - onCalendar = "hourly"; + snapshotDir = lib.mkOption { + description = "Path to Btrbk's snapshot directory."; + example = "/nix/btrbk"; + type = lib.types.str; + }; + }; + + config = let + cfg = config.modules.nixos.services.btrbk; + in + lib.mkIf cfg.enable { + services.btrbk.instances.home = { + onCalendar = "hourly"; - settings = { - snapshot_dir = "/nix/btrbk"; - snapshot_preserve = "7d 5w"; - snapshot_preserve_min = "2d"; - subvolume = "/home"; + settings = { + snapshot_dir = cfg.snapshotDir; + snapshot_preserve = "7d 5w"; + snapshot_preserve_min = "2d"; + subvolume = "/home"; + }; }; + + systemd.tmpfiles.rules = ["d ${cfg.snapshotDir} 700"]; }; - }; }