aboutsummaryrefslogtreecommitdiff
path: root/pkgs/webapps/nextcloud/default.nix
blob: 2d4eb3909dcd5bb47300370b8b6b8fe06a22b584 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{ varDir ? "/var/lib/nextcloud", otherConfig ? {}, lib, stdenv, fetchurl }:
let
  buildApp = { appName, version, url, sha256, 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;
      };
    };
  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 = old.passthru // {
      otherConfig = with lib.attrsets; with lib.lists; let
        zipped = zipAttrs ([old.otherConfig or {}] ++ map (v: v.otherConfig) apps);
      in
        {
          mimetypealiases = foldr (h: prev: prev // h) {} zipped.mimetypealiases;
          mimetypemapping = mapAttrs (_: v: unique (flatten v)) (zipAttrs zipped.mimetypemapping);
        };
      inherit apps;
      withApps = moreApps: old.withApps (moreApps ++ apps);
    };
  });

  package = stdenv.mkDerivation rec {
    name = "nextcloud-${version}";
    version = "16.0.0";

    src = fetchurl {
      url = "https://download.nextcloud.com/server/releases/${name}.tar.bz2";
      sha256 = "0bj014vczlrql1w32pqmr7cyqn9awnyzpi2syxhg16qxic1gfcj5";
    };

    installPhase = ''
      mkdir -p $out/
      cp -R . $out/
      rm -r $out/config
      ln -sf ${varDir}/config $out/config
      '';

    passthru = {
      apps = [];
      inherit otherConfig 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