]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - pkgs/webapps/nextcloud/default.nix
Add flake skeletons
[perso/Immae/Config/Nix.git] / pkgs / webapps / nextcloud / default.nix
1 { varDir ? "/var/lib/nextcloud", nextcloudVersion, otherConfig ? {}, lib, stdenv, callPackage, fetchzip, fetchurl }:
2 let
3 shasumsAndVersion = {
4 "20" = { sum = "0rwky0d5i5glck5xxfsa9ygd0v2wf58k2q4ipmyvgq4rki2jqr89"; fullVersion = "20.0.14"; };
5 "21" = { sum = "1dqk2lpqc08qld8znp5vpcm8j8j8spfgvl8ax9faxpmmdrcj34sr"; fullVersion = "21.0.7"; };
6 "22" = { sum = "0allxfcnhh4bkp4s66b47smsn7y9qxlcnxxnxnmw0f0795m9m8k6"; fullVersion = "22.2.3"; };
7 "23" = { sum = "0b0ss1svxyg3kfbymhn85zspmf0lyhj1la2rhk98yp5nqfmr4xf3"; fullVersion = "23.0.0"; };
8 };
9 appNames = [
10 "apporder" "audioplayer" "bookmarks" "calendar" "carnet" "circles"
11 "contacts" "cookbook" "deck" "external" "extract" "files_markdown" "files_mindmap"
12 "files_readmemd" "flowupload" "gpxedit" "gpxpod" "groupfolders" "impersonate"
13 "keeweb" "maps" "metadata" "music" "notes" "ocsms" "onlyoffice" "passman" "polls"
14 "social" "spreed" "talk_matterbridge" "tasks" "drawio"
15 ];
16 toApp = name: callPackage (./apps + "/${name}.nix") { inherit buildApp nextcloudVersion; };
17 allSupportedApps = lib.mapAttrs (n: v: v.value) (lib.filterAttrs (n: v: v.success) (lib.genAttrs appNames (name: builtins.tryEval (toApp name))));
18 allApps = lib.genAttrs appNames toApp;
19 buildApp = { appName, version, url, sha256, installHook ? (n: ""), otherConfig ? {}, installPhase ? "mkdir -p $out && cp -R . $out/" }:
20 stdenv.mkDerivation rec {
21 name = "nextcloud-app-${appName}-${version}";
22 inherit version;
23 phases = "unpackPhase installPhase";
24 inherit installPhase;
25 src = fetchurl { inherit url sha256; };
26 passthru = {
27 inherit appName otherConfig installHook;
28 };
29 };
30 toPassthru = pkg: apps: otherConfig: {
31 inherit apps otherConfig allApps allSupportedApps buildApp varDir;
32 withApps = withApps pkg;
33 };
34 withApps = pkg: toApps:
35 let
36 apps = toApps allApps;
37 toInstallApp = n: ''
38 if [ -e $out/apps/${n.appName} ]; then
39 echo "${n.appName} already exists"
40 false
41 fi
42 ln -sf ${n} $out/apps/${n.appName}
43 '' + (n.installHook n);
44 zipped = lib.attrsets.zipAttrs ([pkg.otherConfig or {}] ++ map (v: v.otherConfig) apps);
45 appConfigs = with lib.attrsets; with lib.lists; {
46 mimetypealiases = foldr (h: prev: prev // h) {} (zipped.mimetypealiases or []);
47 mimetypemapping = mapAttrs (_: v: unique (flatten v)) (zipAttrs (zipped.mimetypemapping or []));
48 };
49 newNextcloud = pkg.overrideAttrs(old: {
50 installPhase = old.installPhase + "\n" + builtins.concatStringsSep "\n" (map toInstallApp apps);
51 passthru = toPassthru newNextcloud (pkg.apps ++ apps) appConfigs;
52 });
53 in newNextcloud;
54 package = stdenv.mkDerivation rec {
55 name = "nextcloud-${version}";
56 version = shasumsAndVersion."${builtins.toString nextcloudVersion}".fullVersion;
57
58 src = fetchurl {
59 url = "https://download.nextcloud.com/server/releases/${name}.tar.bz2";
60 sha256 = shasumsAndVersion."${builtins.toString nextcloudVersion}".sum;
61 };
62
63 installPhase = ''
64 mkdir -p $out/
65 cp -R . $out/
66 sed -i -e "/'appDirsWithDifferentOwner'/d" $out/apps/settings/lib/Controller/CheckSetupController.php
67 rm -r $out/config
68 '' + lib.optionalString (varDir != null) ''
69 ln -sf ${varDir}/config $out/config
70 '';
71
72 passthru = toPassthru package [] otherConfig;
73 meta = {
74 description = "Sharing solution for files, calendars, contacts and more";
75 homepage = https://nextcloud.com;
76 maintainers = with lib.maintainers; [ schneefux bachp globin fpletz ];
77 license = lib.licenses.agpl3Plus;
78 platforms = with lib.platforms; unix;
79 };
80 };
81 in package