Skip to content

Commit

Permalink
fix(modules/nixos/services/btrbk): ensure the snapshot directory exists
Browse files Browse the repository at this point in the history
  • Loading branch information
trueNAHO committed Feb 21, 2024
1 parent 3bbb5c2 commit c9d23c2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
6 changes: 5 additions & 1 deletion hosts/bluetop/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@
repo = "/mnt/borgbackup";
};

btrbk.enable = true;
btrbk = {
enable = true;
snapshotDir = "/nix/btrbk";
};

openssh.enable = true;
};

Expand Down
6 changes: 5 additions & 1 deletion hosts/masterplan/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@
repo = "/mnt/borgbackup";
};

btrbk.enable = true;
btrbk = {
enable = true;
snapshotDir = "/nix/btrbk";
};

openssh.enable = true;
};

Expand Down
33 changes: 23 additions & 10 deletions modules/nixos/services/btrbk/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
};
};
}

0 comments on commit c9d23c2

Please sign in to comment.