1import ../make-test-python.nix ({ pkgs, ...}: let
2 adminpass = "hunter2";
3 adminuser = "root";
4in {
5 name = "nextcloud-with-mysql-and-memcached";
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 https = true;
21 caching = {
22 apcu = true;
23 redis = false;
24 memcached = true;
25 };
26 config = {
27 dbtype = "mysql";
28 dbname = "nextcloud";
29 dbuser = "nextcloud";
30 dbhost = "127.0.0.1";
31 dbport = 3306;
32 dbpass = "hunter2";
33 # Don't inherit adminuser since "root" is supposed to be the default
34 inherit adminpass;
35 };
36 };
37
38 services.mysql = {
39 enable = true;
40 bind = "127.0.0.1";
41 package = pkgs.mariadb;
42 initialScript = pkgs.writeText "mysql-init" ''
43 CREATE USER 'nextcloud'@'localhost' IDENTIFIED BY 'hunter2';
44 CREATE DATABASE IF NOT EXISTS nextcloud;
45 GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER,
46 CREATE TEMPORARY TABLES ON nextcloud.* TO 'nextcloud'@'localhost'
47 IDENTIFIED BY 'hunter2';
48 FLUSH privileges;
49 '';
50 };
51
52 systemd.services.nextcloud-setup= {
53 requires = ["mysql.service"];
54 after = ["mysql.service"];
55 };
56
57 services.memcached.enable = true;
58 };
59 };
60
61 testScript = let
62 configureMemcached = pkgs.writeScript "configure-memcached" ''
63 #!${pkgs.runtimeShell}
64 nextcloud-occ config:system:set memcached_servers 0 0 --value 127.0.0.1 --type string
65 nextcloud-occ config:system:set memcached_servers 0 1 --value 11211 --type integer
66 nextcloud-occ config:system:set memcache.local --value '\OC\Memcache\APCu' --type string
67 nextcloud-occ config:system:set memcache.distributed --value '\OC\Memcache\Memcached' --type string
68 '';
69 withRcloneEnv = pkgs.writeScript "with-rclone-env" ''
70 #!${pkgs.runtimeShell}
71 export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav
72 export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/webdav/"
73 export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud"
74 export RCLONE_CONFIG_NEXTCLOUD_USER="${adminuser}"
75 export RCLONE_CONFIG_NEXTCLOUD_PASS="$(${pkgs.rclone}/bin/rclone obscure ${adminpass})"
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("${configureMemcached}")
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})