summaryrefslogtreecommitdiff
path: root/pkgs/webapps/peertube/default.nix
blob: 89954192e381d16b3ddb152bebecfcd8c5795484 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
{ ldap ? false
, lib, stdenv, fetchzip, youtube-dl, fetchurl, mylibs, python, nodejs, nodePackages }:
let
  nodeHeaders = fetchurl {
    url = "https://nodejs.org/download/release/v${nodejs.version}/node-v${nodejs.version}-headers.tar.gz";
    sha256 = "1g6zi96k8sbim8wa8rzskxy44mgpcv1mn2bs8p4mq36w3kwglwyj";
  };
  patchedPackages = stdenv.mkDerivation (mylibs.fetchedGithub ./peertube.json // rec {
    patches = if ldap then [ ./ldap.patch ././yarn_fix_bluebird_ldap.patch ] else [ ./yarn_fix_bluebird.patch ];
    installPhase = ''
      mkdir $out
      cp package.json yarn.lock $out/
      '';
  });
  # if yarn complains about
  #   TypeError: Cannot read property 'lang' of undefined yarn
  #   make sure that all package names in yarn-packages.nix finish in
  #   .tar.gz where due (especially jsonld-signatures)
  # Most errors where due to jsonld-signature (name, git version, etc.)
  #   or bluebird (3.5.18 instead vs 3.5.21)
  yarnModulesArg = rec {
    pname = "peertube-yarn-modules";
    version = "1.2.0";
    name = "peertube-yarn-modules-${version}";
    packageJSON = "${patchedPackages}/package.json";
    yarnLock = "${patchedPackages}/yarn.lock";
    yarnNix = ./yarn-packages.nix;
    pkgConfig = {
      all = {
        buildInputs = [ mylibs.yarn2nixPackage.src ];
      };
      bcrypt = {
        buildInputs = [ nodePackages.node-pre-gyp ];
        postInstall = let
          bcrypt_lib = fetchurl {
            url = "https://github.com/kelektiv/node.bcrypt.js/releases/download/v3.0.2/bcrypt_lib-v3.0.2-node-v64-linux-x64-glibc.tar.gz";
            sha256 = "0i0dx4h52fqi3mda2zzqrxp2fh7spbvf7h88mjk218h8d7vl53yx";
          };
        in
          ''
            mkdir lib && tar -C lib -xf ${bcrypt_lib}
            patchShebangs ../node-pre-gyp
            npm run install
          '';
      };
      dtrace-provider = {
        buildInputs = [ python nodePackages.node-gyp ];
        postInstall = ''
          npx node-gyp rebuild --tarball=${nodeHeaders}
          '';
      };
      rdf-canonize = {
        buildInputs = [ python nodePackages.node-gyp ];
        postInstall = ''
          npx node-gyp rebuild --tarball=${nodeHeaders}
          '';
      };
      sharp = {
        buildInputs = [ python nodePackages.node-gyp ];
        postInstall =
          let
            tarball = fetchurl {
              url = "https://github.com/lovell/sharp-libvips/releases/download/v8.7.0/libvips-8.7.0-linux-x64.tar.gz";
              sha256 = "1sq7qrp1q1pcrd165c3sky7qjx1kqihfpr4ailb5k73rwyh8lxg4";
            };
          in
          ''
            mkdir vendor
            tar -C vendor -xf ${tarball}
            patchShebangs ../prebuild-install
            npx node install/libvips
            npx node install/dll-copy
            npx prebuild-install || npx node-gyp rebuild --tarball=${nodeHeaders}
          '';
      };
      utf-8-validate = {
        buildInputs = [ nodePackages.node-gyp-build ];
      };
      youtube-dl = {
        postInstall = ''
          mkdir bin
          ln -s ${youtube-dl}/bin/youtube-dl bin/youtube-dl
          cat > bin/details <<EOF
          {"version":"${youtube-dl.version}","path":null,"exec":"youtube-dl"}
          EOF
          '';
      };
    };
  };
  yarnModules = mylibs.yarn2nixPackage.mkYarnModules yarnModulesArg;
  yarnModulesProd = mylibs.yarn2nixPackage.mkYarnModules (yarnModulesArg // { yarnFlags = mylibs.yarn2nixPackage.defaultYarnFlags ++ [ "--production" ]; });
  patchedServer = stdenv.mkDerivation (mylibs.fetchedGithub ./peertube.json // rec {
    patches = lib.optionals ldap [ ./ldap.patch ] ++ [ ./sendmail.patch ];
    buildPhase = ''
      ln -s ${yarnModules}/node_modules .
      npm run build:server
      '';
    installPhase = ''
      mkdir $out
      cp -a dist/server $out
      '';
    buildInputs = [ nodejs yarnModules ];
  });
in
  stdenv.mkDerivation rec {
    version = "v1.2.0";
    name = "peertube-${version}";
    src = fetchzip {
      url = "https://github.com/Chocobozzz/PeerTube/releases/download/${version}/${name}.zip";
      sha256 = "18fp3fy1crw67gdpc29nr38b5zy2f68l70w47zwp7dzhd8bbbipp";
    };
    patches = lib.optionals ldap [ ./ldap_yarn.patch ];
    buildPhase = ''
      ln -s ${yarnModulesProd}/node_modules .
      rm -rf dist/server && cp -a ${patchedServer}/server dist
      '';
    installPhase = ''
      mkdir $out
      cp -a * $out
      ln -s /tmp $out/.cache
      '';
    buildInputs = [ yarnModulesProd ];
  }