{ varDir ? "/var/lib/nextcloud", lib, stdenv, fetchurl }: let buildApp = { appName, version, url, sha256, installPhase ? "mkdir -p $out && cp -R . $out/" }: stdenv.mkDerivation rec { name = "nextcloud-app-${appName}-${version}"; inherit version; phases = "unpackPhase installPhase"; inherit installPhase; src = fetchurl { inherit url sha256; }; passthru.appName = appName; }; withApps = apps: package.overrideAttrs(old: { name = "${old.name}-with-apps"; installPhase = old.installPhase + ( builtins.concatStringsSep "\n" ( map (value: "ln -sf ${value} $out/apps/${value.appName}") apps )); passthru.apps = apps; passthru.withApps = moreApps: old.withApps (moreApps ++ apps); }); package = stdenv.mkDerivation rec { name = "nextcloud-${version}"; version = "15.0.4"; src = fetchurl { url = "https://download.nextcloud.com/server/releases/${name}.tar.bz2"; sha256 = "0xwg7p31y1pkjk1pzygh9shpqxnfkafrab52j7in7xblq53v0zgq"; }; installPhase = '' mkdir -p $out/ cp -R . $out/ rm -r $out/config ln -sf ${varDir}/config $out/config ''; passthru = { apps = []; inherit buildApp withApps varDir; }; meta = { description = "Sharing solution for files, calendars, contacts and more"; homepage = https://nextcloud.com; maintainers = with lib.maintainers; [ schneefux bachp globin fpletz ]; license = lib.licenses.agpl3Plus; platforms = with lib.platforms; unix; }; }; in package