1args@{ pkgs, nextcloudVersion ? 22, ... }:
2
3(import ../make-test-python.nix ({ pkgs, ...}: let
4 adminpass = "hunter2";
5 adminuser = "custom-admin-username";
6in {
7 name = "nextcloud-with-postgresql-and-redis";
8 meta = with pkgs.lib.maintainers; {
9 maintainers = [ eqyiel ];
10 };
11
12 nodes = {
13 # The only thing the client needs to do is download a file.
14 client = { ... }: {};
15
16 nextcloud = { config, pkgs, ... }: {
17 networking.firewall.allowedTCPPorts = [ 80 ];
18
19 services.nextcloud = {
20 enable = true;
21 hostName = "nextcloud";
22 package = pkgs.${"nextcloud" + (toString nextcloudVersion)};
23 caching = {
24 apcu = false;
25 redis = true;
26 memcached = false;
27 };
28 config = {
29 dbtype = "pgsql";
30 dbname = "nextcloud";
31 dbuser = "nextcloud";
32 dbhost = "/run/postgresql";
33 inherit adminuser;
34 adminpassFile = toString (pkgs.writeText "admin-pass-file" ''
35 ${adminpass}
36 '');
37 };
38 };
39
40 services.redis.servers."nextcloud".enable = true;
41 services.redis.servers."nextcloud".port = 6379;
42
43 systemd.services.nextcloud-setup= {
44 requires = ["postgresql.service"];
45 after = [
46 "postgresql.service"
47 ];
48 };
49
50 services.postgresql = {
51 enable = true;
52 ensureDatabases = [ "nextcloud" ];
53 ensureUsers = [
54 { name = "nextcloud";
55 ensurePermissions."DATABASE nextcloud" = "ALL PRIVILEGES";
56 }
57 ];
58 };
59 };
60 };
61
62 testScript = let
63 configureRedis = pkgs.writeScript "configure-redis" ''
64 #!${pkgs.runtimeShell}
65 nextcloud-occ config:system:set redis 'host' --value 'localhost' --type string
66 nextcloud-occ config:system:set redis 'port' --value 6379 --type integer
67 nextcloud-occ config:system:set memcache.local --value '\OC\Memcache\Redis' --type string
68 nextcloud-occ config:system:set memcache.locking --value '\OC\Memcache\Redis' --type string
69 '';
70 withRcloneEnv = pkgs.writeScript "with-rclone-env" ''
71 #!${pkgs.runtimeShell}
72 export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav
73 export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/webdav/"
74 export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud"
75 export RCLONE_CONFIG_NEXTCLOUD_USER="${adminuser}"
76 export RCLONE_CONFIG_NEXTCLOUD_PASS="$(${pkgs.rclone}/bin/rclone obscure ${adminpass})"
77 "''${@}"
78 '';
79 copySharedFile = pkgs.writeScript "copy-shared-file" ''
80 #!${pkgs.runtimeShell}
81 echo 'hi' | ${pkgs.rclone}/bin/rclone rcat nextcloud:test-shared-file
82 '';
83
84 diffSharedFile = pkgs.writeScript "diff-shared-file" ''
85 #!${pkgs.runtimeShell}
86 diff <(echo 'hi') <(${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file)
87 '';
88 in ''
89 start_all()
90 nextcloud.wait_for_unit("multi-user.target")
91 nextcloud.succeed("${configureRedis}")
92 nextcloud.succeed("curl -sSf http://nextcloud/login")
93 nextcloud.succeed(
94 "${withRcloneEnv} ${copySharedFile}"
95 )
96 client.wait_for_unit("multi-user.target")
97 client.succeed(
98 "${withRcloneEnv} ${diffSharedFile}"
99 )
100 '';
101})) args