1 args@{ pkgs, nextcloudVersion ? 22, ... }:
3 (import ../make-test-python.nix ({ pkgs, ...}: let
4 adminpass = "notproduction";
7 name = "nextcloud-basic";
8 meta = with pkgs.lib.maintainers; {
9 maintainers = [ globin eqyiel ];
13 # The only thing the client needs to do is download a file.
15 services.davfs2.enable = true;
16 system.activationScripts.davfs2-secrets = ''
17 echo "http://nextcloud/remote.php/webdav/ ${adminuser} ${adminpass}" > /tmp/davfs2-secrets
18 chmod 600 /tmp/davfs2-secrets
20 virtualisation.fileSystems = {
22 device = "http://nextcloud/remote.php/webdav/";
25 davfs2Conf = (pkgs.writeText "davfs2.conf" "secrets /tmp/davfs2-secrets");
26 in [ "conf=${davfs2Conf}" "x-systemd.automount" "noauto"];
31 nextcloud = { config, pkgs, ... }: let
34 networking.firewall.allowedTCPPorts = [ 80 ];
36 systemd.tmpfiles.rules = [
37 "d /var/lib/nextcloud-data 0750 nextcloud nginx - -"
40 services.nextcloud = {
42 datadir = "/var/lib/nextcloud-data";
43 hostName = "nextcloud";
45 # Don't inherit adminuser since "root" is supposed to be the default
46 adminpassFile = "${pkgs.writeText "adminpass" adminpass}"; # Don't try this at home!
47 dbtableprefix = "nixos_";
49 package = pkgs.${"nextcloud" + (toString nextcloudVersion)};
54 phpExtraExtensions = all: [ all.bz2 ];
57 environment.systemPackages = [ cfg.services.nextcloud.occ ];
60 nextcloudWithoutMagick = args@{ config, pkgs, lib, ... }:
63 { services.nextcloud.enableImagemagick = false; } ];
66 testScript = { nodes, ... }: let
67 withRcloneEnv = pkgs.writeScript "with-rclone-env" ''
68 #!${pkgs.runtimeShell}
69 export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav
70 export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/webdav/"
71 export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud"
72 export RCLONE_CONFIG_NEXTCLOUD_USER="${adminuser}"
73 export RCLONE_CONFIG_NEXTCLOUD_PASS="$(${pkgs.rclone}/bin/rclone obscure ${adminpass})"
76 copySharedFile = pkgs.writeScript "copy-shared-file" ''
77 #!${pkgs.runtimeShell}
78 echo 'hi' | ${withRcloneEnv} ${pkgs.rclone}/bin/rclone rcat nextcloud:test-shared-file
81 diffSharedFile = pkgs.writeScript "diff-shared-file" ''
82 #!${pkgs.runtimeShell}
83 diff <(echo 'hi') <(${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file)
86 findInClosure = what: drv: pkgs.runCommand "find-in-closure" { exportReferencesGraph = [ "graph" drv ]; inherit what; } ''
88 grep "$what" graph >$out || true
90 nextcloudUsesImagick = findInClosure "imagick" nodes.nextcloud.config.system.build.vm;
91 nextcloudWithoutDoesntUseIt = findInClosure "imagick" nodes.nextcloudWithoutMagick.config.system.build.vm;
93 assert open("${nextcloudUsesImagick}").read() != ""
94 assert open("${nextcloudWithoutDoesntUseIt}").read() == ""
98 nextcloud.wait_for_unit("multi-user.target")
99 # This is just to ensure the nextcloud-occ program is working
100 nextcloud.succeed("nextcloud-occ status")
101 nextcloud.succeed("curl -sSf http://nextcloud/login")
103 "${withRcloneEnv} ${copySharedFile}"
105 client.wait_for_unit("multi-user.target")
106 nextcloud.succeed("test -f /var/lib/nextcloud-data/data/root/files/test-shared-file")
108 "${withRcloneEnv} ${diffSharedFile}"
110 assert "hi" in client.succeed("cat /mnt/dav/test-shared-file")