forked from hacc/haccfiles
142 lines
3.9 KiB
Nix
142 lines
3.9 KiB
Nix
|
{ stdenv, yarn2nix-moretea, lib, nodePackages, fetchFromGitHub, fetchurl, youtube-dl, jq, nodejs }:
|
||
|
|
||
|
let
|
||
|
inherit (yarn2nix-moretea) mkYarnPackage defaultYarnFlags;
|
||
|
in rec {
|
||
|
mkYarnModules = args: (yarn2nix-moretea.mkYarnModules args).overrideAttrs(old: {
|
||
|
buildPhase = builtins.replaceStrings [" ./package.json"] [" /dev/null; cp deps/*/package.json ."] old.buildPhase;
|
||
|
});
|
||
|
|
||
|
source = stdenv.mkDerivation {
|
||
|
name = "peertube-src";
|
||
|
src = fetchFromGitHub {
|
||
|
owner = "Chocobozzz";
|
||
|
repo = "peertube";
|
||
|
rev = "v3.0.1";
|
||
|
sha256 = "0zrrhc5kml7mqxafmr8yggiakjh3a33wvn2m1i6ij112nkjyv1bc";
|
||
|
};
|
||
|
|
||
|
phases = [ "unpackPhase" "patchPhase" "installPhase" "fixupPhase" ];
|
||
|
patches = [ ./fix-yarnlock.patch ];
|
||
|
|
||
|
installPhase = ''
|
||
|
mkdir $out
|
||
|
cp -a . $out
|
||
|
'';
|
||
|
|
||
|
fixupPhase = ''
|
||
|
patchShebangs $out/scripts
|
||
|
'';
|
||
|
};
|
||
|
|
||
|
nodeHeaders = fetchurl {
|
||
|
url = "https://nodejs.org/download/release/v${nodejs.version}/node-v${nodejs.version}-headers.tar.gz";
|
||
|
sha256 = "18nsc6qc3f367vk63bm3wwmcw6lwi8jqxgv025jnv9mc539zx4iy";
|
||
|
};
|
||
|
|
||
|
yarnModulesConfig = {
|
||
|
bcrypt = {
|
||
|
buildInputs = [ nodePackages.node-pre-gyp ];
|
||
|
postInstall = let
|
||
|
bcrypt_version = "5.0.0";
|
||
|
bcrypt_lib = fetchurl {
|
||
|
url = "https://github.com/kelektiv/node.bcrypt.js/releases/download/v${bcrypt_version}/bcrypt_lib-v${bcrypt_version}-napi-v3-linux-x64-glibc.tar.gz";
|
||
|
sha256 = "0j3p2px1xb17sw3gpm8l4apljajxxfflal1yy552mhpzhi21wccn";
|
||
|
};
|
||
|
in
|
||
|
''
|
||
|
if [ "${bcrypt_version}" != "$(cat package.json | ${jq}/bin/jq -r .version)" ]; then
|
||
|
echo "Mismatching version please update bcrypt in derivation"
|
||
|
false
|
||
|
fi
|
||
|
mkdir -p lib/binding && tar -C lib/binding -xf ${bcrypt_lib}
|
||
|
patchShebangs ../node-pre-gyp
|
||
|
npm run install
|
||
|
'';
|
||
|
};
|
||
|
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
|
||
|
'';
|
||
|
};
|
||
|
};
|
||
|
|
||
|
serverModules = mkYarnModules rec {
|
||
|
pname = "peertube-server-yarn-modules";
|
||
|
version = "3.0.1";
|
||
|
name = "${pname}-${version}";
|
||
|
packageJSON = "${source}/package.json";
|
||
|
yarnLock = "${source}/yarn.lock";
|
||
|
pkgConfig = yarnModulesConfig;
|
||
|
};
|
||
|
|
||
|
clientModules = mkYarnModules rec {
|
||
|
pname = "peertube-client-yarn-modules";
|
||
|
version = "3.0.1";
|
||
|
name = "${pname}-${version}";
|
||
|
packageJSON = "${source}/client/package.json";
|
||
|
yarnLock = "${source}/client/yarn.lock";
|
||
|
pkgConfig = yarnModulesConfig;
|
||
|
};
|
||
|
|
||
|
serverModulesProd = serverModules.overrideAttrs (_: {
|
||
|
yarnFlags = defaultYarnFlags ++ [ "--production" ];
|
||
|
});
|
||
|
|
||
|
server = stdenv.mkDerivation {
|
||
|
pname = "peertube-server";
|
||
|
version = "3.0.1";
|
||
|
src = source;
|
||
|
nativeBuildInputs = [ nodePackages.npm ];
|
||
|
buildPhase = ''
|
||
|
ln -s ${serverModules}/node_modules ./
|
||
|
rm -rf ./dist
|
||
|
npm run build:server
|
||
|
'';
|
||
|
installPhase = ''
|
||
|
mkdir $out
|
||
|
cp -a dist $out
|
||
|
'';
|
||
|
};
|
||
|
|
||
|
client = stdenv.mkDerivation {
|
||
|
pname = "peertube-client";
|
||
|
version = "3.0.1";
|
||
|
src = source;
|
||
|
buildPhase = ''
|
||
|
ln -s ${serverModules}/node_modules .
|
||
|
cp -a ${clientModules}/node_modules client/
|
||
|
chmod -R +w client/node_modules
|
||
|
npm run build:client
|
||
|
'';
|
||
|
installPhase = ''
|
||
|
mkdir $out
|
||
|
cp -a client/dist $out
|
||
|
'';
|
||
|
buildInputs = [ nodejs ];
|
||
|
};
|
||
|
|
||
|
package = stdenv.mkDerivation {
|
||
|
pname = "peertube";
|
||
|
version = "3.0.1";
|
||
|
src = source;
|
||
|
buildPhase = ''
|
||
|
ln -s ${serverModulesProd}/node_modules .
|
||
|
rm -rf dist && cp -a ${server}/dist dist
|
||
|
rm -rf client/dist && cp -a ${client}/dist client/
|
||
|
'';
|
||
|
installPhase = ''
|
||
|
mkdir $out
|
||
|
cp -a * $out
|
||
|
ln -s /tmp $out/.cache
|
||
|
'';
|
||
|
};
|
||
|
}
|