summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--custom/borgbackup.nix19
-rw-r--r--custom/btrfs-snapshots.nix23
-rw-r--r--custom/lvm-snapshots.nix7
-rw-r--r--sif.nix18
m---------utils0
5 files changed, 33 insertions, 34 deletions
diff --git a/custom/borgbackup.nix b/custom/borgbackup.nix
index 3871af0a..b292f6f2 100644
--- a/custom/borgbackup.nix
+++ b/custom/borgbackup.nix
@@ -21,9 +21,9 @@ let
21 21
22 systemdPath = path: escapeSystemdPath (if cfg.snapshots == "lvm" then "${path.VG}-${path.LV}" else path); 22 systemdPath = path: escapeSystemdPath (if cfg.snapshots == "lvm" then "${path.VG}-${path.LV}" else path);
23 23
24 withPrefix = path: config.services.btrfs-snapshots.mountPrefix + path; 24 withSuffix = path: path + (if cfg.snapshots == "btrfs" then config.services.btrfs-snapshots.mountSuffix else config.services.lvm-snapshots.mountSuffix);
25 25
26 mountPoint = if cfg.snapshots == "lvm" then config.services.lvm-snapshots.mountPoint else config.services.btrfs-snapshots.mountPoint; 26 mountPoint = if cfg.snapshots == "lvm" then config.services.lvm-snapshots.mountPoint else "";
27 27
28 targetOptions = { 28 targetOptions = {
29 options = { 29 options = {
@@ -86,18 +86,17 @@ in {
86 }; 86 };
87 }; 87 };
88 88
89 imports = [ 89 imports =
90 ./lvm-snapshots.nix 90 [ ./lvm-snapshots.nix
91 ./btrfs-snapshots.nix 91 ./btrfs-snapshots.nix
92 ]; 92 ];
93 93
94 config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) { 94 config = mkIf (any (t: t.paths != []) (attrValues cfg.targets)) {
95
96 services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true; 95 services.btrfs-snapshots.enable = mkIf (cfg.snapshots == "btrfs") true;
97 96
98 services.lvm-snapshots.snapshots = mkIf (cfg.snapshots == "lvm") (listToAttrs (map (path: nameValuePair (path.VG + "-" + path.LV) { 97 services.lvm-snapshots.snapshots = mkIf (cfg.snapshots == "lvm") (listToAttrs (map (path: nameValuePair (path.VG + "-" + path.LV) {
99 inherit (path) LV VG; 98 inherit (path) LV VG;
100 mountName = withPrefix (path.VG + "-" + path.LV); 99 mountName = withSuffix (path.VG + "-" + path.LV);
101 }) (unique (flatten (mapAttrsToList (target: tCfg: tCfg.paths) cfg.targets))))); 100 }) (unique (flatten (mapAttrsToList (target: tCfg: tCfg.paths) cfg.targets)))));
102 101
103 systemd.targets."timers-borg" = { 102 systemd.targets."timers-borg" = {
@@ -159,12 +158,12 @@ in {
159 unitConfig = { 158 unitConfig = {
160 AssertPathIsDirectory = mkIf (tCfg.lock != null) "/var/lock"; 159 AssertPathIsDirectory = mkIf (tCfg.lock != null) "/var/lock";
161 DefaultDependencies = false; 160 DefaultDependencies = false;
162 RequiresMountsFor = mkIf (cfg.snapshots == "lvm") [ "${mountPoint}/${withPrefix "%I"}" ]; 161 RequiresMountsFor = mkIf (cfg.snapshots == "lvm") [ "${mountPoint}/${withSuffix "%I"}" ];
163 }; 162 };
164 163
165 serviceConfig = { 164 serviceConfig = {
166 Type = "oneshot"; 165 Type = "oneshot";
167 WorkingDirectory = if (cfg.snapshots == null) then "%I" else (if (cfg.snapshots == "lvm") then "${mountPoint}/${withPrefix "%I"}" else "${mountPoint}/${withPrefix "%i"}"); 166 WorkingDirectory = if (cfg.snapshots == null) then "%I" else (if (cfg.snapshots == "lvm") then "${withSuffix "%I"}" else "${withSuffix "%f"}");
168 Nice = 15; 167 Nice = 15;
169 IOSchedulingClass = 2; 168 IOSchedulingClass = 2;
170 IOSchedulingPriority = 7; 169 IOSchedulingPriority = 7;
diff --git a/custom/btrfs-snapshots.nix b/custom/btrfs-snapshots.nix
index 39e0bf0c..96d2b2ba 100644
--- a/custom/btrfs-snapshots.nix
+++ b/custom/btrfs-snapshots.nix
@@ -5,21 +5,16 @@ with lib;
5let 5let
6 cfg = config.services.btrfs-snapshots; 6 cfg = config.services.btrfs-snapshots;
7 7
8 snapshotMount = str: "${cfg.mountPoint}/${cfg.mountPrefix}${str}"; 8 snapshotMount = str: "${str}${cfg.mountSuffix}";
9in { 9in {
10 options = { 10 options = {
11 11
12 services.btrfs-snapshots = { 12 services.btrfs-snapshots = {
13 enable = mkEnableOption "a systemd unit for btrfs snapshots"; 13 enable = mkEnableOption "a systemd unit for btrfs snapshots";
14 14
15 mountPoint = mkOption { 15 mountSuffix = mkOption {
16 type = types.path;
17 default = "/mnt";
18 };
19
20 mountPrefix = mkOption {
21 type = types.str; 16 type = types.str;
22 default = "snapshot-"; 17 default = ".snapshot";
23 }; 18 };
24 19
25 readOnly = mkOption { 20 readOnly = mkOption {
@@ -37,25 +32,19 @@ in {
37 32
38 33
39 config = mkIf cfg.enable { 34 config = mkIf cfg.enable {
40
41 system.activationScripts."btrfs-snapshots" = ''
42 mkdir -p ${cfg.mountPoint}
43 '';
44
45 systemd.services."btrfs-snapshot@" = { 35 systemd.services."btrfs-snapshot@" = {
46 enable = true; 36 enable = true;
47 37
48 unitConfig = { 38 unitConfig = {
49 AssertPathIsDirectory = cfg.mountPoint;
50 StopWhenUnneeded = !cfg.persist; 39 StopWhenUnneeded = !cfg.persist;
51 }; 40 };
52 41
53 serviceConfig = with pkgs; { 42 serviceConfig = with pkgs; {
54 Type = "oneshot"; 43 Type = "oneshot";
55 ExecStartPre = "-${btrfs-progs}/bin/btrfs subvolume delete -c ${snapshotMount "%i"}"; 44 ExecStartPre = "-${btrfs-progs}/bin/btrfs subvolume delete -c ${snapshotMount "%f"}";
56 ExecStart = "${btrfs-progs}/bin/btrfs subvolume snapshot ${optionalString cfg.readOnly "-r"} %f ${snapshotMount "%i"}"; 45 ExecStart = "${btrfs-progs}/bin/btrfs subvolume snapshot ${optionalString cfg.readOnly "-r"} %f ${snapshotMount "%f"}";
57 RemainAfterExit = true; 46 RemainAfterExit = true;
58 ExecStop = "${btrfs-progs}/bin/btrfs subvolume delete -c ${snapshotMount "%i"}"; 47 ExecStop = "${btrfs-progs}/bin/btrfs subvolume delete -c ${snapshotMount "%f"}";
59 }; 48 };
60 }; 49 };
61 50
diff --git a/custom/lvm-snapshots.nix b/custom/lvm-snapshots.nix
index 98c64330..13cbf421 100644
--- a/custom/lvm-snapshots.nix
+++ b/custom/lvm-snapshots.nix
@@ -7,7 +7,7 @@ let
7 cfg = config.services.lvm-snapshots; 7 cfg = config.services.lvm-snapshots;
8 8
9 snapshotMount = name: "${cfg.mountPoint}/${if isNull cfg.snapshots."${name}".mountName then name else cfg.snapshots."${name}".mountName}"; 9 snapshotMount = name: "${cfg.mountPoint}/${if isNull cfg.snapshots."${name}".mountName then name else cfg.snapshots."${name}".mountName}";
10 snapshotName = name: "${name}-snapshot"; 10 snapshotName = name: "${name}-${cfg.mountSuffix}";
11 11
12 snapshotConfig = { 12 snapshotConfig = {
13 options = { 13 options = {
@@ -53,6 +53,11 @@ in {
53 type = types.path; 53 type = types.path;
54 default = "/mnt"; 54 default = "/mnt";
55 }; 55 };
56
57 mountSuffix = mkOption {
58 type = types.str;
59 default = "-snapshot";
60 };
56 }; 61 };
57 }; 62 };
58 63
diff --git a/sif.nix b/sif.nix
index 80018442..36afeca2 100644
--- a/sif.nix
+++ b/sif.nix
@@ -97,6 +97,8 @@
97 libinput.enable = true; 97 libinput.enable = true;
98 98
99 dpi = 282; 99 dpi = 282;
100
101 videoDrivers = [ "intel" "nvidia" ];
100 }; 102 };
101 103
102 yggdrasilTinc = { 104 yggdrasilTinc = {
@@ -293,10 +295,14 @@
293 295
294 brightnessctl.enable = true; 296 brightnessctl.enable = true;
295 297
296 bumblebee = { 298 nvidia = {
297 enable = true; 299 modesetting.enable = true;
298 group = "video"; 300
299 connectDisplay = true; 301 optimus_prime = {
302 enable = true;
303 nvidiaBusId = "PCI:1:0:0";
304 intelBusId = "PCI:0:2:0";
305 };
300 }; 306 };
301 }; 307 };
302 308
@@ -349,12 +355,12 @@
349 ''; 355 '';
350 356
351 services.borgbackup = { 357 services.borgbackup = {
352 snapshots = "lvm"; 358 snapshots = "btrfs";
353 prefix = "yggdrasil.midgard.sif."; 359 prefix = "yggdrasil.midgard.sif.";
354 targets = { 360 targets = {
355 "munin" = { 361 "munin" = {
356 repo = "borg.munin:borg"; 362 repo = "borg.munin:borg";
357 paths = [ { VG = "nvm"; LV = "home"; } ]; 363 paths = [ "/home/gkleen" ];
358 prune = { 364 prune = {
359 "home" = 365 "home" =
360 [ "--keep-within" "24H" 366 [ "--keep-within" "24H"
diff --git a/utils b/utils
Subproject a7f511e7c9e8099db097d58c4fa6775766850c5 Subproject f55aa62c7dd25d44b37985ef5f109eb8212f5ae