1 import ../make-test-python.nix ({ pkgs, ...}: let
3 adminuser = "custom-admin-username";
5 name = "nextcloud-with-declarative-redis";
6 meta = with pkgs.lib.maintainers; {
7 maintainers = [ eqyiel ];
11 # The only thing the client needs to do is download a file.
14 nextcloud = { config, pkgs, ... }: {
15 networking.firewall.allowedTCPPorts = [ 80 ];
17 services.nextcloud = {
19 hostName = "nextcloud";
29 dbhost = "/run/postgresql";
31 adminpassFile = toString (pkgs.writeText "admin-pass-file" ''
35 secretFile = "/etc/nextcloud-secrets.json";
37 extraOptions.redis = {
38 host = "/run/redis/redis.sock";
42 # password handled via secretfile below
44 extraOptions.memcache = {
45 local = "\OC\Memcache\Redis";
46 locking = "\OC\Memcache\Redis";
50 services.redis.servers."nextcloud".enable = true;
51 services.redis.servers."nextcloud".port = 6379;
53 systemd.services.nextcloud-setup= {
54 requires = ["postgresql.service"];
60 services.postgresql = {
62 ensureDatabases = [ "nextcloud" ];
65 ensurePermissions."DATABASE nextcloud" = "ALL PRIVILEGES";
70 # This file is meant to contain secret options which should
71 # not go into the nix store. Here it is just used to set the
72 # databyse type to postgres.
73 environment.etc."nextcloud-secrets.json".text = ''
84 withRcloneEnv = pkgs.writeScript "with-rclone-env" ''
85 #!${pkgs.runtimeShell}
86 export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav
87 export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/webdav/"
88 export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud"
89 export RCLONE_CONFIG_NEXTCLOUD_USER="${adminuser}"
90 export RCLONE_CONFIG_NEXTCLOUD_PASS="$(${pkgs.rclone}/bin/rclone obscure ${adminpass})"
93 copySharedFile = pkgs.writeScript "copy-shared-file" ''
94 #!${pkgs.runtimeShell}
95 echo 'hi' | ${pkgs.rclone}/bin/rclone rcat nextcloud:test-shared-file
98 diffSharedFile = pkgs.writeScript "diff-shared-file" ''
99 #!${pkgs.runtimeShell}
100 diff <(echo 'hi') <(${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file)
104 nextcloud.wait_for_unit("multi-user.target")
105 nextcloud.succeed("curl -sSf http://nextcloud/login")
107 "${withRcloneEnv} ${copySharedFile}"
109 client.wait_for_unit("multi-user.target")
111 "${withRcloneEnv} ${diffSharedFile}"
114 # redis cache should not be empty
115 nextcloud.fail("redis-cli KEYS * | grep -q 'empty array'")