]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - pkgs/webapps/peertube/default.nix
Upgrade nixos-unstable
[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 = "12415ss4fxxafp3w8rxp2jbb16y0d7f01b7wv72nmy3cwiqxqkhn";
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 node_module_version = "72";
47 bcrypt_lib = fetchurl {
48 url = "https://github.com/kelektiv/node.bcrypt.js/releases/download/v3.0.7/bcrypt_lib-v3.0.7-node-v${node_module_version}-linux-x64-glibc.tar.gz";
49 sha256 = "0kpm9j0yc4lqsafldfsql3m72rr1fapljlb6ddxvy3zi13rb7ppx";
50 };
51 in
52 ''
53 if [ "$(node -e "console.log(process.versions.modules)")" != "${node_module_version}" ]; then
54 echo "mismatching version with nodejs please update bcrypt derivation"
55 false
56 fi
57 mkdir lib && tar -C lib -xf ${bcrypt_lib}
58 patchShebangs ../node-pre-gyp
59 npm run install
60 '';
61 };
62 dtrace-provider = {
63 buildInputs = [ python nodePackages.node-gyp ];
64 postInstall = ''
65 npx node-gyp rebuild --tarball=${nodeHeaders}
66 '';
67 };
68 node-sass = {
69 buildInputs = [ libsass python ];
70 postInstall =
71 ''
72 node scripts/build.js --tarball=${nodeHeaders}
73 '';
74 };
75
76 sharp = {
77 buildInputs = [ python nodePackages.node-gyp ];
78 postInstall =
79 let
80 tarball = fetchurl {
81 url = "https://github.com/lovell/sharp-libvips/releases/download/v8.8.1/libvips-8.8.1-linux-x64.tar.gz";
82 sha256 = "0xqv61g6s6rkvc31zq9a3bf8rp56ijnpw0xhr91hc88asqprd5yh";
83 };
84 in
85 ''
86 mkdir vendor
87 tar -C vendor -xf ${tarball}
88 patchShebangs ../prebuild-install
89 npx node install/libvips
90 npx node install/dll-copy
91 npx prebuild-install || npx node-gyp rebuild --tarball=${nodeHeaders}
92 '';
93 };
94 utf-8-validate = {
95 buildInputs = [ nodePackages.node-gyp-build ];
96 };
97 youtube-dl = {
98 postInstall = ''
99 mkdir bin
100 ln -s ${youtube-dl}/bin/youtube-dl bin/youtube-dl
101 cat > bin/details <<EOF
102 {"version":"${youtube-dl.version}","path":null,"exec":"youtube-dl"}
103 EOF
104 '';
105 };
106 };
107 serverYarnModulesArg = rec {
108 pname = "peertube-server-yarn-modules";
109 version = source.version;
110 name = "${pname}-${version}";
111 packageJSON = "${serverPatchedPackage}/package.json";
112 yarnLock = "${serverPatchedPackage}/yarn.lock";
113 yarnNix = ./server-yarn-packages.nix;
114 pkgConfig = yarnModulesConfig;
115 };
116 clientYarnModulesArg = rec {
117 pname = "peertube-client-yarn-modules";
118 version = source.version;
119 name = "${pname}-${version}";
120 packageJSON = "${clientPatchedPackage}/package.json";
121 yarnLock = "${clientPatchedPackage}/yarn.lock";
122 yarnNix = ./client-yarn-packages.nix;
123 pkgConfig = yarnModulesConfig;
124 };
125 yarnModulesNoWorkspace = args: (yarn2nix-moretea.mkYarnModules args).overrideAttrs(old: {
126 buildPhase = builtins.replaceStrings [" ./package.json"] [" /dev/null; cp deps/*/package.json ."] old.buildPhase;
127 });
128
129 patchedPackages = stdenv.mkDerivation (source // rec {
130 patches = if ldap then [ ./ldap.patch ] else [ ./yarn_fix_http_node.patch ];
131 installPhase = ''
132 mkdir $out
133 cp package.json yarn.lock $out/
134 '';
135 });
136 serverYarnModules = yarnModulesNoWorkspace serverYarnModulesArg;
137 serverYarnModulesProd = yarnModulesNoWorkspace (serverYarnModulesArg // { yarnFlags = yarn2nix-moretea.defaultYarnFlags ++ [ "--production" ]; });
138 clientYarnModules = yarnModulesNoWorkspace clientYarnModulesArg;
139
140 server = stdenv.mkDerivation ({
141 pname = "peertube-server";
142 version = source.version;
143 src = patchedSource;
144 buildPhase = ''
145 ln -s ${serverYarnModules}/node_modules .
146 npm run build:server
147 '';
148 installPhase = ''
149 mkdir $out
150 cp -a dist $out
151 '';
152 buildInputs = [ nodejs serverYarnModules ];
153 });
154
155 client = stdenv.mkDerivation ({
156 pname = "peertube-client";
157 version = source.version;
158 src = patchedSource;
159 buildPhase = let
160 lightArg = if light == null then "" else if light == true then "--light" else "--light-language";
161 in ''
162 ln -s ${serverYarnModules}/node_modules .
163 cp -a ${clientYarnModules}/node_modules client/
164 chmod +w client/node_modules
165 patchShebangs .
166 npm run build:client -- ${lightArg}
167 '';
168 installPhase = ''
169 mkdir $out
170 cp -a client/dist $out
171 '';
172 buildInputs = [ nodejs clientYarnModules ];
173 });
174
175 package = stdenv.mkDerivation rec {
176 version = source.version;
177 pname = "peertube";
178 src = patchedSource;
179 buildPhase = ''
180 ln -s ${serverYarnModulesProd}/node_modules .
181 ln -s ${clientYarnModules}/node_modules client/
182 rm -rf dist && cp -a ${server}/dist dist
183 rm -rf client/dist && cp -a ${client}/dist client/
184 '';
185 installPhase = ''
186 mkdir $out
187 cp -a * $out
188 ln -s /tmp $out/.cache
189 '';
190
191 meta = {
192 description = "A free software to take back control of your videos";
193
194 longDescription = ''
195 PeerTube aspires to be a decentralized and free/libre alternative to video
196 broadcasting services.
197 PeerTube is not meant to become a huge platform that would centralize
198 videos from all around the world. Rather, it is a network of
199 inter-connected small videos hosters.
200 Anyone with a modicum of technical skills can host a PeerTube server, aka
201 an instance. Each instance hosts its users and their videos. In this way,
202 every instance is created, moderated and maintained independently by
203 various administrators.
204 You can still watch from your account videos hosted by other instances
205 though if the administrator of your instance had previously connected it
206 with other instances.
207 '';
208
209 license = stdenv.lib.licenses.agpl3Plus;
210
211 homepage = "https://joinpeertube.org/";
212
213 platforms = stdenv.lib.platforms.linux; # not sure here
214 maintainers = with stdenv.lib.maintainers; [ matthiasbeyer immae ];
215 };
216 };
217 in
218 package