aboutsummaryrefslogtreecommitdiff
path: root/pkgs/cryptpad/default.nix
blob: 1e8c756832862c600e72ed94744dd0e90b3dcbb0 (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
68
69
70
# taken from nixpkgs to upgrade to latest version
{ stdenv
, pkgs
, lib
, buildBowerComponents
, fetchurl
, nodejs
}:

let
  nodePackages = import ./node-packages.nix {
    inherit pkgs nodejs;
    inherit (stdenv.hostPlatform) system;
  };

  bowerPackages = buildBowerComponents {
    name = "${cryptpad.name}-bower-packages";
    # this list had to be tweaked by hand:
    # * add the second jquery ~2.1.0 entry
    # * add the second bootstrap ~3.1.1 entry
    generated = ./bower-packages.nix;
    src = cryptpad.src;
  };

  # find an element in an attribute set
  findValue = pred: default: set:
    let
      list =
        lib.concatMap
        (name:
          let v = set.${name}; in
          if pred name v then [v] else []
        )
        (lib.attrNames set)
        ;
    in
      if list == [] then default
      else lib.head list
      ;

  # The cryptpad package attribute key changes for each release. Get it out
  # programatically instead.
  cryptpad = findValue
    (k: v: v.packageName == "cryptpad")
    (throw "cryptpad not found")
    nodePackages
    ;

  combined = cryptpad.override {
    postInstall = ''
      out_cryptpad=$out/lib/node_modules/cryptpad

      substituteInPlace $out_cryptpad/lib/workers/index.js --replace "lib/workers/db-worker" "$out_cryptpad/lib/workers/db-worker"

      # add the bower components
      ln -sv \
        ${bowerPackages}/bower_components \
        $out_cryptpad/www/bower_components

      # add executable
      mkdir $out/bin
      cat <<EOF > $out/bin/cryptpad
      #!${stdenv.shell}
      exec ${nodejs}/bin/node $out_cryptpad/server.js
      EOF
      chmod +x $out/bin/cryptpad
    '';
  };
in
  combined