2023-07-15 17:15:38 +00:00
|
|
|
args@{ nextcloudVersion ? 27, ... }:
|
|
|
|
(import ../make-test-python.nix ({ pkgs, ...}: let
|
2023-08-04 22:07:22 +00:00
|
|
|
adminuser = "custom_admin_username";
|
2023-05-24 13:37:59 +00:00
|
|
|
# This will be used both for redis and postgresql
|
|
|
|
pass = "hunter2";
|
|
|
|
# Don't do this at home, use a file outside of the nix store instead
|
|
|
|
passFile = toString (pkgs.writeText "pass-file" ''
|
|
|
|
${pass}
|
|
|
|
'');
|
2022-08-12 12:06:08 +00:00
|
|
|
in {
|
|
|
|
name = "nextcloud-with-declarative-redis";
|
|
|
|
meta = with pkgs.lib.maintainers; {
|
2023-07-15 17:15:38 +00:00
|
|
|
maintainers = [ eqyiel ma27 ];
|
2022-08-12 12:06:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
|
|
|
# The only thing the client needs to do is download a file.
|
|
|
|
client = { ... }: {};
|
|
|
|
|
|
|
|
nextcloud = { config, pkgs, ... }: {
|
|
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
|
|
|
|
|
|
|
services.nextcloud = {
|
|
|
|
enable = true;
|
|
|
|
hostName = "nextcloud";
|
2023-07-15 17:15:38 +00:00
|
|
|
package = pkgs.${"nextcloud" + (toString nextcloudVersion)};
|
2022-08-12 12:06:08 +00:00
|
|
|
caching = {
|
|
|
|
apcu = false;
|
|
|
|
redis = true;
|
|
|
|
memcached = false;
|
|
|
|
};
|
2023-05-24 13:37:59 +00:00
|
|
|
# This test also validates that we can use an "external" database
|
|
|
|
database.createLocally = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
config = {
|
|
|
|
dbtype = "pgsql";
|
|
|
|
dbname = "nextcloud";
|
2023-08-04 22:07:22 +00:00
|
|
|
dbuser = adminuser;
|
2023-05-24 13:37:59 +00:00
|
|
|
dbpassFile = passFile;
|
2023-08-04 22:07:22 +00:00
|
|
|
adminuser = adminuser;
|
2023-05-24 13:37:59 +00:00
|
|
|
adminpassFile = passFile;
|
2022-08-12 12:06:08 +00:00
|
|
|
};
|
|
|
|
secretFile = "/etc/nextcloud-secrets.json";
|
|
|
|
|
2024-02-07 01:22:34 +00:00
|
|
|
settings = {
|
2024-01-02 11:29:13 +00:00
|
|
|
allow_local_remote_servers = true;
|
|
|
|
redis = {
|
|
|
|
dbindex = 0;
|
|
|
|
timeout = 1.5;
|
|
|
|
# password handled via secretfile below
|
|
|
|
};
|
2022-08-12 12:06:08 +00:00
|
|
|
};
|
2023-07-15 17:15:38 +00:00
|
|
|
configureRedis = true;
|
2022-08-12 12:06:08 +00:00
|
|
|
};
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
services.redis.servers."nextcloud" = {
|
|
|
|
enable = true;
|
|
|
|
port = 6379;
|
|
|
|
requirePass = "secret";
|
|
|
|
};
|
2022-08-12 12:06:08 +00:00
|
|
|
|
|
|
|
systemd.services.nextcloud-setup= {
|
|
|
|
requires = ["postgresql.service"];
|
2023-05-24 13:37:59 +00:00
|
|
|
after = [ "postgresql.service" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
2024-01-02 11:29:13 +00:00
|
|
|
package = pkgs.postgresql_14;
|
2022-08-12 12:06:08 +00:00
|
|
|
};
|
2023-05-24 13:37:59 +00:00
|
|
|
systemd.services.postgresql.postStart = pkgs.lib.mkAfter ''
|
|
|
|
password=$(cat ${passFile})
|
|
|
|
${config.services.postgresql.package}/bin/psql <<EOF
|
2023-08-04 22:07:22 +00:00
|
|
|
CREATE ROLE ${adminuser} WITH LOGIN PASSWORD '$password' CREATEDB;
|
2023-05-24 13:37:59 +00:00
|
|
|
CREATE DATABASE nextcloud;
|
2023-08-04 22:07:22 +00:00
|
|
|
GRANT ALL PRIVILEGES ON DATABASE nextcloud TO ${adminuser};
|
2023-05-24 13:37:59 +00:00
|
|
|
EOF
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
|
|
|
|
# This file is meant to contain secret options which should
|
|
|
|
# not go into the nix store. Here it is just used to set the
|
2023-07-15 17:15:38 +00:00
|
|
|
# redis password.
|
2022-08-12 12:06:08 +00:00
|
|
|
environment.etc."nextcloud-secrets.json".text = ''
|
|
|
|
{
|
|
|
|
"redis": {
|
|
|
|
"password": "secret"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = let
|
|
|
|
withRcloneEnv = pkgs.writeScript "with-rclone-env" ''
|
|
|
|
#!${pkgs.runtimeShell}
|
|
|
|
export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav
|
2023-08-04 22:07:22 +00:00
|
|
|
export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/dav/files/${adminuser}"
|
2022-08-12 12:06:08 +00:00
|
|
|
export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud"
|
2023-08-04 22:07:22 +00:00
|
|
|
export RCLONE_CONFIG_NEXTCLOUD_USER="${adminuser}"
|
2023-05-24 13:37:59 +00:00
|
|
|
export RCLONE_CONFIG_NEXTCLOUD_PASS="$(${pkgs.rclone}/bin/rclone obscure ${pass})"
|
2022-08-12 12:06:08 +00:00
|
|
|
"''${@}"
|
|
|
|
'';
|
|
|
|
copySharedFile = pkgs.writeScript "copy-shared-file" ''
|
|
|
|
#!${pkgs.runtimeShell}
|
|
|
|
echo 'hi' | ${pkgs.rclone}/bin/rclone rcat nextcloud:test-shared-file
|
|
|
|
'';
|
|
|
|
|
|
|
|
diffSharedFile = pkgs.writeScript "diff-shared-file" ''
|
|
|
|
#!${pkgs.runtimeShell}
|
|
|
|
diff <(echo 'hi') <(${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file)
|
|
|
|
'';
|
|
|
|
in ''
|
|
|
|
start_all()
|
|
|
|
nextcloud.wait_for_unit("multi-user.target")
|
|
|
|
nextcloud.succeed("curl -sSf http://nextcloud/login")
|
|
|
|
nextcloud.succeed(
|
|
|
|
"${withRcloneEnv} ${copySharedFile}"
|
|
|
|
)
|
|
|
|
client.wait_for_unit("multi-user.target")
|
|
|
|
client.succeed(
|
|
|
|
"${withRcloneEnv} ${diffSharedFile}"
|
|
|
|
)
|
|
|
|
|
|
|
|
# redis cache should not be empty
|
2023-07-15 17:15:38 +00:00
|
|
|
nextcloud.fail('test "[]" = "$(redis-cli --json KEYS "*")"')
|
2022-08-12 12:06:08 +00:00
|
|
|
'';
|
2023-07-15 17:15:38 +00:00
|
|
|
})) args
|