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