fangame-flake/pkgs/fetchers.nix

57 lines
1.3 KiB
Nix
Raw Normal View History

2023-06-15 01:41:21 +02:00
{ lib
, runCommand
, findutils
2023-06-15 22:41:31 +02:00
, megatools
2023-06-15 21:26:19 +02:00
, badown
, mediafire-dl
2023-06-15 01:41:21 +02:00
, gdown
}:
let
mkFetcher = mkCmd: {
name ? "source",
assert_exists ? [],
url,
hash ? lib.fakeHash,
preferLocalBuild ? true,
}: runCommand name {
outputHash = if hash == "" || hash == null then lib.fakeHash else hash;
outputHashAlgo = null;
outputHashMode = "recursive";
inherit preferLocalBuild;
passthru = { inherit url; };
} ''
cd $(mktemp -d)
${mkCmd url}
${lib.concatMapStringsSep "\n" (fname: ''
if ! test -s ${lib.escapeShellArg fname}; then
echo ERROR: file not found: ${lib.escapeShellArg fname}
echo Files found:
${findutils}/bin/find .
false
fi
'') assert_exists}
if test $(ls | wc -l) -gt 1; then
mkdir $out
fi
cp -v * $out
'';
in {
fetchFromDrive = mkFetcher (url:
"HOME=$(mktemp -d) ${gdown}/bin/gdown ${lib.escapeShellArg url}"
);
2023-06-15 22:41:31 +02:00
fetchFromMega = mkFetcher (url:
"${megatools}/bin/megadl ${lib.escapeShellArg url} --disable-resume --no-ask-password"
);
2023-06-15 21:26:19 +02:00
fetchFromMediafire = mkFetcher (url:
# TODO: why doesn't this work inside a FOD?
#"${badown}/bin/badown ${lib.escapeShellArg url}"
"${mediafire-dl}/bin/mediafire-dl ${lib.escapeShellArg url}"
);
2023-06-15 01:41:21 +02:00
}