summaryrefslogtreecommitdiff
path: root/modules/nextcloud.nix
blob: f6f9d1acbc84d8b97aa6f61c4d9027112c7aa813 (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
{ config, lib, pkgs, ... }:
let
  cfg = config.orbekk.nextcloud;
in
{
  options = {
    orbekk.nextcloud = {
      enable = lib.mkEnableOption "Enable nextcloud server";
    };
  };

  config = lib.mkIf cfg.enable {
    services.nextcloud = {
      enable = true;
      package = pkgs.nextcloud21;
      hostName = "nextcloud.orbekk.com";
      config = {
        dbtype = "pgsql";
        dbuser = "nextcloud";
        dbhost = "/run/postgresql"; # nextcloud will add /.s.PGSQL.5432 by itself
        dbname = "nextcloud";
        adminpassFile = "/opt/secret/nextcloud/admin-pass-file";
        adminuser = "root";
      };
      autoUpdateApps.enable = true;
      https = true;
    };

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

    users.extraUsers.nextcloud.extraGroups = ["readonly"];

    systemd.services."nextcloud-setup" = {
      requires = ["postgresql.service"];
      after = ["postgresql.service"];
    };
  };
}