fangame-flake/pkgs/fetchers.nix

57 lines
1.3 KiB
Nix

{ lib
, runCommand
, findutils
, megatools
, 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}"
);
fetchFromMega = mkFetcher (url:
"${megatools}/bin/megadl ${lib.escapeShellArg url} --disable-resume --no-ask-password"
);
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}"
);
}