summaryrefslogtreecommitdiff
path: root/hosts/surtr/zfs.nix
blob: 17c5cd324d62cb6a0b918556ff48e37592dd366f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{ pkgs, config, ... }:
{
  config = {
    fileSystems = {
      "/nix" =
        { device = "surtr/local/nix";
          fsType = "zfs";
        };

      "/root" =
        { device = "surtr/safe/home-root";
          fsType = "zfs";
        };

      "/var/lib/systemd" =
        { device = "surtr/local/var-lib-systemd";
          fsType = "zfs";
          neededForBoot = true;
        };

      "/var/lib/nixos" =
        { device = "surtr/local/var-lib-nixos";
          fsType = "zfs";
          neededForBoot = true;
        };

      "/var/lib/sops-nix" =
        { device = "surtr/local/var-lib-sops--nix";
          fsType = "zfs";
          neededForBoot = true;
        };

      "/var/log" =
        { device = "surtr/local/var-log";
          fsType = "zfs";
        };

      "/home" =
        { device = "surtr/safe/home";
          fsType = "zfs";
        };

      # "/srv" =
      #   { device = "surtr/safe/srv";
      #     fsType = "zfs";
      #     options = [ "zfsutil" ];
      #   };
    };

    boot.postBootCommands = ''
      echo "=== STARTING ZPOOL IMPORT ==="
      ${pkgs.zfs}/bin/zpool import -a -N -d /dev
      ${pkgs.zfs}/bin/zpool status
      ${pkgs.zfs}/bin/zfs mount -a
      echo "=== ZPOOL IMPORT COMPLETE ==="
    '';

    system.activationScripts = {
      zfsMount.text = ''
        ${pkgs.zfs}/bin/zfs mount -a
      '';
    };

    services.zfssnap.enable = true;
    services.zfs.trim = {
      enable = true;
      interval = "Sun 16:00:00 Europe/Berlin";
    };
    services.zfs.autoScrub = {
      enable = true;
      interval = "Sun *-*-1..7 04:00:00 Europe/Berlin";
    };
    services.zfs.zed.settings = {
      ZED_SYSLOG_SUBCLASS_EXCLUDE = "history_event";
    };
  };
}