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