Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 108 lines 3.0 kB view raw
1{ 2 lib, 3 buildNpmPackage, 4 fetchFromGitHub, 5 gitUpdater, 6 nodejs, 7 cmake, 8 pkg-config, 9 openssl, 10 libdatachannel, 11 plog, 12}: 13 14let 15 # Modified from pkgs/by-name/ht/httptoolkit-server/package.nix 16 nodeDatachannel = buildNpmPackage { 17 pname = "node-datachannel"; 18 version = "0.10.1"; 19 20 src = fetchFromGitHub { 21 owner = "murat-dogan"; 22 repo = "node-datachannel"; 23 rev = "refs/tags/v${nodeDatachannel.version}"; 24 hash = "sha256-r5tBg645ikIWm+RU7Muw/JYyd7AMpkImD0Xygtm1MUk="; 25 }; 26 27 npmFlags = [ "--ignore-scripts" ]; 28 29 makeCacheWritable = true; 30 31 npmDepsHash = "sha256-1ZJd0Y45B3CT2YPXDYfCuFMBo5uggWRuDH11eCobyyY="; 32 33 nativeBuildInputs = [ 34 cmake 35 pkg-config 36 ]; 37 38 buildInputs = [ 39 openssl 40 libdatachannel 41 plog 42 ]; 43 44 dontUseCmakeConfigure = true; 45 46 env.NIX_CFLAGS_COMPILE = "-I${nodejs}/include/node"; 47 48 preBuild = '' 49 # don't use static libs and don't use FetchContent 50 substituteInPlace CMakeLists.txt \ 51 --replace-fail 'OPENSSL_USE_STATIC_LIBS TRUE' 'OPENSSL_USE_STATIC_LIBS FALSE' \ 52 --replace-fail 'if(NOT libdatachannel)' 'if(false)' \ 53 --replace-fail 'datachannel-static' 'datachannel' 54 sed -i '2ifind_package(plog)' CMakeLists.txt 55 56 # don't fetch node headers 57 substituteInPlace node_modules/cmake-js/lib/dist.js \ 58 --replace-fail '!this.downloaded' 'false' 59 ''; 60 61 installPhase = '' 62 runHook preInstall 63 install -Dm755 build/Release/*.node -t $out/build/Release 64 runHook postInstall 65 ''; 66 }; 67in 68 69buildNpmPackage rec { 70 pname = "webtorrent-mpv-hook"; 71 version = "1.4.4"; 72 73 src = fetchFromGitHub { 74 owner = "mrxdst"; 75 repo = pname; 76 rev = "v${version}"; 77 hash = "sha256-qFeQBVPZZFKkxz1fhK3+ah3TPDovklhhQwtv09TiSqo="; 78 }; 79 passthru.updateScript = gitUpdater { rev-prefix = "v"; }; 80 81 postPatch = '' 82 substituteInPlace src/webtorrent.ts --replace-fail "node_path: 'node'" "node_path: '${lib.getExe nodejs}'" 83 # This executable is just for telling non-Nix users how to install 84 substituteInPlace package.json --replace-fail '"bin": "build/bin.mjs",' "" 85 rm -rf src/bin.ts 86 ''; 87 88 npmDepsHash = "sha256-fKzXdbtxC2+63/GZdvPOxvBpQ5rzgvfseigOgpP1n5I="; 89 makeCacheWritable = true; 90 npmFlags = [ "--ignore-scripts" ]; 91 92 postConfigure = '' 93 # manually place our prebuilt `node-datachannel` binary into its place, since we used '--ignore-scripts' 94 ln -s ${nodeDatachannel}/build node_modules/node-datachannel/build 95 ''; 96 postInstall = '' 97 mkdir -p $out/share/mpv/scripts/ 98 ln -s $out/lib/node_modules/webtorrent-mpv-hook/build/webtorrent.js $out/share/mpv/scripts/ 99 ''; 100 passthru.scriptName = "webtorrent.js"; 101 102 meta = { 103 description = "Adds a hook that allows mpv to stream torrents"; 104 homepage = "https://github.com/mrxdst/webtorrent-mpv-hook"; 105 maintainers = [ lib.maintainers.chuangzhu ]; 106 license = lib.licenses.isc; 107 }; 108}