at 22.05-pre 4.0 kB view raw
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/webdav/ ${adminuser} ${adminpass}" > /tmp/davfs2-secrets 18 chmod 600 /tmp/davfs2-secrets 19 ''; 20 virtualisation.fileSystems = { 21 "/mnt/dav" = { 22 device = "http://nextcloud/remote.php/webdav/"; 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 config = { 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_"; 48 }; 49 package = pkgs.${"nextcloud" + (toString nextcloudVersion)}; 50 autoUpdateApps = { 51 enable = true; 52 startAt = "20:00"; 53 }; 54 phpExtraExtensions = all: [ all.bz2 ]; 55 }; 56 57 environment.systemPackages = [ cfg.services.nextcloud.occ ]; 58 }; 59 60 nextcloudWithoutMagick = args@{ config, pkgs, lib, ... }: 61 lib.mkMerge 62 [ (nextcloud args) 63 { services.nextcloud.enableImagemagick = false; } ]; 64 }; 65 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})" 74 "''${@}" 75 ''; 76 copySharedFile = pkgs.writeScript "copy-shared-file" '' 77 #!${pkgs.runtimeShell} 78 echo 'hi' | ${withRcloneEnv} ${pkgs.rclone}/bin/rclone rcat nextcloud:test-shared-file 79 ''; 80 81 diffSharedFile = pkgs.writeScript "diff-shared-file" '' 82 #!${pkgs.runtimeShell} 83 diff <(echo 'hi') <(${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file) 84 ''; 85 86 findInClosure = what: drv: pkgs.runCommand "find-in-closure" { exportReferencesGraph = [ "graph" drv ]; inherit what; } '' 87 test -e graph 88 grep "$what" graph >$out || true 89 ''; 90 nextcloudUsesImagick = findInClosure "imagick" nodes.nextcloud.config.system.build.vm; 91 nextcloudWithoutDoesntUseIt = findInClosure "imagick" nodes.nextcloudWithoutMagick.config.system.build.vm; 92 in '' 93 assert open("${nextcloudUsesImagick}").read() != "" 94 assert open("${nextcloudWithoutDoesntUseIt}").read() == "" 95 96 nextcloud.start() 97 client.start() 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") 102 nextcloud.succeed( 103 "${withRcloneEnv} ${copySharedFile}" 104 ) 105 client.wait_for_unit("multi-user.target") 106 nextcloud.succeed("test -f /var/lib/nextcloud-data/data/root/files/test-shared-file") 107 client.succeed( 108 "${withRcloneEnv} ${diffSharedFile}" 109 ) 110 assert "hi" in client.succeed("cat /mnt/dav/test-shared-file") 111 ''; 112})) args