2021-10-01 17:03:32 +02:00
|
|
|
args@{ pkgs, nextcloudVersion ? 22, ... }:
|
|
|
|
|
|
|
|
(import ../make-test-python.nix ({ pkgs, ...}: let
|
2018-06-29 19:17:54 +02:00
|
|
|
adminpass = "notproduction";
|
|
|
|
adminuser = "root";
|
|
|
|
in {
|
|
|
|
name = "nextcloud-basic";
|
2021-01-10 20:08:30 +01:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2018-06-29 19:17:54 +02:00
|
|
|
maintainers = [ globin eqyiel ];
|
|
|
|
};
|
|
|
|
|
2021-03-09 01:44:18 +01:00
|
|
|
nodes = rec {
|
2018-06-29 19:17:54 +02:00
|
|
|
# The only thing the client needs to do is download a file.
|
2020-05-24 00:01:06 +02:00
|
|
|
client = { ... }: {
|
|
|
|
services.davfs2.enable = true;
|
|
|
|
system.activationScripts.davfs2-secrets = ''
|
|
|
|
echo "http://nextcloud/remote.php/webdav/ ${adminuser} ${adminpass}" > /tmp/davfs2-secrets
|
|
|
|
chmod 600 /tmp/davfs2-secrets
|
|
|
|
'';
|
2021-02-14 12:23:50 +01:00
|
|
|
virtualisation.fileSystems = {
|
2020-05-24 00:01:06 +02:00
|
|
|
"/mnt/dav" = {
|
|
|
|
device = "http://nextcloud/remote.php/webdav/";
|
|
|
|
fsType = "davfs";
|
|
|
|
options = let
|
|
|
|
davfs2Conf = (pkgs.writeText "davfs2.conf" "secrets /tmp/davfs2-secrets");
|
|
|
|
in [ "conf=${davfs2Conf}" "x-systemd.automount" "noauto"];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2018-06-29 19:17:54 +02:00
|
|
|
|
2020-06-20 09:55:02 +02:00
|
|
|
nextcloud = { config, pkgs, ... }: let
|
|
|
|
cfg = config;
|
|
|
|
in {
|
2018-06-29 19:17:54 +02:00
|
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
|
|
|
|
2021-10-09 22:36:35 +02:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d /var/lib/nextcloud-data 0750 nextcloud nginx - -"
|
|
|
|
];
|
|
|
|
|
2018-06-29 19:17:54 +02:00
|
|
|
services.nextcloud = {
|
|
|
|
enable = true;
|
2021-10-09 22:36:35 +02:00
|
|
|
datadir = "/var/lib/nextcloud-data";
|
2018-06-29 19:17:54 +02:00
|
|
|
hostName = "nextcloud";
|
|
|
|
config = {
|
|
|
|
# Don't inherit adminuser since "root" is supposed to be the default
|
2021-10-08 18:30:57 +02:00
|
|
|
adminpassFile = "${pkgs.writeText "adminpass" adminpass}"; # Don't try this at home!
|
2021-08-27 20:21:25 +02:00
|
|
|
dbtableprefix = "nixos_";
|
2018-06-29 19:17:54 +02:00
|
|
|
};
|
2021-10-01 17:03:32 +02:00
|
|
|
package = pkgs.${"nextcloud" + (toString nextcloudVersion)};
|
2019-05-19 19:58:19 +02:00
|
|
|
autoUpdateApps = {
|
|
|
|
enable = true;
|
|
|
|
startAt = "20:00";
|
|
|
|
};
|
2021-01-09 17:53:30 +01:00
|
|
|
phpExtraExtensions = all: [ all.bz2 ];
|
2018-06-29 19:17:54 +02:00
|
|
|
};
|
2020-06-20 09:55:02 +02:00
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.services.nextcloud.occ ];
|
2018-06-29 19:17:54 +02:00
|
|
|
};
|
2021-03-09 01:44:18 +01:00
|
|
|
|
|
|
|
nextcloudWithoutMagick = args@{ config, pkgs, lib, ... }:
|
|
|
|
lib.mkMerge
|
|
|
|
[ (nextcloud args)
|
2021-04-22 02:17:12 +02:00
|
|
|
{ services.nextcloud.enableImagemagick = false; } ];
|
2018-06-29 19:17:54 +02:00
|
|
|
};
|
|
|
|
|
2021-03-11 02:56:11 +01:00
|
|
|
testScript = { nodes, ... }: let
|
2018-06-29 19:17:54 +02:00
|
|
|
withRcloneEnv = pkgs.writeScript "with-rclone-env" ''
|
2020-04-07 08:25:48 +02:00
|
|
|
#!${pkgs.runtimeShell}
|
2018-06-29 19:17:54 +02:00
|
|
|
export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav
|
|
|
|
export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/webdav/"
|
|
|
|
export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud"
|
|
|
|
export RCLONE_CONFIG_NEXTCLOUD_USER="${adminuser}"
|
|
|
|
export RCLONE_CONFIG_NEXTCLOUD_PASS="$(${pkgs.rclone}/bin/rclone obscure ${adminpass})"
|
|
|
|
"''${@}"
|
|
|
|
'';
|
|
|
|
copySharedFile = pkgs.writeScript "copy-shared-file" ''
|
2020-04-07 08:25:48 +02:00
|
|
|
#!${pkgs.runtimeShell}
|
2018-06-29 19:17:54 +02:00
|
|
|
echo 'hi' | ${withRcloneEnv} ${pkgs.rclone}/bin/rclone rcat nextcloud:test-shared-file
|
|
|
|
'';
|
|
|
|
|
|
|
|
diffSharedFile = pkgs.writeScript "diff-shared-file" ''
|
2020-04-07 08:25:48 +02:00
|
|
|
#!${pkgs.runtimeShell}
|
2018-06-29 19:17:54 +02:00
|
|
|
diff <(echo 'hi') <(${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file)
|
|
|
|
'';
|
2021-03-11 02:56:11 +01:00
|
|
|
|
|
|
|
findInClosure = what: drv: pkgs.runCommand "find-in-closure" { exportReferencesGraph = [ "graph" drv ]; inherit what; } ''
|
|
|
|
test -e graph
|
|
|
|
grep "$what" graph >$out || true
|
|
|
|
'';
|
|
|
|
nextcloudUsesImagick = findInClosure "imagick" nodes.nextcloud.config.system.build.vm;
|
|
|
|
nextcloudWithoutDoesntUseIt = findInClosure "imagick" nodes.nextcloudWithoutMagick.config.system.build.vm;
|
2018-06-29 19:17:54 +02:00
|
|
|
in ''
|
2021-03-11 02:56:11 +01:00
|
|
|
assert open("${nextcloudUsesImagick}").read() != ""
|
|
|
|
assert open("${nextcloudWithoutDoesntUseIt}").read() == ""
|
|
|
|
|
2021-03-09 01:44:18 +01:00
|
|
|
nextcloud.start()
|
|
|
|
client.start()
|
2019-11-27 10:50:26 +01:00
|
|
|
nextcloud.wait_for_unit("multi-user.target")
|
2020-06-20 09:55:02 +02:00
|
|
|
# This is just to ensure the nextcloud-occ program is working
|
|
|
|
nextcloud.succeed("nextcloud-occ status")
|
2019-11-27 10:50:26 +01:00
|
|
|
nextcloud.succeed("curl -sSf http://nextcloud/login")
|
|
|
|
nextcloud.succeed(
|
|
|
|
"${withRcloneEnv} ${copySharedFile}"
|
|
|
|
)
|
|
|
|
client.wait_for_unit("multi-user.target")
|
2021-10-09 22:36:35 +02:00
|
|
|
nextcloud.succeed("test -f /var/lib/nextcloud-data/data/root/files/test-shared-file")
|
2019-11-27 10:50:26 +01:00
|
|
|
client.succeed(
|
|
|
|
"${withRcloneEnv} ${diffSharedFile}"
|
|
|
|
)
|
2020-05-24 00:01:06 +02:00
|
|
|
assert "hi" in client.succeed("cat /mnt/dav/test-shared-file")
|
2018-06-29 19:17:54 +02:00
|
|
|
'';
|
2021-10-01 17:03:32 +02:00
|
|
|
})) args
|