2024-09-30 22:21:29 +02:00
|
|
|
{
|
|
|
|
name,
|
|
|
|
pkgs,
|
|
|
|
testBase,
|
|
|
|
system,
|
|
|
|
...
|
|
|
|
}:
|
2024-09-30 22:11:43 +02:00
|
|
|
|
|
|
|
with import ../../lib/testing-python.nix { inherit system pkgs; };
|
|
|
|
runTest (
|
2024-12-22 21:36:32 +01:00
|
|
|
{ config, lib, ... }:
|
2024-09-30 22:11:43 +02:00
|
|
|
let
|
|
|
|
inherit (config) adminuser;
|
|
|
|
in
|
|
|
|
{
|
2024-09-30 22:21:29 +02:00
|
|
|
inherit name;
|
2024-12-22 21:36:32 +01:00
|
|
|
meta = with lib.maintainers; {
|
2023-06-17 14:04:44 +02:00
|
|
|
maintainers = [
|
|
|
|
eqyiel
|
|
|
|
ma27
|
|
|
|
];
|
2021-03-30 20:09:29 +02:00
|
|
|
};
|
|
|
|
|
2024-09-30 22:11:43 +02:00
|
|
|
imports = [ testBase ];
|
2021-03-30 20:09:29 +02:00
|
|
|
|
2024-09-30 22:11:43 +02:00
|
|
|
nodes = {
|
2021-03-30 20:09:29 +02:00
|
|
|
nextcloud =
|
|
|
|
{ config, pkgs, ... }:
|
|
|
|
{
|
2024-09-30 22:11:43 +02:00
|
|
|
environment.systemPackages = [ pkgs.jq ];
|
2021-03-30 20:09:29 +02:00
|
|
|
services.nextcloud = {
|
|
|
|
caching = {
|
|
|
|
apcu = false;
|
|
|
|
redis = true;
|
|
|
|
memcached = false;
|
|
|
|
};
|
2024-12-22 19:02:55 +01:00
|
|
|
notify_push = {
|
|
|
|
enable = true;
|
|
|
|
bendDomainToLocalhost = true;
|
|
|
|
logLevel = "debug";
|
|
|
|
};
|
|
|
|
extraAppsEnable = true;
|
|
|
|
extraApps.notify_push = config.services.nextcloud.package.packages.apps.notify_push;
|
2023-04-30 14:34:42 -03:00
|
|
|
# This test also validates that we can use an "external" database
|
|
|
|
database.createLocally = false;
|
2021-03-30 20:09:29 +02:00
|
|
|
config = {
|
|
|
|
dbtype = "pgsql";
|
|
|
|
dbname = "nextcloud";
|
2023-07-25 12:15:34 +02:00
|
|
|
dbuser = adminuser;
|
2024-09-30 22:11:43 +02:00
|
|
|
dbpassFile = config.services.nextcloud.config.adminpassFile;
|
2021-03-30 20:09:29 +02:00
|
|
|
};
|
2024-09-30 22:11:43 +02:00
|
|
|
|
2022-07-06 00:08:29 +02:00
|
|
|
secretFile = "/etc/nextcloud-secrets.json";
|
2021-03-30 20:09:29 +02:00
|
|
|
|
2024-01-26 11:59:56 +01:00
|
|
|
settings = {
|
2023-11-25 22:58:06 +01:00
|
|
|
allow_local_remote_servers = true;
|
|
|
|
redis = {
|
|
|
|
dbindex = 0;
|
|
|
|
timeout = 1.5;
|
|
|
|
# password handled via secretfile below
|
2024-12-10 20:26:33 +01:00
|
|
|
};
|
|
|
|
};
|
2023-06-16 14:07:05 +02:00
|
|
|
configureRedis = true;
|
2023-11-25 22:58:06 +01:00
|
|
|
};
|
2021-03-30 20:09:29 +02:00
|
|
|
|
2023-06-17 14:04:44 +02:00
|
|
|
services.redis.servers."nextcloud" = {
|
|
|
|
enable = true;
|
|
|
|
port = 6379;
|
|
|
|
requirePass = "secret";
|
|
|
|
};
|
2021-03-30 20:09:29 +02:00
|
|
|
|
|
|
|
systemd.services.nextcloud-setup = {
|
|
|
|
requires = [ "postgresql.service" ];
|
2023-04-30 14:34:42 -03:00
|
|
|
after = [ "postgresql.service" ];
|
2021-03-30 20:09:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
|
|
|
};
|
2024-12-22 21:36:32 +01:00
|
|
|
systemd.services.postgresql.postStart = lib.mkAfter ''
|
2024-09-30 22:11:43 +02:00
|
|
|
password=$(cat ${config.services.nextcloud.config.dbpassFile})
|
2023-04-30 14:34:42 -03:00
|
|
|
${config.services.postgresql.package}/bin/psql <<EOF
|
2023-07-25 12:15:34 +02:00
|
|
|
CREATE ROLE ${adminuser} WITH LOGIN PASSWORD '$password' CREATEDB;
|
2023-04-30 14:34:42 -03:00
|
|
|
CREATE DATABASE nextcloud;
|
2024-12-30 23:54:35 +01:00
|
|
|
ALTER DATABASE nextcloud OWNER to ${adminuser};
|
2023-04-30 14:34:42 -03:00
|
|
|
EOF
|
|
|
|
'';
|
2022-07-06 00:08:29 +02: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-06-16 14:07:05 +02:00
|
|
|
# redis password.
|
2022-07-06 00:08:29 +02:00
|
|
|
environment.etc."nextcloud-secrets.json".text = ''
|
|
|
|
{
|
|
|
|
"redis": {
|
|
|
|
"password": "secret"
|
2024-12-10 20:26:33 +01:00
|
|
|
}
|
2022-07-06 00:08:29 +02:00
|
|
|
}
|
|
|
|
'';
|
2024-12-10 20:26:33 +01:00
|
|
|
};
|
2021-03-30 20:09:29 +02:00
|
|
|
};
|
|
|
|
|
2024-09-30 22:11:43 +02:00
|
|
|
test-helpers.extraTests = ''
|
|
|
|
with subtest("non-empty redis cache"):
|
|
|
|
# redis cache should not be empty
|
2024-12-23 00:46:32 +01:00
|
|
|
assert nextcloud.succeed('redis-cli --pass secret --json KEYS "*" | jq length').strip() != "0", """
|
|
|
|
redis-cli for keys * returned 0 entries
|
|
|
|
"""
|
2024-12-22 19:02:55 +01:00
|
|
|
|
|
|
|
with subtest("notify-push"):
|
2024-12-22 21:36:32 +01:00
|
|
|
client.execute("${lib.getExe pkgs.nextcloud-notify_push.passthru.test_client} http://nextcloud ${config.adminuser} ${config.adminpass} >&2 &")
|
2024-12-22 19:02:55 +01:00
|
|
|
nextcloud.wait_until_succeeds("journalctl -u nextcloud-notify_push | grep -q \"Sending ping to ${config.adminuser}\"")
|
2021-03-30 20:09:29 +02:00
|
|
|
'';
|
2024-09-30 22:11:43 +02:00
|
|
|
}
|
|
|
|
)
|