mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-04-16 06:19:11 +00:00
lib/fetchers: add Internet Archive fetcher
This commit is contained in:
parent
1a1421386c
commit
e56c0a6136
@ -17,11 +17,13 @@ pkgs.lib.makeExtensible
|
||||
builders = callLib ./builders.nix;
|
||||
trivial = callLib ./trivial.nix;
|
||||
data = callLib ./data.nix;
|
||||
fetchers = callLib ./fetchers;
|
||||
|
||||
inherit (self.builders) makeXDGMimeAssociationList
|
||||
makeXDGPortalConfiguration makeXDGDesktopEntry;
|
||||
inherit (self.trivial) countAttrs;
|
||||
inherit (self.data) importYAML renderTeraTemplate;
|
||||
inherit (self.fetchers) fetchInternetArchive;
|
||||
} // lib.optionalAttrs (builtins ? fetchTree) {
|
||||
flake = callLib ./flake.nix;
|
||||
|
||||
|
5
lib/fetchers/default.nix
Normal file
5
lib/fetchers/default.nix
Normal file
@ -0,0 +1,5 @@
|
||||
{ pkgs, lib, self }:
|
||||
|
||||
{
|
||||
fetchInternetArchive = pkgs.callPackage ./fetch-internet-archive { };
|
||||
}
|
27
lib/fetchers/fetch-internet-archive/default.nix
Normal file
27
lib/fetchers/fetch-internet-archive/default.nix
Normal file
@ -0,0 +1,27 @@
|
||||
{ stdenvNoCC, lib, fetchzip, fetchurl, curl }:
|
||||
|
||||
{
|
||||
id,
|
||||
file ? "",
|
||||
formats ? [ ],
|
||||
hash ? "",
|
||||
name ? "internet-archive-${id}",
|
||||
}@args:
|
||||
|
||||
let
|
||||
isFormatIndiciated = formats != [ ];
|
||||
url =
|
||||
if isFormatIndiciated
|
||||
then "https://archive.org/compress/${lib.escapeURL id}/formats=${lib.concatStringsSep "," formats}"
|
||||
else "https://archive.org/download/${lib.escapeURL id}/${lib.escapeURL file}";
|
||||
|
||||
args' = lib.removeAttrs args [ "id" "file" "formats" ] // {
|
||||
inherit url hash name;
|
||||
} // lib.optionalAttrs isFormatIndiciated { inherit hash; };
|
||||
|
||||
fetcher =
|
||||
if isFormatIndiciated
|
||||
then fetchzip
|
||||
else fetchurl;
|
||||
in
|
||||
fetcher args'
|
21
tests/lib/fetchers.nix
Normal file
21
tests/lib/fetchers.nix
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
lib ? pkgs.lib,
|
||||
self ? import ../../lib { inherit pkgs; },
|
||||
}:
|
||||
|
||||
{
|
||||
testsInternetArchiveFetcher =
|
||||
self.fetchers.fetchInternetArchive {
|
||||
id = "md_music_sonic_the_hedgehog";
|
||||
file = "01 - Title Theme - Masato Nakamura.flac";
|
||||
hash = "sha256-kGjsVjtjXK9imqyi4GF6qkFVmobiTAe/ZAeEwiouqS4=";
|
||||
};
|
||||
|
||||
testsInternetArchiveFetcher2 =
|
||||
self.fetchers.fetchInternetArchive {
|
||||
id = "md_music_sonic_the_hedgehog";
|
||||
formats = [ "TEXT" "PNG" ];
|
||||
hash = "sha256-xbhasJ/wEgcY+EcBAJp5UoYB4N4It3QV/iIeGGdCET8=";
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user