summaryrefslogtreecommitdiff
path: root/hosts/vidhar/zfs.nix
blob: 3a258961de423fd2535507ee71d8623d64e7649f (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
{ pkgs, lib, config, ... }:
{
  config = {
    fileSystems = {
      "/boot" =
        { device = "boot";
          fsType = "zfs";
        };

      "/nix" =
        { device = "ssd-raid0/local/nix";
          fsType = "zfs";
        };

      "/root" =
        { device = "ssd-raid1/safe/home-root";
          fsType = "zfs";
          neededForBoot = true;
        };

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

      "/var/lib/unbound" =
        { device = "ssd-raid1/local/var-lib-unbound";
          fsType = "zfs";
        };
      
      # "/var/lib/dhcp" =
      #   { device = "ssd-raid1/local/var-lib-dhcp";
      #     fsType = "zfs";
      #   };
      
      "/var/lib/chrony" =
        { device = "ssd-raid1/local/var-lib-chrony";
          fsType = "zfs";
        };
      
      "/var/lib/samba" =
        { device = "ssd-raid1/local/var-lib-samba";
          fsType = "zfs";
        };
      
      # "/var/lib/prometheus2" =
      #   { device = "ssd-raid1/local/var-lib-prometheus2";
      #     fsType = "zfs";
      #     options = [ "zfsutil" ];
      #   };

      # "/var/lib/grafana" =
      #   { device = "ssd-raid1/local/var-lib-grafana";
      #     fsType = "zfs";
      #     options = [ "zfsutil" ];
      #   };

      # "/var/lib/loki" =
      #   { device = "ssd-raid1/local/var-lib-loki";
      #     fsType = "zfs";
      #     options = [ "zfsutil" ];
      #   };
      
      # "/srv/tftp" =
      #   { device = "ssd-raid1/local/srv-tftp";
      #     fsType = "zfs";
      #     options = [ "zfsutil" ];
      #   };

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

      # "/home" =
      #   { device = "hdd-raid6/safe/home";
      #     fsType = "zfs";
      #     options = [ "zfsutil" ];
      #   };

      # "/home/gkleen" =
      #   { device = "hdd-raid6/safe/home/gkleen";
      #     fsType = "zfs";
      #     options = [ "zfsutil" ];
      #   };

      # "/home/mherold" =
      #   { device = "hdd-raid6/safe/home/mherold";
      #     fsType = "zfs";
      #     options = [ "zfsutil" ];
      #   };
    };

    users.users.gkleen.createHome = lib.mkForce false;
    users.users.mherold.createHome = lib.mkForce false;

    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 ==="
    '';

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