aboutsummaryrefslogtreecommitdiff
path: root/pkgs/webapps/peertube/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/webapps/peertube/default.nix')
-rw-r--r--pkgs/webapps/peertube/default.nix284
1 files changed, 187 insertions, 97 deletions
diff --git a/pkgs/webapps/peertube/default.nix b/pkgs/webapps/peertube/default.nix
index 9929106..7889cee 100644
--- a/pkgs/webapps/peertube/default.nix
+++ b/pkgs/webapps/peertube/default.nix
@@ -1,123 +1,213 @@
1{ ldap ? false 1{ ldap ? false, sendmail ? false, light ? null, runCommand, libsass
2, lib, stdenv, fetchzip, youtube-dl, fetchurl, mylibs, python, nodejs, nodePackages }: 2, lib, stdenv, rsync, fetchzip, youtube-dl, fetchurl, mylibs, python, nodejs, nodePackages, yarn2nix-moretea }:
3let 3let
4 nodeHeaders = fetchurl { 4 nodeHeaders = fetchurl {
5 url = "https://nodejs.org/download/release/v${nodejs.version}/node-v${nodejs.version}-headers.tar.gz"; 5 url = "https://nodejs.org/download/release/v${nodejs.version}/node-v${nodejs.version}-headers.tar.gz";
6 sha256 = "1df3yhlwlvai0m9kvjyknjg11hnw0kj0rnhyzbwvsfjnmr6z8r76"; 6 sha256 = "1df3yhlwlvai0m9kvjyknjg11hnw0kj0rnhyzbwvsfjnmr6z8r76";
7 }; 7 };
8 patchedPackages = stdenv.mkDerivation (mylibs.fetchedGithub ./peertube.json // rec { 8 source = mylibs.fetchedGithub ./peertube.json;
9 patches = if ldap then [ ./ldap.patch ././yarn_fix_bluebird_ldap.patch ] else [ ./yarn_fix_bluebird.patch ]; 9 patchedSource = stdenv.mkDerivation (source // rec {
10 installPhase = '' 10 phases = [ "unpackPhase" "patchPhase" "installPhase" ];
11 patches = [ ./yarn_fix_http_node.patch ] ++ lib.optionals ldap [ ./ldap.patch ] ++ lib.optionals sendmail [ ./sendmail.patch ];
12 installPhase = let
13 # Peertube supports several languages, but they take a very long
14 # time to build. The build script accepts --light which builds
15 # only English, and --light-fr which only builds English + French.
16 # This small hack permits to builds only English + A chosen
17 # language depending on the value of "light"
18 # Default (null) is to build every language
19 lightFix = if light == true || light == null then "" else ''
20 sed -i -e "s/fr-FR/${light}/g" -e "s/--light-fr/--light-language/" $out/scripts/build/client.sh
21 '';
22 in ''
11 mkdir $out 23 mkdir $out
12 cp package.json yarn.lock $out/ 24 cp -a . $out/
25 ${lightFix}
13 ''; 26 '';
14 }); 27 });
15 # if yarn complains about 28 serverPatchedPackage = runCommand "server-package" {} ''
16 # TypeError: Cannot read property 'lang' of undefined yarn 29 mkdir -p $out
17 # make sure that all package names in yarn-packages.nix finish in 30 cp ${patchedSource}/package.json $out/
18 # .tar.gz where due (especially jsonld-signatures) 31 cp ${patchedSource}/yarn.lock $out/
19 # Most errors where due to jsonld-signature (name, git version, etc.) 32 '';
20 # or bluebird (3.5.18 instead vs 3.5.21) 33 clientPatchedPackage = runCommand "client-package" {} ''
21 yarnModulesArg = rec { 34 mkdir -p $out
22 pname = "peertube-yarn-modules"; 35 cp ${patchedSource}/client/package.json $out/
23 version = "1.2.0"; 36 cp ${patchedSource}/client/yarn.lock $out/
24 name = "peertube-yarn-modules-${version}"; 37 '';
25 packageJSON = "${patchedPackages}/package.json"; 38
26 yarnLock = "${patchedPackages}/yarn.lock"; 39 yarnModulesConfig = {
27 yarnNix = ./yarn-packages.nix; 40 # all = {
28 pkgConfig = { 41 # buildInputs = [ yarn2nix-moretea.yarn2nix.src ];
29 all = { 42 # };
30 buildInputs = [ mylibs.yarn2nixPackage.src ]; 43 bcrypt = {
31 }; 44 buildInputs = [ nodePackages.node-pre-gyp ];
32 bcrypt = { 45 postInstall = let
33 buildInputs = [ nodePackages.node-pre-gyp ]; 46 bcrypt_lib = fetchurl {
34 postInstall = let 47 url = "https://github.com/kelektiv/node.bcrypt.js/releases/download/v3.0.7/bcrypt_lib-v3.0.7-node-v64-linux-x64-glibc.tar.gz";
35 bcrypt_lib = fetchurl { 48 sha256 = "0gbq4grhp5wl0f9yqb4y43kjfh8nivfd6y0nkv1x6gfvs2v23wb0";
36 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"; 49 };
37 sha256 = "0i0dx4h52fqi3mda2zzqrxp2fh7spbvf7h88mjk218h8d7vl53yx"; 50 in
51 ''
52 mkdir lib && tar -C lib -xf ${bcrypt_lib}
53 patchShebangs ../node-pre-gyp
54 npm run install
55 '';
56 };
57 dtrace-provider = {
58 buildInputs = [ python nodePackages.node-gyp ];
59 postInstall = ''
60 npx node-gyp rebuild --tarball=${nodeHeaders}
61 '';
62 };
63 node-sass = {
64 buildInputs = [ libsass python ];
65 postInstall =
66 ''
67 node scripts/build.js --tarball=${nodeHeaders}
68 '';
69 };
70
71 sharp = {
72 buildInputs = [ python nodePackages.node-gyp ];
73 postInstall =
74 let
75 tarball = fetchurl {
76 url = "https://github.com/lovell/sharp-libvips/releases/download/v8.8.1/libvips-8.8.1-linux-x64.tar.gz";
77 sha256 = "0xqv61g6s6rkvc31zq9a3bf8rp56ijnpw0xhr91hc88asqprd5yh";
38 }; 78 };
39 in 79 in
40 '' 80 ''
41 mkdir lib && tar -C lib -xf ${bcrypt_lib} 81 mkdir vendor
42 patchShebangs ../node-pre-gyp 82 tar -C vendor -xf ${tarball}
43 npm run install 83 patchShebangs ../prebuild-install
44 ''; 84 npx node install/libvips
45 }; 85 npx node install/dll-copy
46 dtrace-provider = { 86 npx prebuild-install || npx node-gyp rebuild --tarball=${nodeHeaders}
47 buildInputs = [ python nodePackages.node-gyp ]; 87 '';
48 postInstall = '' 88 };
49 npx node-gyp rebuild --tarball=${nodeHeaders} 89 utf-8-validate = {
50 ''; 90 buildInputs = [ nodePackages.node-gyp-build ];
51 };
52 rdf-canonize = {
53 buildInputs = [ python nodePackages.node-gyp ];
54 postInstall = ''
55 npx node-gyp rebuild --tarball=${nodeHeaders}
56 '';
57 };
58 sharp = {
59 buildInputs = [ python nodePackages.node-gyp ];
60 postInstall =
61 let
62 tarball = fetchurl {
63 url = "https://github.com/lovell/sharp-libvips/releases/download/v8.7.0/libvips-8.7.0-linux-x64.tar.gz";
64 sha256 = "1sq7qrp1q1pcrd165c3sky7qjx1kqihfpr4ailb5k73rwyh8lxg4";
65 };
66 in
67 ''
68 mkdir vendor
69 tar -C vendor -xf ${tarball}
70 patchShebangs ../prebuild-install
71 npx node install/libvips
72 npx node install/dll-copy
73 npx prebuild-install || npx node-gyp rebuild --tarball=${nodeHeaders}
74 '';
75 };
76 utf-8-validate = {
77 buildInputs = [ nodePackages.node-gyp-build ];
78 };
79 youtube-dl = {
80 postInstall = ''
81 mkdir bin
82 ln -s ${youtube-dl}/bin/youtube-dl bin/youtube-dl
83 cat > bin/details <<EOF
84 {"version":"${youtube-dl.version}","path":null,"exec":"youtube-dl"}
85 EOF
86 '';
87 };
88 }; 91 };
92 youtube-dl = {
93 postInstall = ''
94 mkdir bin
95 ln -s ${youtube-dl}/bin/youtube-dl bin/youtube-dl
96 cat > bin/details <<EOF
97 {"version":"${youtube-dl.version}","path":null,"exec":"youtube-dl"}
98 EOF
99 '';
100 };
101 };
102 serverYarnModulesArg = rec {
103 pname = "peertube-server-yarn-modules";
104 version = source.version;
105 name = "${pname}-${version}";
106 packageJSON = "${serverPatchedPackage}/package.json";
107 yarnLock = "${serverPatchedPackage}/yarn.lock";
108 yarnNix = ./server-yarn-packages.nix;
109 pkgConfig = yarnModulesConfig;
89 }; 110 };
90 yarnModules = mylibs.yarn2nixPackage.mkYarnModules yarnModulesArg; 111 clientYarnModulesArg = rec {
91 yarnModulesProd = mylibs.yarn2nixPackage.mkYarnModules (yarnModulesArg // { yarnFlags = mylibs.yarn2nixPackage.defaultYarnFlags ++ [ "--production" ]; }); 112 pname = "peertube-client-yarn-modules";
92 patchedServer = stdenv.mkDerivation (mylibs.fetchedGithub ./peertube.json // rec { 113 version = source.version;
93 patches = lib.optionals ldap [ ./ldap.patch ] ++ [ ./sendmail.patch ]; 114 name = "${pname}-${version}";
115 packageJSON = "${clientPatchedPackage}/package.json";
116 yarnLock = "${clientPatchedPackage}/yarn.lock";
117 yarnNix = ./client-yarn-packages.nix;
118 pkgConfig = yarnModulesConfig;
119 };
120 yarnModulesNoWorkspace = args: (yarn2nix-moretea.mkYarnModules args).overrideAttrs(old: {
121 buildPhase = builtins.replaceStrings [" ./package.json"] [" /dev/null; cp deps/*/package.json ."] old.buildPhase;
122 });
123
124 patchedPackages = stdenv.mkDerivation (source // rec {
125 patches = if ldap then [ ./ldap.patch ] else [ ./yarn_fix_http_node.patch ];
126 installPhase = ''
127 mkdir $out
128 cp package.json yarn.lock $out/
129 '';
130 });
131 serverYarnModules = yarnModulesNoWorkspace serverYarnModulesArg;
132 serverYarnModulesProd = yarnModulesNoWorkspace (serverYarnModulesArg // { yarnFlags = yarn2nix-moretea.defaultYarnFlags ++ [ "--production" ]; });
133 clientYarnModules = yarnModulesNoWorkspace clientYarnModulesArg;
134
135 server = stdenv.mkDerivation ({
136 pname = "peertube-server";
137 version = source.version;
138 src = patchedSource;
94 buildPhase = '' 139 buildPhase = ''
95 ln -s ${yarnModules}/node_modules . 140 ln -s ${serverYarnModules}/node_modules .
96 npm run build:server 141 npm run build:server
97 ''; 142 '';
98 installPhase = '' 143 installPhase = ''
99 mkdir $out 144 mkdir $out
100 cp -a dist/server $out 145 cp -a dist $out
101 ''; 146 '';
102 buildInputs = [ nodejs yarnModules ]; 147 buildInputs = [ nodejs serverYarnModules ];
103 }); 148 });
104in 149
105 stdenv.mkDerivation rec { 150 client = stdenv.mkDerivation ({
106 version = "v1.2.0"; 151 pname = "peertube-client";
107 name = "peertube-${version}"; 152 version = source.version;
108 src = fetchzip { 153 src = patchedSource;
109 url = "https://github.com/Chocobozzz/PeerTube/releases/download/${version}/${name}.zip"; 154 buildPhase = let
110 sha256 = "18fp3fy1crw67gdpc29nr38b5zy2f68l70w47zwp7dzhd8bbbipp"; 155 lightArg = if light == null then "" else if light == true then "--light" else "--light-language";
111 }; 156 in ''
112 patches = lib.optionals ldap [ ./ldap_yarn.patch ]; 157 ln -s ${serverYarnModules}/node_modules .
158 cp -a ${clientYarnModules}/node_modules client/
159 chmod +w client/node_modules
160 patchShebangs .
161 npm run build:client -- ${lightArg}
162 '';
163 installPhase = ''
164 mkdir $out
165 cp -a client/dist $out
166 '';
167 buildInputs = [ nodejs clientYarnModules ];
168 });
169
170 package = stdenv.mkDerivation rec {
171 version = source.version;
172 pname = "peertube";
173 src = patchedSource;
113 buildPhase = '' 174 buildPhase = ''
114 ln -s ${yarnModulesProd}/node_modules . 175 ln -s ${serverYarnModulesProd}/node_modules .
115 rm -rf dist/server && cp -a ${patchedServer}/server dist 176 ln -s ${clientYarnModules}/node_modules client/
177 rm -rf dist && cp -a ${server}/dist dist
178 rm -rf client/dist && cp -a ${client}/dist client/
116 ''; 179 '';
117 installPhase = '' 180 installPhase = ''
118 mkdir $out 181 mkdir $out
119 cp -a * $out 182 cp -a * $out
120 ln -s /tmp $out/.cache 183 ln -s /tmp $out/.cache
121 ''; 184 '';
122 buildInputs = [ yarnModulesProd ]; 185
123 } 186 meta = {
187 description = "A free software to take back control of your videos";
188
189 longDescription = ''
190 PeerTube aspires to be a decentralized and free/libre alternative to video
191 broadcasting services.
192 PeerTube is not meant to become a huge platform that would centralize
193 videos from all around the world. Rather, it is a network of
194 inter-connected small videos hosters.
195 Anyone with a modicum of technical skills can host a PeerTube server, aka
196 an instance. Each instance hosts its users and their videos. In this way,
197 every instance is created, moderated and maintained independently by
198 various administrators.
199 You can still watch from your account videos hosted by other instances
200 though if the administrator of your instance had previously connected it
201 with other instances.
202 '';
203
204 license = stdenv.lib.licenses.agpl3Plus;
205
206 homepage = "https://joinpeertube.org/";
207
208 platforms = stdenv.lib.platforms.linux; # not sure here
209 maintainers = with stdenv.lib.maintainers; [ matthiasbeyer immae ];
210 };
211 };
212in
213 package