aboutsummaryrefslogtreecommitdiff
path: root/configuration.nix
blob: fad53054684a62886b9adedf55dc5f249810dba4 (plain) (blame)
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
{ config, pkgs, ... }:

let
  privateConfiguration = import ./private-configuration.nix;
  derivedConfiguration = import ./derived-configuration.nix;
in {
  imports = [ ./hardware-configuration.nix];

  boot.loader.grub = {
    enable = true;
    version = 2;
    device = "/dev/vda";
  };

  networking = {
    useDHCP = false;
    interfaces.ens3.useDHCP = true;
  };

  environment.systemPackages = with pkgs; [
    vim
  ];

  networking.firewall.allowedTCPPorts = [ 80 443 22 ];

  security.acme = {
    acceptTerms = true;
    email = privateConfiguration.letsencryptEmail;
  };

  services = {
    openssh = {
      enable = true;
      permitRootLogin = "no";
      passwordAuthentication = false;
    };

    nginx = {
      enable = true;
      recommendedGzipSettings = true;
      recommendedOptimisation = true;
      recommendedProxySettings = true;
      recommendedTlsSettings = true;
      sslCiphers = "AES256+EECDH:AES256+EDH:!aNULL"; # FIXME: ?????
      virtualHosts = let
        customConfigTLDs = {};
        defaultConfigTLDs = [
          derivedConfiguration.nextcloudTLD
          derivedConfiguration.gitTLD
        ];
        buildDefaultConfiguration = tld:
          {
            "${tld}" = {
              forceSSL = true;
              enableACME = true;
            };
          };
      in
        pkgs.lib.fold
          (tldString: acc: acc // buildDefaultConfiguration tldString)
          customConfigTLDs
          defaultConfigTLDs;

      gitweb = {
        enable = true;
        location = "/";
        virtualHost = derivedConfiguration.gitTLD;
      };
    };

    nextcloud = {
      enable = true;
      hostName = derivedConfiguration.nextcloudTLD;
      nginx.enable = true;
      https = true;
      autoUpdateApps.enable = true;
      autoUpdateApps.startAt = "05:00:00";
      config = {
        overwriteProtocol = "https";

        dbtype = "pgsql";
        dbuser = "nextcloud";
        dbhost = "/run/postgresql"; # nextcloud will add /.s.PGSQL.5432 by itself
        dbname = "nextcloud";
        dbpassFile = "/var/nextcloud-db-pass";

        adminpassFile = "/var/nextcloud-admin-pass";
        adminuser = "admin";
      };
    };

    postgresql = {
      enable = true;
      ensureDatabases = [ "nextcloud" ];
      ensureUsers = [
        {
          name = "nextcloud";
          ensurePermissions."DATABASE nextcloud" = "ALL PRIVILEGES";
        }
      ];
    };

    gitweb = {
      gitwebTheme = true;
      projectroot = "/srv/git";
    };
  };

  # FIXME: is this required?
  systemd.services."nextcloud-setup" = {
    requires = ["postgresql.service"];
    after = ["postgresql.service"];
  };

  users.users.nixos = {
    uid = 1000;
    extraGroups = ["wheel"];
    useDefaultShell = true;
    # FIXME: password hash file?
    openssh.authorizedKeys.keyFiles = [ "/etc/nixos/nixos-user-authorized-key"];
  };

  system.stateVersion = "19.09";
}