]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - pkgs/webapps/peertube/default.nix
Add syden peertube website
[perso/Immae/Config/Nix.git] / pkgs / webapps / peertube / default.nix
1 { ldap ? false, sendmail ? false, light ? null, syden ? false, runCommand, libsass
2 , lib, stdenv, rsync, fetchzip, youtube-dl, fetchurl, mylibs, python, nodejs, nodePackages, yarn2nix-moretea }:
3 let
4 nodeHeaders = fetchurl {
5 url = "https://nodejs.org/download/release/v${nodejs.version}/node-v${nodejs.version}-headers.tar.gz";
6 sha256 = "1df3yhlwlvai0m9kvjyknjg11hnw0kj0rnhyzbwvsfjnmr6z8r76";
7 };
8 source = mylibs.fetchedGithub ./peertube.json;
9 patchedSource = stdenv.mkDerivation (source // rec {
10 phases = [ "unpackPhase" "patchPhase" "installPhase" ];
11 patches = [ ./yarn_fix_http_node.patch ]
12 ++ lib.optionals ldap [ ./ldap.patch ]
13 ++ lib.optionals sendmail [ ./sendmail.patch ]
14 ++ lib.optionals syden [ ./syden.patch ];
15 installPhase = let
16 # Peertube supports several languages, but they take a very long
17 # time to build. The build script accepts --light which builds
18 # only English, and --light-fr which only builds English + French.
19 # This small hack permits to builds only English + A chosen
20 # language depending on the value of "light"
21 # Default (null) is to build every language
22 lightFix = if light == true || light == null then "" else ''
23 sed -i -e "s/fr-FR/${light}/g" -e "s/--light-fr/--light-language/" $out/scripts/build/client.sh
24 '';
25 in ''
26 mkdir $out
27 cp -a . $out/
28 ${lightFix}
29 '';
30 });
31 serverPatchedPackage = runCommand "server-package" {} ''
32 mkdir -p $out
33 cp ${patchedSource}/package.json $out/
34 cp ${patchedSource}/yarn.lock $out/
35 '';
36 clientPatchedPackage = runCommand "client-package" {} ''
37 mkdir -p $out
38 cp ${patchedSource}/client/package.json $out/
39 cp ${patchedSource}/client/yarn.lock $out/
40 '';
41
42 yarnModulesConfig = {
43 bcrypt = {
44 buildInputs = [ nodePackages.node-pre-gyp ];
45 postInstall = let
46 bcrypt_lib = fetchurl {
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";
48 sha256 = "0gbq4grhp5wl0f9yqb4y43kjfh8nivfd6y0nkv1x6gfvs2v23wb0";
49 };
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";
78 };
79 in
80 ''
81 mkdir vendor
82 tar -C vendor -xf ${tarball}
83 patchShebangs ../prebuild-install
84 npx node install/libvips
85 npx node install/dll-copy
86 npx prebuild-install || npx node-gyp rebuild --tarball=${nodeHeaders}
87 '';
88 };
89 utf-8-validate = {
90 buildInputs = [ nodePackages.node-gyp-build ];
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;
110 };
111 clientYarnModulesArg = rec {
112 pname = "peertube-client-yarn-modules";
113 version = source.version;
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;
139 buildPhase = ''
140 ln -s ${serverYarnModules}/node_modules .
141 npm run build:server
142 '';
143 installPhase = ''
144 mkdir $out
145 cp -a dist $out
146 '';
147 buildInputs = [ nodejs serverYarnModules ];
148 });
149
150 client = stdenv.mkDerivation ({
151 pname = "peertube-client";
152 version = source.version;
153 src = patchedSource;
154 buildPhase = let
155 lightArg = if light == null then "" else if light == true then "--light" else "--light-language";
156 in ''
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;
174 buildPhase = ''
175 ln -s ${serverYarnModulesProd}/node_modules .
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/
179 '';
180 installPhase = ''
181 mkdir $out
182 cp -a * $out
183 ln -s /tmp $out/.cache
184 '';
185
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 };
212 in
213 package