1import ../make-test-python.nix ({ pkgs, ...}: let
2 adminpass = "notproduction";
3 adminuser = "root";
4in {
5 name = "nextcloud-basic";
6 meta = with pkgs.lib.maintainers; {
7 maintainers = [ globin eqyiel ];
8 };
9
10 nodes = rec {
11 # The only thing the client needs to do is download a file.
12 client = { ... }: {
13 services.davfs2.enable = true;
14 system.activationScripts.davfs2-secrets = ''
15 echo "http://nextcloud/remote.php/webdav/ ${adminuser} ${adminpass}" > /tmp/davfs2-secrets
16 chmod 600 /tmp/davfs2-secrets
17 '';
18 virtualisation.fileSystems = {
19 "/mnt/dav" = {
20 device = "http://nextcloud/remote.php/webdav/";
21 fsType = "davfs";
22 options = let
23 davfs2Conf = (pkgs.writeText "davfs2.conf" "secrets /tmp/davfs2-secrets");
24 in [ "conf=${davfs2Conf}" "x-systemd.automount" "noauto"];
25 };
26 };
27 };
28
29 nextcloud = { config, pkgs, ... }: let
30 cfg = config;
31 in {
32 networking.firewall.allowedTCPPorts = [ 80 ];
33
34 services.nextcloud = {
35 enable = true;
36 hostName = "nextcloud";
37 config = {
38 # Don't inherit adminuser since "root" is supposed to be the default
39 inherit adminpass;
40 };
41 autoUpdateApps = {
42 enable = true;
43 startAt = "20:00";
44 };
45 phpExtraExtensions = all: [ all.bz2 ];
46 };
47
48 environment.systemPackages = [ cfg.services.nextcloud.occ ];
49 };
50
51 nextcloudWithoutMagick = args@{ config, pkgs, lib, ... }:
52 lib.mkMerge
53 [ (nextcloud args)
54 { services.nextcloud.enableImagemagick = false; } ];
55 };
56
57 testScript = { nodes, ... }: let
58 withRcloneEnv = pkgs.writeScript "with-rclone-env" ''
59 #!${pkgs.runtimeShell}
60 export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav
61 export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/webdav/"
62 export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud"
63 export RCLONE_CONFIG_NEXTCLOUD_USER="${adminuser}"
64 export RCLONE_CONFIG_NEXTCLOUD_PASS="$(${pkgs.rclone}/bin/rclone obscure ${adminpass})"
65 "''${@}"
66 '';
67 copySharedFile = pkgs.writeScript "copy-shared-file" ''
68 #!${pkgs.runtimeShell}
69 echo 'hi' | ${withRcloneEnv} ${pkgs.rclone}/bin/rclone rcat nextcloud:test-shared-file
70 '';
71
72 diffSharedFile = pkgs.writeScript "diff-shared-file" ''
73 #!${pkgs.runtimeShell}
74 diff <(echo 'hi') <(${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file)
75 '';
76
77 findInClosure = what: drv: pkgs.runCommand "find-in-closure" { exportReferencesGraph = [ "graph" drv ]; inherit what; } ''
78 test -e graph
79 grep "$what" graph >$out || true
80 '';
81 nextcloudUsesImagick = findInClosure "imagick" nodes.nextcloud.config.system.build.vm;
82 nextcloudWithoutDoesntUseIt = findInClosure "imagick" nodes.nextcloudWithoutMagick.config.system.build.vm;
83 in ''
84 assert open("${nextcloudUsesImagick}").read() != ""
85 assert open("${nextcloudWithoutDoesntUseIt}").read() == ""
86
87 nextcloud.start()
88 client.start()
89 nextcloud.wait_for_unit("multi-user.target")
90 # This is just to ensure the nextcloud-occ program is working
91 nextcloud.succeed("nextcloud-occ status")
92 nextcloud.succeed("curl -sSf http://nextcloud/login")
93 nextcloud.succeed(
94 "${withRcloneEnv} ${copySharedFile}"
95 )
96 client.wait_for_unit("multi-user.target")
97 client.succeed(
98 "${withRcloneEnv} ${diffSharedFile}"
99 )
100 assert "hi" in client.succeed("cat /mnt/dav/test-shared-file")
101 '';
102})