summaryrefslogtreecommitdiff
path: root/custom/btrfs-snapshots.nix
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 /custom/btrfs-snapshots.nix
parente5195df4dbb63f3f05c8f502970cdba41c8c5311 (diff)
downloadnixos-10537afaa7749e38fdb6a5e67be91afaabb47dc8.tar
nixos-10537afaa7749e38fdb6a5e67be91afaabb47dc8.tar.gz
nixos-10537afaa7749e38fdb6a5e67be91afaabb47dc8.tar.bz2
nixos-10537afaa7749e38fdb6a5e67be91afaabb47dc8.tar.xz
nixos-10537afaa7749e38fdb6a5e67be91afaabb47dc8.zip
btrfs-snapshots on hel
Diffstat (limited to 'custom/btrfs-snapshots.nix')
-rw-r--r--custom/btrfs-snapshots.nix52
1 files changed, 52 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}