at 23.05-pre 4.5 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 system.stateVersion = "22.11"; # stateVersion >=21.11 to make sure that we use OpenSSL3 41 42 services.nextcloud = { 43 enable = true; 44 datadir = "/var/lib/nextcloud-data"; 45 hostName = "nextcloud"; 46 config = { 47 # Don't inherit adminuser since "root" is supposed to be the default 48 adminpassFile = "${pkgs.writeText "adminpass" adminpass}"; # Don't try this at home! 49 dbtableprefix = "nixos_"; 50 }; 51 package = pkgs.${"nextcloud" + (toString nextcloudVersion)}; 52 autoUpdateApps = { 53 enable = true; 54 startAt = "20:00"; 55 }; 56 phpExtraExtensions = all: [ all.bz2 ]; 57 }; 58 59 environment.systemPackages = [ cfg.services.nextcloud.occ ]; 60 }; 61 62 nextcloudWithoutMagick = args@{ config, pkgs, lib, ... }: 63 lib.mkMerge 64 [ (nextcloud args) 65 { services.nextcloud.enableImagemagick = false; } ]; 66 }; 67 68 testScript = { nodes, ... }: let 69 withRcloneEnv = pkgs.writeScript "with-rclone-env" '' 70 #!${pkgs.runtimeShell} 71 export RCLONE_CONFIG_NEXTCLOUD_TYPE=webdav 72 export RCLONE_CONFIG_NEXTCLOUD_URL="http://nextcloud/remote.php/webdav/" 73 export RCLONE_CONFIG_NEXTCLOUD_VENDOR="nextcloud" 74 export RCLONE_CONFIG_NEXTCLOUD_USER="${adminuser}" 75 export RCLONE_CONFIG_NEXTCLOUD_PASS="$(${pkgs.rclone}/bin/rclone obscure ${adminpass})" 76 "''${@}" 77 ''; 78 copySharedFile = pkgs.writeScript "copy-shared-file" '' 79 #!${pkgs.runtimeShell} 80 echo 'hi' | ${withRcloneEnv} ${pkgs.rclone}/bin/rclone rcat nextcloud:test-shared-file 81 ''; 82 83 diffSharedFile = pkgs.writeScript "diff-shared-file" '' 84 #!${pkgs.runtimeShell} 85 diff <(echo 'hi') <(${pkgs.rclone}/bin/rclone cat nextcloud:test-shared-file) 86 ''; 87 88 findInClosure = what: drv: pkgs.runCommand "find-in-closure" { exportReferencesGraph = [ "graph" drv ]; inherit what; } '' 89 test -e graph 90 grep "$what" graph >$out || true 91 ''; 92 nextcloudUsesImagick = findInClosure "imagick" nodes.nextcloud.config.system.build.vm; 93 nextcloudWithoutDoesntUseIt = findInClosure "imagick" nodes.nextcloudWithoutMagick.config.system.build.vm; 94 in '' 95 assert open("${nextcloudUsesImagick}").read() != "" 96 assert open("${nextcloudWithoutDoesntUseIt}").read() == "" 97 98 nextcloud.start() 99 client.start() 100 nextcloud.wait_for_unit("multi-user.target") 101 # This is just to ensure the nextcloud-occ program is working 102 nextcloud.succeed("nextcloud-occ status") 103 nextcloud.succeed("curl -sSf http://nextcloud/login") 104 # Ensure that no OpenSSL 1.1 is used. 105 nextcloud.succeed( 106 "${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" 107 ) 108 nextcloud.succeed( 109 "${withRcloneEnv} ${copySharedFile}" 110 ) 111 client.wait_for_unit("multi-user.target") 112 nextcloud.succeed("test -f /var/lib/nextcloud-data/data/root/files/test-shared-file") 113 client.succeed( 114 "${withRcloneEnv} ${diffSharedFile}" 115 ) 116 assert "hi" in client.succeed("cat /mnt/dav/test-shared-file") 117 nextcloud.succeed("grep -vE '^HBEGIN:oc_encryption_module' /var/lib/nextcloud-data/data/root/files/test-shared-file") 118 ''; 119})) args