2020-04-24 23:36:52 +00:00
|
|
|
import ../make-test-python.nix ({ pkgs, ...}: let
|
|
|
|
adminpass = "notproduction";
|
|
|
|
adminuser = "root";
|
|
|
|
in {
|
|
|
|
name = "nextcloud-basic";
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with pkgs.lib.maintainers; {
|
2020-04-24 23:36:52 +00:00
|
|
|
maintainers = [ globin eqyiel ];
|
|
|
|
};
|
|
|
|
|
2021-03-12 07:09:13 +00:00
|
|
|
nodes = rec {
|
2020-04-24 23:36:52 +00:00
|
|
|
# The only thing the client needs to do is download a file.
|
2020-05-29 06:06:01 +00: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-16 17:04:54 +00:00
|
|
|
virtualisation.fileSystems = {
|
2020-05-29 06:06:01 +00: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"];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-06-15 15:56:04 +00:00
|
|
|
nextcloud = { config, pkgs, ... }: let
|
|
|
|
cfg = config;
|
|
|
|
in {
|
2020-04-24 23:36:52 +00:00
|
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
|
|
|
|
|
|
|
services.nextcloud = {
|
|
|
|
enable = true;
|
|
|
|
hostName = "nextcloud";
|
|
|
|
config = {
|
|
|
|
# Don't inherit adminuser since "root" is supposed to be the default
|
|
|
|
inherit adminpass;
|
2021-09-18 10:52:07 +00:00
|
|
|
dbtableprefix = "nixos_";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
autoUpdateApps = {
|
|
|
|
enable = true;
|
|
|
|
startAt = "20:00";
|
|
|
|
};
|
2021-02-05 17:12:51 +00:00
|
|
|
phpExtraExtensions = all: [ all.bz2 ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2020-06-15 15:56:04 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.services.nextcloud.occ ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2021-03-12 07:09:13 +00:00
|
|
|
|
|
|
|
nextcloudWithoutMagick = args@{ config, pkgs, lib, ... }:
|
|
|
|
lib.mkMerge
|
|
|
|
[ (nextcloud args)
|
2021-04-25 03:57:28 +00:00
|
|
|
{ services.nextcloud.enableImagemagick = false; } ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-03-12 07:09:13 +00:00
|
|
|
testScript = { nodes, ... }: let
|
2020-04-24 23:36:52 +00:00
|
|
|
withRcloneEnv = pkgs.writeScript "with-rclone-env" ''
|
|
|
|
#!${pkgs.runtimeShell}
|
|
|
|
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" ''
|
|
|
|
#!${pkgs.runtimeShell}
|
|
|
|
echo 'hi' | ${withRcloneEnv} ${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)
|
|
|
|
'';
|
2021-03-12 07:09:13 +00: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;
|
2020-04-24 23:36:52 +00:00
|
|
|
in ''
|
2021-03-12 07:09:13 +00:00
|
|
|
assert open("${nextcloudUsesImagick}").read() != ""
|
|
|
|
assert open("${nextcloudWithoutDoesntUseIt}").read() == ""
|
|
|
|
|
|
|
|
nextcloud.start()
|
|
|
|
client.start()
|
2020-04-24 23:36:52 +00:00
|
|
|
nextcloud.wait_for_unit("multi-user.target")
|
2020-06-15 15:56:04 +00:00
|
|
|
# This is just to ensure the nextcloud-occ program is working
|
|
|
|
nextcloud.succeed("nextcloud-occ status")
|
2020-04-24 23:36:52 +00:00
|
|
|
nextcloud.succeed("curl -sSf http://nextcloud/login")
|
|
|
|
nextcloud.succeed(
|
|
|
|
"${withRcloneEnv} ${copySharedFile}"
|
|
|
|
)
|
|
|
|
client.wait_for_unit("multi-user.target")
|
|
|
|
client.succeed(
|
|
|
|
"${withRcloneEnv} ${diffSharedFile}"
|
|
|
|
)
|
2020-05-29 06:06:01 +00:00
|
|
|
assert "hi" in client.succeed("cat /mnt/dav/test-shared-file")
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
})
|