summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-12-17 00:23:35 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2017-12-17 00:23:35 +0100
commit10537afaa7749e38fdb6a5e67be91afaabb47dc8 (patch)
treea9855c803d17ca88048cf865cefababce6281a76
parente5195df4dbb63f3f05c8f502970cdba41c8c5311 (diff)
downloadnixos-10537afaa7749e38fdb6a5e67be91afaabb47dc8.tar
nixos-10537afaa7749e38fdb6a5e67be91afaabb47dc8.tar.gz
nixos-10537afaa7749e38fdb6a5e67be91afaabb47dc8.tar.bz2
nixos-10537afaa7749e38fdb6a5e67be91afaabb47dc8.tar.xz
nixos-10537afaa7749e38fdb6a5e67be91afaabb47dc8.zip
btrfs-snapshots on hel
-rw-r--r--custom/btrfs-snapshots.nix52
-rw-r--r--hel.nix3
2 files changed, 55 insertions, 0 deletions
diff --git a/custom/btrfs-snapshots.nix b/custom/btrfs-snapshots.nix
new file mode 100644
index 00000000..7caf7a30
--- /dev/null
+++ b/custom/btrfs-snapshots.nix
@@ -0,0 +1,52 @@
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.btrfs-snapshots;
7
8 snapshotMount = str: "${cfg.mountPoint}/${cfg.mountPrefix}${str}"
9in {
10 options = {
11
12 services.btrfs-snapshots = {
13 enable = mkEnableOption "btrfs snapshot unit";
14
15 mountPoint = mkOption {
16 type = types.path;
17 default = "/mnt";
18 };
19
20 mountPrefix = mkOption {
21 type = types.str;
22 default = "snapshot-";
23 };
24
25 readOnly = mkOption {
26 type = types.bool;
27 default = true;
28 };
29 };
30
31 };
32
33
34 config = mkIf cfg.enable {
35
36 systemd.services."btrfs-snapshot@" = {
37 enable = true;
38 path = with pkgs; [btrfs-progs];
39
40 unitConfig = {
41 AssertPathIsDirectory = ${cfg.mountPoint};
42 };
43
44 serviceConfig = with pkgs; {
45 ExecStart = "${btrfs-progs}/bin/btrfs subvolume snapshot ${optionalString cfg.readOnly "-r"} %f ${snapshotMount "%i"}";
46 RemainAfterExit = true;
47 ExecStop = "${btrfs-progs}/bin/btrfs subvolume delete ${snapshotMount "%i"}";
48 };
49 };
50
51 };
52}
diff --git a/hel.nix b/hel.nix
index ba86b1e4..8e1462d9 100644
--- a/hel.nix
+++ b/hel.nix
@@ -14,6 +14,7 @@
14 ./custom/tinc/def.nix 14 ./custom/tinc/def.nix
15 ./custom/tinc/yggdrasil.nix 15 ./custom/tinc/yggdrasil.nix
16 ./custom/uucp.nix 16 ./custom/uucp.nix
17 ./custom/btrfs-snapshots.nix
17 ]; 18 ];
18 19
19 system.stateVersion = "16.09"; 20 system.stateVersion = "16.09";
@@ -515,5 +516,7 @@
515 systemd.targets."multi-user".wants = ["gpscfg.timer"]; 516 systemd.targets."multi-user".wants = ["gpscfg.timer"];
516 517
517 systemd.services."NetworkManager-wait-online".enable = true; 518 systemd.services."NetworkManager-wait-online".enable = true;
519
520 services.btrfs-snapshots.enable = true;
518} 521}
519 522