--- /dev/null
+{ varDir ? "/var/lib/nextcloud", nextcloudVersion, otherConfig ? {}, lib, stdenv, callPackage, fetchzip, fetchurl }:
+let
+ shasumsAndVersion = {
+ "20" = { sum = "0rwky0d5i5glck5xxfsa9ygd0v2wf58k2q4ipmyvgq4rki2jqr89"; fullVersion = "20.0.14"; };
+ "21" = { sum = "1dqk2lpqc08qld8znp5vpcm8j8j8spfgvl8ax9faxpmmdrcj34sr"; fullVersion = "21.0.7"; };
+ "22" = { sum = "0allxfcnhh4bkp4s66b47smsn7y9qxlcnxxnxnmw0f0795m9m8k6"; fullVersion = "22.2.3"; };
+ "23" = { sum = "0b0ss1svxyg3kfbymhn85zspmf0lyhj1la2rhk98yp5nqfmr4xf3"; fullVersion = "23.0.0"; };
+ };
+ appNames = [
+ "apporder" "audioplayer" "bookmarks" "calendar" "carnet" "circles"
+ "contacts" "cookbook" "deck" "external" "extract" "files_markdown" "files_mindmap"
+ "files_readmemd" "flowupload" "gpxedit" "gpxpod" "groupfolders" "impersonate"
+ "keeweb" "maps" "metadata" "music" "notes" "ocsms" "onlyoffice" "passman" "polls"
+ "social" "spreed" "talk_matterbridge" "tasks" "drawio"
+ ];
+ toApp = name: callPackage (./apps + "/${name}.nix") { inherit buildApp nextcloudVersion; };
+ allSupportedApps = lib.mapAttrs (n: v: v.value) (lib.filterAttrs (n: v: v.success) (lib.genAttrs appNames (name: builtins.tryEval (toApp name))));
+ allApps = lib.genAttrs appNames toApp;
+ buildApp = { appName, version, url, sha256, installHook ? (n: ""), otherConfig ? {}, 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 = {
+ inherit appName otherConfig installHook;
+ };
+ };
+ toPassthru = pkg: apps: otherConfig: {
+ inherit apps otherConfig allApps allSupportedApps buildApp varDir;
+ withApps = withApps pkg;
+ };
+ withApps = pkg: toApps:
+ let
+ apps = toApps allApps;
+ toInstallApp = n: ''
+ if [ -e $out/apps/${n.appName} ]; then
+ echo "${n.appName} already exists"
+ false
+ fi
+ ln -sf ${n} $out/apps/${n.appName}
+ '' + (n.installHook n);
+ zipped = lib.attrsets.zipAttrs ([pkg.otherConfig or {}] ++ map (v: v.otherConfig) apps);
+ appConfigs = with lib.attrsets; with lib.lists; {
+ mimetypealiases = foldr (h: prev: prev // h) {} (zipped.mimetypealiases or []);
+ mimetypemapping = mapAttrs (_: v: unique (flatten v)) (zipAttrs (zipped.mimetypemapping or []));
+ };
+ newNextcloud = pkg.overrideAttrs(old: {
+ installPhase = old.installPhase + "\n" + builtins.concatStringsSep "\n" (map toInstallApp apps);
+ passthru = toPassthru newNextcloud (pkg.apps ++ apps) appConfigs;
+ });
+ in newNextcloud;
+ package = stdenv.mkDerivation rec {
+ name = "nextcloud-${version}";
+ version = shasumsAndVersion."${builtins.toString nextcloudVersion}".fullVersion;
+
+ src = fetchurl {
+ url = "https://download.nextcloud.com/server/releases/${name}.tar.bz2";
+ sha256 = shasumsAndVersion."${builtins.toString nextcloudVersion}".sum;
+ };
+
+ installPhase = ''
+ mkdir -p $out/
+ cp -R . $out/
+ sed -i -e "/'appDirsWithDifferentOwner'/d" $out/apps/settings/lib/Controller/CheckSetupController.php
+ rm -r $out/config
+ '' + lib.optionalString (varDir != null) ''
+ ln -sf ${varDir}/config $out/config
+ '';
+
+ passthru = toPassthru package [] otherConfig;
+ 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