aboutsummaryrefslogtreecommitdiff
path: root/nixops/modules/websites/tools/cloud/default.nix
blob: 5c3e9a8e7cb8cf2b7ce7c2c06c039235af6582f7 (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
{ lib, pkgs, config, myconfig, mylibs, ... }:
let
    nextcloud = pkgs.callPackage ./nextcloud.nix {
      env = myconfig.env.tools.nextcloud;
    };

    cfg = config.services.myWebsites.tools.cloud;
in {
  options.services.myWebsites.tools.cloud = {
    enable = lib.mkEnableOption "enable cloud website";
  };

  config = lib.mkIf cfg.enable {
    security.acme.certs."eldiron".extraDomains."cloud.immae.eu" = null;

    services.myWebsites.tools.modules = nextcloud.apache.modules;

    services.myWebsites.tools.vhostConfs.cloud = {
      certName    = "eldiron";
      hosts       = ["cloud.immae.eu" ];
      root        = nextcloud.apache.root;
      extraConfig = [
        nextcloud.apache.vhostConf
      ];
    };

    mySecrets.keys = nextcloud.keys;
    users.users.root.packages = let
      occ = pkgs.writeScriptBin "nextcloud-occ" ''
        #! ${pkgs.stdenv.shell}
        cd ${nextcloud.webRoot}
        NEXTCLOUD_CONFIG_DIR="${nextcloud.webRoot}/config" \
          exec \
          sudo -u wwwrun ${pkgs.php}/bin/php \
          -c ${pkgs.php}/etc/php.ini \
          occ $*
        '';
    in [ occ ];

    system.activationScripts.nextcloud = nextcloud.activationScript;
    system.extraSystemBuilderCmds = ''
      mkdir -p $out/webapps
      ln -s ${nextcloud.webRoot} $out/webapps/${nextcloud.apache.webappName}
      '';

    services.myPhpfpm = {
      poolPhpConfigs.nextcloud = nextcloud.phpFpm.phpConfig;
      poolConfigs.nextcloud = nextcloud.phpFpm.pool;
    };

    services.cron = {
      enable = true;
      systemCronJobs = [
        ''
          LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive
          */15 * * * * wwwrun ${pkgs.php}/bin/php -f ${nextcloud.webRoot}/cron.php
        ''
      ];
    };
  };
}