aboutsummaryrefslogtreecommitdiffstats
path: root/hosts/arrakis/services.nix
blob: 385dbd0040c9c445c37dcf5319786277cd5db9fb (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
{ config, pkgs, ... }: {

  environment.etc."gitconfig".text = ''
    [safe]
    	directory = *
  '';

  networking.firewall.allowedTCPPorts = [ 2049 ];

  security.acme = {
    acceptTerms = true;
    certs."arrakis.bitgnome.net".postRun = ''
      ${pkgs.acl}/bin/setfacl -m u:postfix:--x /var/lib/acme/arrakis.bitgnome.net
      ${pkgs.acl}/bin/setfacl -m u:postfix:r-- /var/lib/acme/arrakis.bitgnome.net/{fullchain,key}.pem
      ${pkgs.systemd}/bin/systemctl reload postfix.service
    '';
    defaults.email = "nipsy@bitgnome.net";
  };

  services = {

    avahi = {
      enable = true;
      nssmdns4 = true;
      openFirewall = true;
    };

    cgit = {
      "arrakis.bitgnome.net" = {
        enable = true;
        nginx.location = "/nipsy/git/";
        scanPath = "/home/nipsy/www/git";
        settings = {
          about-filter = "${pkgs.cgit}/lib/cgit/filters/about-formatting.sh";
          branch-sort = "age";
          clone-url = "https://$HTTP_HOST$SCRIPT_NAME/$CGIT_REPO_URL";
          css = "/nipsy/git/cgit.css";
          enable-commit-graph = true;
          enable-follow-links = true;
          enable-git-config = true;
          enable-index-links = true;
          enable-log-filecount = true;
          enable-log-linecount = true;
          logo = "/nipsy/git/cgit.png";
          max-stats = "quarter";
          mimetype-file = "${pkgs.mailcap}/etc/mime.types";
          readme = ":README.md";
          remove-suffix = 1;
          root-desc= "Dune.  Desert planet.";
          root-title = "Spice Factory";
          snapshots = "all";
          source-filter = "${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py";
        };
      };
    };

    clamav.updater.enable = true;

    cron.enable = true;

    dictd.enable = true;

    iperf3.openFirewall = true;

    jellyfin = {
      enable = true;
      package = pkgs.master.jellyfin;
    };

    nfs = {
      server = {
        enable = true;
        exports = ''
          /srv/nfs	192.168.1.0/24(ro,all_squash,insecure,crossmnt,subtree_check,fsid=0)
        '';
      };
      settings = {
        nfsd = {
          udp = false;
          vers2 = false;
          vers3 = false;
          vers4 = true;
        };
      };
    };

    nginx = {
      enable = true;

      # Use recommended settings
      recommendedGzipSettings = true;
      recommendedOptimisation = true;
      #recommendedProxySettings = true;
      recommendedTlsSettings = true;

      # Only allow PFS-enabled ciphers with AES256
      sslCiphers = "AES256+EECDH:AES256+EDH:!aNULL";

      virtualHosts = {
        "arrakis.bitgnome.net" = {
          enableACME = true;
          forceSSL = true;
          locations = {
            "/" = {
              extraConfig = ''
                default_type text/html;
              '';
              return = "200 '<html><body>Hot damn, it works!</body></html>'";
            };
            "/jellyfin" = {
              return = "302 $scheme://$host/jellyfin/";
            };
            "/jellyfin/" = {
              extraConfig = ''
                proxy_pass_request_headers on;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Forwarded-Host $http_host;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection $http_connection;
                proxy_buffering off;

                # CORS setup
                add_header 'Access-Control-Allow-Origin' '*' always;
                add_header 'Access-Control-Expose-Headers' 'Content-Length';

                # Allow CORS preflight requests
                if ($request_method = 'OPTIONS') {
                	add_header 'Access-Control-Allow-Origin' '*';
                	add_header 'Access-Control-Max-Age' 1728000;
                	add_header 'Content-Type' 'text/plain charset=UTF-8';
                	add_header 'Content-Length' 0;
                	return 204;
                }
              '';
              proxyPass = "http://192.168.1.2:8096/jellyfin/";

            };
            "/nipsy" = {
              return = "302 $scheme://$host/nipsy/";
            };
            "/nipsy/" = {
              root = "/data/home/nipsy/www";
              tryFiles = "$uri =404";
            };
          };
        };
      };
    };

    postfix = let my_email = "nipsy@bitgnome.net"; in {
      enable = true;
      extraAliases = ''
        nipsy: ${my_email}
      '';
      hostname = "${config.networking.hostName}.${config.networking.domain}";
      relayHost = "mail.bitgnome.net";
      relayPort = 587;
      rootAlias = my_email;
      sslCert = "/var/lib/acme/arrakis.bitgnome.net/fullchain.pem";
      sslKey = "/var/lib/acme/arrakis.bitgnome.net/key.pem";
    };

    printing.enable = true;

    sabnzbd = {
      enable = true;
      user = "nipsy";
      group = "nipsy";
      configFile = "/home/nipsy/.sabnzbd/sabnzbd.ini";
    };

    samba = {
      enable = true;
      settings = {
        global = {
          "invalid users" = [
            "root"
          ];
          "passwd program" = "/run/wrappers/bin/passwd %u";
          security = "user";
          "smb1 unix extensions" = "no";
        };
        homes = {
          browseable = "no";
          "create mask" = "0775";
          "directory mask" = "0775";
          "read only" = "no";
          "valid users" = "%S";
          "wide links" = "yes";
        };
        nipsy-ro = {
          browseable = "no";
          path = "/home/nipsy";
          "read only" = "yes";
          "valid users" = "nipsy";
          "wide links" = "yes";
        };
      };
    };

    smartd = let my_email_addr = "nipsy@bitgnome.net"; in {
      enable = true;
      devices = [
        {
          device = "/dev/disk/by-id/nvme-WD_BLACK_SN850X_4000GB_23162P800005";
          options = "-a -o on -S on -m ${my_email_addr}";
        }
        {
          device = "/dev/disk/by-id/nvme-WD_BLACK_SN850X_4000GB_23162P800014";
          options = "-a -o on -S on -m ${my_email_addr}";
        }
        {
          device = "/dev/disk/by-id/ata-WDC_WD80EFAX-68KNBN0_VAHUEZNL";
          options = "-a -o on -S on -s (S/../.././02|L/../../5/03) -m ${my_email_addr}";
        }
        {
          device = "/dev/disk/by-id/ata-WDC_WD80EFAX-68KNBN0_VAHUUSXL";
          options = "-a -o on -S on -s (S/../.././02|L/../../5/03) -m ${my_email_addr}";
        }
        {
          device = "/dev/disk/by-id/ata-WDC_WD80EFAX-68KNBN0_VAHV0H5L";
          options = "-a -o on -S on -s (S/../.././02|L/../../5/03) -m ${my_email_addr}";
        }
        {
          device = "/dev/disk/by-id/ata-WDC_WD80EFAX-68KNBN0_VAHUK5EL";
          options = "-a -o on -S on -s (S/../.././02|L/../../5/03) -m ${my_email_addr}";
        }
        {
          device = "/dev/disk/by-id/ata-WDC_WD80EFAX-68KNBN0_VAHV5JEL";
          options = "-a -o on -S on -s (S/../.././02|L/../../5/03) -m ${my_email_addr}";
        }
        {
          device = "/dev/disk/by-id/ata-WDC_WD80EFAX-68KNBN0_VAHUZ42L";
          options = "-a -o on -S on -s (S/../.././02|L/../../5/03) -m ${my_email_addr}";
        }
        {
          device = "/dev/disk/by-id/ata-WDC_WD80EFAX-68KNBN0_VAHV3BSL";
          options = "-a -o on -S on -s (S/../.././02|L/../../5/03) -m ${my_email_addr}";
        }
        {
          device = "/dev/disk/by-id/ata-WDC_WD80EFAX-68KNBN0_VAHV338L";
          options = "-a -o on -S on -s (S/../.././02|L/../../5/03) -m ${my_email_addr}";
        }
      ];
    };

  };

}