1 { system ? builtins.currentSystem
3 , pkgs ? import ../../.. { inherit system config; }
9 baseModule = { config, ... }: {
12 options.test-helpers = {
13 rclone = mkOption { type = types.str; };
14 upload-sample = mkOption { type = types.str; };
15 check-sample = mkOption { type = types.str; };
16 init = mkOption { type = types.str; default = ""; };
17 extraTests = mkOption { type = types.either types.str (types.functionTo types.str); default = ""; };
19 options.adminuser = mkOption { type = types.str; };
20 options.adminpass = mkOption { type = types.str; };
25 adminpass = "hunter2";
27 test-helpers.rclone = "${pkgs.writeShellScript "rclone" ''
29 export PATH="${pkgs.rclone}/bin:$PATH"
30 export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav
31 export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/dav/files/${config.adminuser}"
32 export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud"
33 export RCLONE_CONFIG_NEXTCLOUD_USER="${config.adminuser}"
34 export RCLONE_CONFIG_NEXTCLOUD_PASS="$(rclone obscure ${config.adminpass})"
37 test-helpers.upload-sample = "${pkgs.writeShellScript "rclone-upload" ''
38 <<<'hi' rclone rcat nextcloud:test-shared-file
40 test-helpers.check-sample = "${pkgs.writeShellScript "check-sample" ''
42 diff <(echo 'hi') <(rclone cat nextcloud:test-shared-file)
47 nextcloud = { lib, ... }: {
48 networking.firewall.allowedTCPPorts = [ 80 ];
49 services.nextcloud = {
51 hostName = "nextcloud";
53 database.createLocally = lib.mkDefault true;
55 adminpassFile = "${pkgs.writeText "adminpass" config.adminpass}"; # Don't try this at home!
61 testScript = args@{ nodes, ... }: let
62 inherit (config) test-helpers;
66 nextcloud.wait_for_unit("multi-user.target")
70 with subtest("Ensure nextcloud-occ is working"):
71 nextcloud.succeed("nextcloud-occ status")
72 nextcloud.succeed("curl -sSf http://nextcloud/login")
74 with subtest("Upload/Download test"):
76 "${test-helpers.rclone} ${test-helpers.upload-sample}"
78 client.wait_for_unit("multi-user.target")
80 "${test-helpers.rclone} ${test-helpers.check-sample}"
83 ${if builtins.isFunction test-helpers.extraTests then test-helpers.extraTests args else test-helpers.extraTests}
92 nodes.nextcloud = { pkgs, ... }: {
93 services.nextcloud.package = pkgs.${"nextcloud${toString version}"};
98 callNextcloudTest = path:
100 name = "${removeSuffix ".nix" (baseNameOf path)}${toString version}";
101 in nameValuePair name (import path {
102 inherit system pkgs testBase;
103 name = "nextcloud-${name}";
105 in map callNextcloudTest [
107 ./with-declarative-redis-and-secrets.nix
108 ./with-mysql-and-memcached.nix
109 ./with-postgresql-and-redis.nix
110 ./with-objectstore.nix
113 listToAttrs (concatMap genTests [ 28 29 30 ])