52 lines
1.1 KiB
Nix
52 lines
1.1 KiB
Nix
{ lib
|
|
, runCommand
|
|
, findutils
|
|
, badown
|
|
, mediafire-dl
|
|
, 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}"
|
|
);
|
|
|
|
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}"
|
|
);
|
|
|
|
}
|