From 2fd6af1929acc4cd2e0da827f016dd988eb66e5f Mon Sep 17 00:00:00 2001 From: Eirik Wittersø Date: Sat, 28 Oct 2023 00:25:35 +0200 Subject: fetchFromBittorrent: Rename to fetchtorrent --- pkgs/build-support/fetchbittorrent/default.nix | 60 -------------------------- pkgs/build-support/fetchbittorrent/tests.nix | 25 ----------- pkgs/build-support/fetchtorrent/default.nix | 60 ++++++++++++++++++++++++++ pkgs/build-support/fetchtorrent/tests.nix | 25 +++++++++++ 4 files changed, 85 insertions(+), 85 deletions(-) delete mode 100644 pkgs/build-support/fetchbittorrent/default.nix delete mode 100644 pkgs/build-support/fetchbittorrent/tests.nix create mode 100644 pkgs/build-support/fetchtorrent/default.nix create mode 100644 pkgs/build-support/fetchtorrent/tests.nix (limited to 'pkgs/build-support') diff --git a/pkgs/build-support/fetchbittorrent/default.nix b/pkgs/build-support/fetchbittorrent/default.nix deleted file mode 100644 index 916c7e7d8c9..00000000000 --- a/pkgs/build-support/fetchbittorrent/default.nix +++ /dev/null @@ -1,60 +0,0 @@ -{ lib, runCommand, transmission_noSystemd, rqbit, writeShellScript, formats, cacert, rsync }: -let - urlRegexp = ''.*xt=urn:bt[im]h:([^&]{64}|[^&]{40}).*''; -in -{ url -, name ? - if (builtins.match urlRegexp url) == null then - "bittorrent" - else - "bittorrent-" + builtins.head (builtins.match urlRegexp url) -, config ? if (backend == "transmission") then { } else throw "json config for configuring fetchFromBitorrent only works with the transmission backend" -, hash -, backend ? "transmission" -, recursiveHash ? true -, postFetch ? "" -, postUnpack ? "" -}: -let - afterSuccess = writeShellScript "fetch-bittorrent-done.sh" '' - ${postUnpack} - # Flatten the directory, so that only the torrent contents are in $out, not - # the folder name - shopt -s dotglob - mv -v $downloadedDirectory/*/* $out - rm -v -rf $downloadedDirectory - unset downloadedDirectory - ${postFetch} - kill $PPID - ''; - jsonConfig = (formats.json {}).generate "jsonConfig" config; -in -runCommand name { - nativeBuildInputs = [ cacert ] ++ (if (backend == "transmission" ) then [ transmission_noSystemd ] else if (backend == "rqbit") then [ rqbit ] else throw "rqbit or transmission are the only available backends for fetchbittorrent"); - outputHashAlgo = if hash != "" then null else "sha256"; - outputHash = hash; - outputHashMode = if recursiveHash then "recursive" else "flat"; - - # url will be written to the derivation, meaning it can be parsed and utilized - # by external tools, such as tools that may want to seed fetchBittorrent calls - # in nixpkgs - inherit url; -} -(if (backend == "transmission") then '' - export HOME=$TMP - export downloadedDirectory=$out/downloadedDirectory - mkdir -p $downloadedDirectory - mkdir -p $HOME/.config/transmission - cp ${jsonConfig} $HOME/.config/transmission/settings.json - function handleChild { - # This detects failures and logs the contents of the transmission fetch - find $out - exit 0 - } - trap handleChild CHLD - transmission-cli --port $(shuf -n 1 -i 49152-65535) --portmap --finish ${afterSuccess} --download-dir $downloadedDirectory --config-dir "$HOME"/.config/transmission "$url" -'' else -'' - export HOME=$TMP - rqbit --disable-dht-persistence --http-api-listen-addr "127.0.0.1:$(shuf -n 1 -i 49152-65535)" download -o $out --exit-on-finish "$url" -'') diff --git a/pkgs/build-support/fetchbittorrent/tests.nix b/pkgs/build-support/fetchbittorrent/tests.nix deleted file mode 100644 index fce1b3933a7..00000000000 --- a/pkgs/build-support/fetchbittorrent/tests.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ testers, fetchFromBittorrent, ... }: - -{ - http-link = testers.invalidateFetcherByDrvHash fetchFromBittorrent { - url = "https://webtorrent.io/torrents/wired-cd.torrent"; - hash = "sha256-OCsC22WuanqoN6lPv5wDT5ZxPcEHDpZ1EgXGvz1SDYo="; - backend = "transmission"; - }; - magnet-link = testers.invalidateFetcherByDrvHash fetchFromBittorrent { - url = "magnet:?xt=urn:btih:a88fda5954e89178c372716a6a78b8180ed4dad3&dn=The+WIRED+CD+-+Rip.+Sample.+Mash.+Share&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fwired-cd.torrent"; - hash = "sha256-OCsC22WuanqoN6lPv5wDT5ZxPcEHDpZ1EgXGvz1SDYo="; - backend = "transmission"; - }; - http-link-rqbit = testers.invalidateFetcherByDrvHash fetchFromBittorrent { - url = "https://webtorrent.io/torrents/wired-cd.torrent"; - hash = "sha256-OCsC22WuanqoN6lPv5wDT5ZxPcEHDpZ1EgXGvz1SDYo="; - backend = "rqbit"; - }; - magnet-link-rqbit = testers.invalidateFetcherByDrvHash fetchFromBittorrent { - url = "magnet:?xt=urn:btih:a88fda5954e89178c372716a6a78b8180ed4dad3&dn=The+WIRED+CD+-+Rip.+Sample.+Mash.+Share&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fwired-cd.torrent"; - hash = "sha256-OCsC22WuanqoN6lPv5wDT5ZxPcEHDpZ1EgXGvz1SDYo="; - backend = "rqbit"; - }; -} - diff --git a/pkgs/build-support/fetchtorrent/default.nix b/pkgs/build-support/fetchtorrent/default.nix new file mode 100644 index 00000000000..beb2415df70 --- /dev/null +++ b/pkgs/build-support/fetchtorrent/default.nix @@ -0,0 +1,60 @@ +{ lib, runCommand, transmission_noSystemd, rqbit, writeShellScript, formats, cacert, rsync }: +let + urlRegexp = ''.*xt=urn:bt[im]h:([^&]{64}|[^&]{40}).*''; +in +{ url +, name ? + if (builtins.match urlRegexp url) == null then + "bittorrent" + else + "bittorrent-" + builtins.head (builtins.match urlRegexp url) +, config ? if (backend == "transmission") then { } else throw "json config for configuring fetchFromBitorrent only works with the transmission backend" +, hash +, backend ? "transmission" +, recursiveHash ? true +, postFetch ? "" +, postUnpack ? "" +}: +let + afterSuccess = writeShellScript "fetch-bittorrent-done.sh" '' + ${postUnpack} + # Flatten the directory, so that only the torrent contents are in $out, not + # the folder name + shopt -s dotglob + mv -v $downloadedDirectory/*/* $out + rm -v -rf $downloadedDirectory + unset downloadedDirectory + ${postFetch} + kill $PPID + ''; + jsonConfig = (formats.json {}).generate "jsonConfig" config; +in +runCommand name { + nativeBuildInputs = [ cacert ] ++ (if (backend == "transmission" ) then [ transmission_noSystemd ] else if (backend == "rqbit") then [ rqbit ] else throw "rqbit or transmission are the only available backends for fetchtorrent"); + outputHashAlgo = if hash != "" then null else "sha256"; + outputHash = hash; + outputHashMode = if recursiveHash then "recursive" else "flat"; + + # url will be written to the derivation, meaning it can be parsed and utilized + # by external tools, such as tools that may want to seed fetchtorrent calls + # in nixpkgs + inherit url; +} +(if (backend == "transmission") then '' + export HOME=$TMP + export downloadedDirectory=$out/downloadedDirectory + mkdir -p $downloadedDirectory + mkdir -p $HOME/.config/transmission + cp ${jsonConfig} $HOME/.config/transmission/settings.json + function handleChild { + # This detects failures and logs the contents of the transmission fetch + find $out + exit 0 + } + trap handleChild CHLD + transmission-cli --port $(shuf -n 1 -i 49152-65535) --portmap --finish ${afterSuccess} --download-dir $downloadedDirectory --config-dir "$HOME"/.config/transmission "$url" +'' else +'' + export HOME=$TMP + rqbit --disable-dht-persistence --http-api-listen-addr "127.0.0.1:$(shuf -n 1 -i 49152-65535)" download -o $out --exit-on-finish "$url" +'') diff --git a/pkgs/build-support/fetchtorrent/tests.nix b/pkgs/build-support/fetchtorrent/tests.nix new file mode 100644 index 00000000000..b36c82c6326 --- /dev/null +++ b/pkgs/build-support/fetchtorrent/tests.nix @@ -0,0 +1,25 @@ +{ testers, fetchtorrent, ... }: + +{ + http-link = testers.invalidateFetcherByDrvHash fetchtorrent { + url = "https://webtorrent.io/torrents/wired-cd.torrent"; + hash = "sha256-OCsC22WuanqoN6lPv5wDT5ZxPcEHDpZ1EgXGvz1SDYo="; + backend = "transmission"; + }; + magnet-link = testers.invalidateFetcherByDrvHash fetchtorrent { + url = "magnet:?xt=urn:btih:a88fda5954e89178c372716a6a78b8180ed4dad3&dn=The+WIRED+CD+-+Rip.+Sample.+Mash.+Share&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fwired-cd.torrent"; + hash = "sha256-OCsC22WuanqoN6lPv5wDT5ZxPcEHDpZ1EgXGvz1SDYo="; + backend = "transmission"; + }; + http-link-rqbit = testers.invalidateFetcherByDrvHash fetchtorrent { + url = "https://webtorrent.io/torrents/wired-cd.torrent"; + hash = "sha256-OCsC22WuanqoN6lPv5wDT5ZxPcEHDpZ1EgXGvz1SDYo="; + backend = "rqbit"; + }; + magnet-link-rqbit = testers.invalidateFetcherByDrvHash fetchtorrent { + url = "magnet:?xt=urn:btih:a88fda5954e89178c372716a6a78b8180ed4dad3&dn=The+WIRED+CD+-+Rip.+Sample.+Mash.+Share&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fwired-cd.torrent"; + hash = "sha256-OCsC22WuanqoN6lPv5wDT5ZxPcEHDpZ1EgXGvz1SDYo="; + backend = "rqbit"; + }; +} + -- cgit 1.4.1