summaryrefslogtreecommitdiff
path: root/modules/nixos/nas.nix
blob: 6201160e372328c00c0ff306a1739c7e5a84eb3c (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
{ config, pkgs, lib, ... }:

{
  options = {
    client.nas.enable = lib.mkEnableOption "enables nas";
  };

  config = lib.mkIf config.client.nas.enable {
    services.tailscale.enable = true;
    services.tailscale.useRoutingFeatures = "client";
    services.tailscale.openFirewall = true;
    services.tailscale.extraUpFlags = [ "--accept-dns=false" ];
    networking.nftables.enable = true;
    networking.firewall = {
      enable = true;
      trustedInterfaces = [ "tailscale0" ];
      allowedUDPPorts = [ config.services.tailscale.port ];
    };

    networking.nftables = {
      tables = {
        mullvad_tailscale = {
          content = ''
            chain output {
              type route hook output priority 0; policy accept;
              ip daddr 100.64.0.0/10 ct mark set 0x00000f41 meta mark set 0x6d6f6c65;
            }
          '';
          family = "inet";
        };
      };
    };

    systemd.services.tailscaled.serviceConfig.Environment = [ 
      "TS_DEBUG_FIREWALL_MODE=nftables" 
    ];

    systemd.network.wait-online.enable = false; 
    boot.initrd.systemd.network.wait-online.enable = false;

    boot.supportedFilesystems = [ "nfs" ];

    environment.systemPackages = with pkgs; [
      nfs-utils
    ];

    fileSystems."/mnt/data" = {
      device = "100.106.156.106:/tank/data";
      fsType = "nfs4";

      options = [
        "x-systemd.automount"
        "noauto"
        "nofail"
        "_netdev"

        "hard"
        "noatime"

        "x-systemd.mount-timeout=10"
        "x-systemd.idle-timeout=600"
      ];
    };

    fileSystems."/mnt/backups" = {
      device = "100.106.156.106:/tank/backups";
      fsType = "nfs4";

      options = [
        "x-systemd.automount"
        "noauto"
        "nofail"
        "_netdev"

        "hard"
        "noatime"

        "x-systemd.mount-timeout=10"
        "x-systemd.idle-timeout=600"
      ];
    };

    fileSystems."/mnt/media" = {
      device = "100.106.156.106:/tank/media";
      fsType = "nfs4";

      options = [
        "x-systemd.automount"
        "noauto"
        "nofail"
        "_netdev"

        "hard"
        "noatime"

        "x-systemd.mount-timeout=10"
        "x-systemd.idle-timeout=600"
      ];
    };
  };
}