summaryrefslogtreecommitdiff
path: root/custom
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2018-04-09 13:35:37 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2018-04-09 13:35:37 +0200
commit05393c477a2ec1bfc0ed8c6a4f8a80066f5ec81d (patch)
treed3895f51a8d9e7dc08ac2947ce4a1c64a452ef59 /custom
parentbb87c21224a1aad29b52267d3be710aac87871d1 (diff)
downloadnixos-05393c477a2ec1bfc0ed8c6a4f8a80066f5ec81d.tar
nixos-05393c477a2ec1bfc0ed8c6a4f8a80066f5ec81d.tar.gz
nixos-05393c477a2ec1bfc0ed8c6a4f8a80066f5ec81d.tar.bz2
nixos-05393c477a2ec1bfc0ed8c6a4f8a80066f5ec81d.tar.xz
nixos-05393c477a2ec1bfc0ed8c6a4f8a80066f5ec81d.zip
borg on odin
Diffstat (limited to 'custom')
-rw-r--r--custom/borgbackup.nix30
-rw-r--r--custom/lvm-snapshots.nix1
2 files changed, 26 insertions, 5 deletions
diff --git a/custom/borgbackup.nix b/custom/borgbackup.nix
index 91de89a5..77e7637a 100644
--- a/custom/borgbackup.nix
+++ b/custom/borgbackup.nix
@@ -5,6 +5,21 @@ with lib;
5let 5let
6 cfg = config.services.borgbackup; 6 cfg = config.services.borgbackup;
7 7
8 lvmPath = {
9 options = {
10 LV = mkOption {
11 type = types.str;
12 };
13 VG = mkOption {
14 type = types.str;
15 };
16 };
17 };
18
19 pathType = if cfg.snapshots == "lvm" then types.submodule lvmPath else types.path;
20
21 systemdPath = path: if cfg.snapshots == "lvm" then escapeSystemdPath "${path.VG}/${path.LV}" else escapeSystemdPath path;
22
8 targetOptions = { 23 targetOptions = {
9 options = { 24 options = {
10 repo = mkOption { 25 repo = mkOption {
@@ -12,7 +27,7 @@ let
12 }; 27 };
13 28
14 paths = mkOption { 29 paths = mkOption {
15 type = types.listOf types.str; 30 type = types.listOf pathType;
16 default = []; 31 default = [];
17 }; 32 };
18 33
@@ -46,7 +61,7 @@ in {
46 options = { 61 options = {
47 services.borgbackup = { 62 services.borgbackup = {
48 snapshots = mkOption { 63 snapshots = mkOption {
49 type = types.nullOr (types.enum ["btrfs"]); 64 type = types.nullOr (types.enum ["btrfs" "lvm"]);
50 default = null; 65 default = null;
51 }; 66 };
52 67
@@ -63,8 +78,13 @@ in {
63 78
64 config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) { 79 config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) {
65 services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true; 80 services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true;
81
82 services.lvm-snapshots = mkIf (cfg.snapshots == "lvm") (listToAttrs (map (path: nameValuePair (systemdPath path) {
83 inherit (path) LV VG;
84 mountName = "snapshot-${systemdPath path}";
85 }) (unique (flatten (mapAttrsToList (target: tCfg: tCfg.paths) cfg.targets)))));
66 86
67 systemd.timers = (listToAttrs (map ({ target, path, tCfg }: nameValuePair "borgbackup-${target}@${path}" { 87 systemd.timers = (listToAttrs (map ({ target, path, tCfg }: nameValuePair "borgbackup-${target}@${systemdPath path}" {
68 wantedBy = [ "timers.target" ]; 88 wantedBy = [ "timers.target" ];
69 89
70 timerConfig = { 90 timerConfig = {
@@ -102,7 +122,7 @@ in {
102 --filter 'AME' \ 122 --filter 'AME' \
103 --exclude-caches \ 123 --exclude-caches \
104 --keep-exclude-tags \ 124 --keep-exclude-tags \
105 --patterns-from .backup \ 125 --patterns-from .backup-${target} \
106 --one-file-system \ 126 --one-file-system \
107 --compression auto,lzma \ 127 --compression auto,lzma \
108 ${tCfg.repo}::${cfg.prefix}$1-{utcnow} 128 ${tCfg.repo}::${cfg.prefix}$1-{utcnow}
@@ -133,7 +153,7 @@ in {
133 --lock-wait ${toString tCfg.lockWait} \ 153 --lock-wait ${toString tCfg.lockWait} \
134 --list \ 154 --list \
135 --stats \ 155 --stats \
136 --prefix "${cfg.prefix}${path}" \ 156 --prefix "${cfg.prefix}${escapeSystemdPath path}" \
137 ${concatStringsSep " " args} \ 157 ${concatStringsSep " " args} \
138 ${tCfg.repo} 158 ${tCfg.repo}
139 '') tCfg.prune); 159 '') tCfg.prune);
diff --git a/custom/lvm-snapshots.nix b/custom/lvm-snapshots.nix
index 159fe98b..ea69e1ff 100644
--- a/custom/lvm-snapshots.nix
+++ b/custom/lvm-snapshots.nix
@@ -50,6 +50,7 @@ in {
50 50
51 mountPoint = mkOption { 51 mountPoint = mkOption {
52 type = types.path; 52 type = types.path;
53 readOnly = true;
53 default = "/mnt"; 54 default = "/mnt";
54 }; 55 };
55 }; 56 };