biome: 1.9.2 -> 1.9.3 (#349335)
[NixPkgs.git] / pkgs / servers / peertube / default.nix
bloba839feda1f0a89a0885a906b339421a2a6da4894
1 { lib
2 , stdenv
3 , callPackage
4 , fetchurl
5 , fetchFromGitHub
6 , fetchYarnDeps
7 , nixosTests
8 , brotli
9 , fixup-yarn-lock
10 , jq
11 , fd
12 , nodejs
13 , which
14 , yarn
16 let
17   bcryptHostPlatformAttrs = {
18     x86_64-linux = {
19       arch = "linux-x64";
20       libc = "glibc";
21       hash = "sha256-C5N6VgFtXPLLjZt0ZdRTX095njRIT+12ONuUaBBj7fQ=";
22     };
23     aarch64-linux = {
24       arch = "linux-arm64";
25       libc = "glibc";
26       hash = "sha256-TerDujO+IkSRnHYlSbAKSP9IS7AT7XnQJsZ8D8pCoGc=";
27     };
28     x86_64-darwin = {
29       arch = "darwin-x64";
30       libc = "unknown";
31       hash = "sha256-gphOONWujbeCCr6dkmMRJP94Dhp1Jvp2yt+g7n1HTv0=";
32     };
33     aarch64-darwin = {
34       arch = "darwin-arm64";
35       libc = "unknown";
36       hash = "sha256-JMnELVUxoU1C57Tzue3Sg6OfDFAjfCnzgDit0BWzmlo=";
37     };
38   };
39   bcryptAttrs = bcryptHostPlatformAttrs."${stdenv.hostPlatform.system}" or
40     (throw "Unsupported architecture: ${stdenv.hostPlatform.system}");
41   bcryptVersion = "5.1.1";
42   bcryptLib = fetchurl {
43     url = "https://github.com/kelektiv/node.bcrypt.js/releases/download/v${bcryptVersion}/bcrypt_lib-v${bcryptVersion}-napi-v3-${bcryptAttrs.arch}-${bcryptAttrs.libc}.tar.gz";
44     inherit (bcryptAttrs) hash;
45   };
47 stdenv.mkDerivation rec {
48   pname = "peertube";
49   version = "6.0.4";
51   src = fetchFromGitHub {
52     owner = "Chocobozzz";
53     repo = "PeerTube";
54     rev = "v${version}";
55     hash = "sha256-FxXIvibwdRcv8OaTQEXiM6CvWOIptfQXDQ1/PW910wg=";
56   };
58   yarnOfflineCacheServer = fetchYarnDeps {
59     yarnLock = "${src}/yarn.lock";
60     hash = "sha256-RJX92EgEIXWB1wNFRl8FvseOqBT+7m6gs+pMyoodruk=";
61   };
63   yarnOfflineCacheClient = fetchYarnDeps {
64     yarnLock = "${src}/client/yarn.lock";
65     hash = "sha256-vr9xn5NXwiUS59Kgl8olCtkMgxnI1TKQzibKbb8RNXA=";
66   };
68   yarnOfflineCacheAppsCli = fetchYarnDeps {
69     yarnLock = "${src}/apps/peertube-cli/yarn.lock";
70     hash = "sha256-xsB71bnaPn/9/f1KHyU3TTwx+Q+1dLjWmNK2aVJgoRY=";
71   };
73   yarnOfflineCacheAppsRunner = fetchYarnDeps {
74     yarnLock = "${src}/apps/peertube-runner/yarn.lock";
75     hash = "sha256-9w3aLuiLs7SU00YwuE0ixfiD77gCakXT4YeRpfsgGz0=";
76   };
78   outputs = [ "out" "cli" "runner" ];
80   nativeBuildInputs = [ brotli fixup-yarn-lock jq which yarn fd ];
82   buildInputs = [ nodejs ];
84   buildPhase = ''
85     # Build node modules
86     export HOME=$PWD
87     fixup-yarn-lock ~/yarn.lock
88     fixup-yarn-lock ~/client/yarn.lock
89     fixup-yarn-lock ~/apps/peertube-cli/yarn.lock
90     fixup-yarn-lock ~/apps/peertube-runner/yarn.lock
91     yarn config --offline set yarn-offline-mirror $yarnOfflineCacheServer
92     yarn install --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress
93     cd ~/client
94     yarn config --offline set yarn-offline-mirror $yarnOfflineCacheClient
95     yarn install --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress
96     cd ~/apps/peertube-cli
97     yarn config --offline set yarn-offline-mirror $yarnOfflineCacheAppsCli
98     yarn install --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress
99     cd ~/apps/peertube-runner
100     yarn config --offline set yarn-offline-mirror $yarnOfflineCacheAppsRunner
101     yarn install --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress
103     patchShebangs ~/{node_modules,client/node_modules,/apps/peertube-cli/node_modules,apps/peertube-runner/node_modules,scripts}
105     # Fix bcrypt node module
106     cd ~/node_modules/bcrypt
107     if [ "${bcryptVersion}" != "$(cat package.json | jq -r .version)" ]; then
108       echo "Mismatching version please update bcrypt in derivation"
109       exit
110     fi
111     mkdir -p ./lib/binding && tar -C ./lib/binding -xf ${bcryptLib}
113     # Return to home directory
114     cd ~
116     # Build PeerTube server
117     npm run build:server
119     # Build PeerTube client
120     npm run build:client
122     # Build PeerTube cli
123     npm run build:peertube-cli
124     patchShebangs ~/apps/peertube-cli/dist/peertube.js
126     # Build PeerTube runner
127     npm run build:peertube-runner
128     patchShebangs ~/apps/peertube-runner/dist/peertube-runner.js
130     # Clean up declaration files
131     find ~/dist/ \
132       ~/packages/core-utils/dist/ \
133       ~/packages/ffmpeg/dist/ \
134       ~/packages/models/dist/ \
135       ~/packages/node-utils/dist/ \
136       ~/packages/server-commands/dist/ \
137       ~/packages/typescript-utils/dist/ \
138       \( -name '*.d.ts' -o -name '*.d.ts.map' \) -type f -delete
139   '';
141   installPhase = ''
142     mkdir -p $out/dist
143     mv ~/dist $out
144     mv ~/node_modules $out/node_modules
145     mkdir $out/client
146     mv ~/client/{dist,node_modules,package.json,yarn.lock} $out/client
147     mkdir -p $out/packages/{core-utils,ffmpeg,models,node-utils,server-commands,typescript-utils}
148     mv ~/packages/core-utils/{dist,package.json} $out/packages/core-utils
149     mv ~/packages/ffmpeg/{dist,package.json} $out/packages/ffmpeg
150     mv ~/packages/models/{dist,package.json} $out/packages/models
151     mv ~/packages/node-utils/{dist,package.json} $out/packages/node-utils
152     mv ~/packages/server-commands/{dist,package.json} $out/packages/server-commands
153     mv ~/packages/typescript-utils/{dist,package.json} $out/packages/typescript-utils
154     mv ~/{config,support,CREDITS.md,FAQ.md,LICENSE,README.md,package.json,yarn.lock} $out
156     mkdir -p $cli/bin
157     mv ~/apps/peertube-cli/{dist,node_modules,package.json,yarn.lock} $cli
158     ln -s $cli/dist/peertube.js $cli/bin/peertube-cli
160     mkdir -p $runner/bin
161     mv ~/apps/peertube-runner/{dist,node_modules,package.json,yarn.lock} $runner
162     ln -s $runner/dist/peertube-runner.js $runner/bin/peertube-runner
164     # Create static gzip and brotli files
165     fd -e css -e eot -e html -e js -e json -e svg -e webmanifest -e xlf \
166       --type file --search-path $out/client/dist --threads $NIX_BUILD_CORES \
167       --exec gzip -9 -n -c {} > {}.gz \;\
168       --exec brotli --best -f {} -o {}.br
169   '';
171   passthru.tests.peertube = nixosTests.peertube;
173   meta = with lib; {
174     description = "Free software to take back control of your videos";
175     longDescription = ''
176       PeerTube aspires to be a decentralized and free/libre alternative to video
177       broadcasting services.
178       PeerTube is not meant to become a huge platform that would centralize
179       videos from all around the world. Rather, it is a network of
180       inter-connected small videos hosters.
181       Anyone with a modicum of technical skills can host a PeerTube server, aka
182       an instance. Each instance hosts its users and their videos. In this way,
183       every instance is created, moderated and maintained independently by
184       various administrators.
185       You can still watch from your account videos hosted by other instances
186       though if the administrator of your instance had previously connected it
187       with other instances.
188     '';
189     license = licenses.agpl3Plus;
190     homepage = "https://joinpeertube.org/";
191     platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
192     maintainers = with maintainers; [ immae izorkin stevenroose ];
193   };