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 = {
41 enable = true;
42 };
43
44 systemd.services.nextcloud-setup= {
45 requires = ["postgresql.service"];
46 after = [
47 "postgresql.service"
48 ];
49 };
50
51 services.postgresql = {
52 enable = true;
53 ensureDatabases = [ "nextcloud" ];
54 ensureUsers = [
55 { name = "nextcloud";
56 ensurePermissions."DATABASE nextcloud" = "ALL PRIVILEGES";
57 }
58 ];
59 };
60 };
61 };
62
63 testScript = let
64 configureRedis = pkgs.writeScript "configure-redis" ''
65 #!${pkgs.runtimeShell}
66 nextcloud-occ config:system:set redis 'host' --value 'localhost' --type string
67 nextcloud-occ config:system:set redis 'port' --value 6379 --type integer
68 nextcloud-occ config:system:set memcache.local --value '\OC\Memcache\Redis' --type string
69 nextcloud-occ config:system:set memcache.locking --value '\OC\Memcache\Redis' --type string
70 '';
71 withRcloneEnv = pkgs.writeScript "with-rclone-env" ''
72 #!${pkgs.runtimeShell}
73 export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav
74 export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/webdav/"
75 export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud"
76 export RCLONE_CONFIG_NEXTCLOUD_USER="${adminuser}"
77 export RCLONE_CONFIG_NEXTCLOUD_PASS="$(${pkgs.rclone}/bin/rclone obscure ${adminpass})"
78 "''${@}"
79 '';
80 copySharedFile = pkgs.writeScript "copy-shared-file" ''
81 #!${pkgs.runtimeShell}
82 echo 'hi' | ${pkgs.rclone}/bin/rclone rcat nextcloud:test-shared-file
83 '';
84
85 diffSharedFile = pkgs.writeScript "diff-shared-file" ''
86 #!${pkgs.runtimeShell}
87 diff <(echo 'hi') <(${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file)
88 '';
89 in ''
90 start_all()
91 nextcloud.wait_for_unit("multi-user.target")
92 nextcloud.succeed("${configureRedis}")
93 nextcloud.succeed("curl -sSf http://nextcloud/login")
94 nextcloud.succeed(
95 "${withRcloneEnv} ${copySharedFile}"
96 )
97 client.wait_for_unit("multi-user.target")
98 client.succeed(
99 "${withRcloneEnv} ${diffSharedFile}"
100 )
101 '';
102})) args