aboutsummaryrefslogtreecommitdiff
path: root/pkgs/webapps/nextcloud/default.nix
blob: 12134943cf746683946c3b956f2fd056ca11b586 (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
64
65
66
67
{ varDir ? "/var/lib/nextcloud", nextcloudVersion ? 18, otherConfig ? {}, lib, stdenv, callPackage, fetchzip, fetchurl }:
let
  appNames = [
    "apporder" "audioplayer" "bookmarks" "calendar" "carnet" "contacts"
    "cookbook" "deck" "extract" "files_markdown" "files_readmemd"
    "flowupload" "gpxedit" "gpxpod" "keeweb" "maps" "metadata" "music"
    "notes" "ocsms" "passman" "polls" "spreed" "tasks"
  ];
  allApps = lib.attrsets.genAttrs appNames
    (name: callPackage (./apps + "/${name}.nix") { inherit buildApp nextcloudVersion; });
  buildApp = { appName, version, url, sha256, zip ? false, otherConfig ? {}, installPhase ? "mkdir -p $out && cp -R . $out/" }:
    stdenv.mkDerivation rec {
      name = "nextcloud-app-${appName}-${version}";
      inherit version;
      phases = "unpackPhase installPhase";
      inherit installPhase;
      src = (if zip then fetchzip else fetchurl) { inherit url sha256; };
      passthru = {
        inherit appName otherConfig;
      };
    };
  toPassthru = pkg: apps: otherConfig: {
    inherit apps otherConfig allApps buildApp varDir;
    withApps = withApps pkg;
  };
  withApps = pkg: toApps:
    let
      apps = toApps allApps;
      toInstallApp = n: ''
        ln -sf ${n} $out/apps/${n.appName}
      '';
      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 = "${builtins.toString nextcloudVersion}.0.4";

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

    installPhase = ''
      mkdir -p $out/
      cp -R . $out/
      rm -r $out/config
      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