1 args@{ nextcloudVersion ? 27, ... }:
2 (import ../make-test-python.nix ({ pkgs, ...}: let
3 adminuser = "custom_admin_username";
4 # This will be used both for redis and postgresql
6 # Don't do this at home, use a file outside of the nix store instead
7 passFile = toString (pkgs.writeText "pass-file" ''
11 name = "nextcloud-with-declarative-redis";
12 meta = with pkgs.lib.maintainers; {
13 maintainers = [ eqyiel ma27 ];
17 # The only thing the client needs to do is download a file.
20 nextcloud = { config, pkgs, ... }: {
21 networking.firewall.allowedTCPPorts = [ 80 ];
23 services.nextcloud = {
25 hostName = "nextcloud";
26 package = pkgs.${"nextcloud" + (toString nextcloudVersion)};
32 # This test also validates that we can use an "external" database
33 database.createLocally = false;
38 dbpassFile = passFile;
39 adminuser = adminuser;
40 adminpassFile = passFile;
42 secretFile = "/etc/nextcloud-secrets.json";
45 allow_local_remote_servers = true;
49 # password handled via secretfile below
52 configureRedis = true;
55 services.redis.servers."nextcloud" = {
58 requirePass = "secret";
61 systemd.services.nextcloud-setup= {
62 requires = ["postgresql.service"];
63 after = [ "postgresql.service" ];
66 services.postgresql = {
68 package = pkgs.postgresql_14;
70 systemd.services.postgresql.postStart = pkgs.lib.mkAfter ''
71 password=$(cat ${passFile})
72 ${config.services.postgresql.package}/bin/psql <<EOF
73 CREATE ROLE ${adminuser} WITH LOGIN PASSWORD '$password' CREATEDB;
74 CREATE DATABASE nextcloud;
75 GRANT ALL PRIVILEGES ON DATABASE nextcloud TO ${adminuser};
79 # This file is meant to contain secret options which should
80 # not go into the nix store. Here it is just used to set the
82 environment.etc."nextcloud-secrets.json".text = ''
93 withRcloneEnv = pkgs.writeScript "with-rclone-env" ''
94 #!${pkgs.runtimeShell}
95 export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav
96 export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/dav/files/${adminuser}"
97 export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud"
98 export RCLONE_CONFIG_NEXTCLOUD_USER="${adminuser}"
99 export RCLONE_CONFIG_NEXTCLOUD_PASS="$(${pkgs.rclone}/bin/rclone obscure ${pass})"
102 copySharedFile = pkgs.writeScript "copy-shared-file" ''
103 #!${pkgs.runtimeShell}
104 echo 'hi' | ${pkgs.rclone}/bin/rclone rcat nextcloud:test-shared-file
107 diffSharedFile = pkgs.writeScript "diff-shared-file" ''
108 #!${pkgs.runtimeShell}
109 diff <(echo 'hi') <(${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file)
113 nextcloud.wait_for_unit("multi-user.target")
114 nextcloud.succeed("curl -sSf http://nextcloud/login")
116 "${withRcloneEnv} ${copySharedFile}"
118 client.wait_for_unit("multi-user.target")
120 "${withRcloneEnv} ${diffSharedFile}"
123 # redis cache should not be empty
124 nextcloud.fail('test "[]" = "$(redis-cli --json KEYS "*")"')