push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,173 @@
{
lib,
runCommand,
transmission_3_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 ? { },
hash,
backend ? "transmission",
recursiveHash ? true,
flatten ? null,
postFetch ? "",
postUnpack ? "",
meta ? { },
}:
let
# Default to flattening if no flatten argument was specified.
flatten' = if flatten == null then true else flatten;
transmissionFinishScript = 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;
# https://github.com/NixOS/nixpkgs/issues/432001
#
# For a while, the transmission backend would put the downloaded torrent in
# the output directory, but whether the rqbit backend would put the output in
# the output directory or a subdirectory depended on the version of rqbit.
# We want to standardise on a single behaviour, but give users of
# fetchtorrent with the rqbit backend some warning that the behaviour might
# be unexpected, particularly since we can't know what behaviour users might
# be expecting at this point, and they probably wouldn't notice a change
# straight away because the results are fixed-output derivations.
#
# This warning was introduced for 25.11, so we can remove handling of the
# `flatten` argument once that release is no longer supported.
warnings =
if backend == "rqbit" && flatten == null then
[
''
`fetchtorrent` with the rqbit backend may or may not have the
downloaded files stored in a subdirectory of the output directory.
Verify which behaviour you need, and set the `flatten` argument to
`fetchtorrent` accordingly.
The `flatten = false` behaviour will still produce a warning, as this
behaviour is deprecated. It is only available with the "rqbit" backend
to provide temporary support for users who are relying on the
previous incorrect behaviour. For a warning-free evaluation, use
`flatten = true`.
''
]
else if flatten == false then
[
''
`fetchtorrent` with `flatten = false` is deprecated and will be
removed in a future release.
''
]
else
[ ];
in
assert lib.assertMsg (config != { } -> backend == "transmission") ''
json config for configuring fetchtorrent only works with the transmission backend
'';
assert lib.assertMsg (backend == "transmission" -> flatten') ''
`flatten = false` is only supported by the rqbit backend for fetchtorrent
'';
runCommand name
{
inherit meta;
nativeBuildInputs = [
cacert
]
++ (
if (backend == "transmission") then
[ transmission_3_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
port="$(shuf -n 1 -i 49152-65535)"
function handleChild {
# This detects failures and logs the contents of the transmission fetch
find $out
exit 0
}
trap handleChild CHLD
transmission-cli \
--port "$port" \
--portmap \
--finish ${transmissionFinishScript} \
--download-dir "$downloadedDirectory" \
--config-dir "$HOME"/.config/transmission \
"$url"
''
else
''
export HOME=$TMP
''
+ lib.optionalString flatten' ''
downloadedDirectory=$out/downloadedDirectory
mkdir -p $downloadedDirectory
''
+ lib.optionalString (!flatten') ''
downloadedDirectory=$out
''
+ ''
port="$(shuf -n 1 -i 49152-65535)"
rqbit \
--disable-dht-persistence \
--http-api-listen-addr "127.0.0.1:$port" \
download \
-o "$downloadedDirectory" \
--exit-on-finish \
"$url"
${postUnpack}
''
+ lib.optionalString flatten' ''
# 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}
''
)

View File

@@ -0,0 +1,91 @@
{
lib,
testers,
fetchtorrent,
...
}:
let
sintel.meta = {
description = "An open source short film to show off open source technologies.";
longDescription = ''
An independently produced short film, initiated by the Blender Foundation
as a means to further improve andvalidate the free/open source 3D
creation suite Blender.
'';
license = lib.licenses.cc-by-30;
homepage = "https://durian.blender.org/";
};
# Via https://webtorrent.io/free-torrents
http.url = "https://webtorrent.io/torrents/sintel.torrent";
magnet.url = "magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&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%2Fsintel.torrent";
flattened.hash = "sha256-EzbmBiTEWOlFUNaV5R4eDeD9EBbp6d93rfby88ACg0s=";
unflattened.hash = "sha256-lVrlo1AwmFcxwsIsY976VYqb3hAprFH1xWYdmlTuw0U=";
in
# Seems almost but not quite worth using lib.mapCartesianProduct...
builtins.mapAttrs (n: v: testers.invalidateFetcherByDrvHash fetchtorrent v) {
http-link = {
inherit (http) url;
inherit (flattened) hash;
inherit (sintel) meta;
};
http-link-transmission = {
inherit (http) url;
backend = "transmission";
inherit (flattened) hash;
inherit (sintel) meta;
};
magnet-link = {
inherit (magnet) url;
inherit (flattened) hash;
inherit (sintel) meta;
};
magnet-link-transmission = {
inherit (magnet) url;
backend = "transmission";
inherit (flattened) hash;
inherit (sintel) meta;
};
http-link-rqbit = {
inherit (http) url;
backend = "rqbit";
inherit (flattened) hash;
inherit (sintel) meta;
};
magnet-link-rqbit = {
inherit (magnet) url;
backend = "rqbit";
inherit (flattened) hash;
inherit (sintel) meta;
};
http-link-rqbit-flattened = {
inherit (http) url;
backend = "rqbit";
flatten = true;
inherit (flattened) hash;
inherit (sintel) meta;
};
magnet-link-rqbit-flattened = {
inherit (magnet) url;
backend = "rqbit";
flatten = true;
inherit (flattened) hash;
inherit (sintel) meta;
};
http-link-rqbit-unflattened = {
inherit (http) url;
backend = "rqbit";
flatten = false;
inherit (unflattened) hash;
inherit (sintel) meta;
};
magnet-link-rqbit-unflattened = {
inherit (magnet) url;
backend = "rqbit";
flatten = false;
inherit (unflattened) hash;
inherit (sintel) meta;
};
}