use nix-instantiate for fetching distfiles

This commit is contained in:
Solene Rapenne 2022-08-28 14:47:42 +02:00
parent c93e9fecd3
commit f6252040f9
1 changed files with 5 additions and 57 deletions

View File

@ -9,67 +9,15 @@ use Data::Dumper;
my $json = do { local $/; <> };
my @text = decode_json($json);
my @data = @{$text[0]};
my $return;
foreach my $val (@data) {
print "Fetching $val->{name} from $val->{url} with $val->{hash}\n";
my $url = $val->{url};
$url =~ s,^mirror://savannah/,https://mirror.easyname.at/nongnu/,;
$url =~ s,^mirror://alsa/,https://www.alsa-project.org/files/pub/,;
$url =~ s,^mirror://apache/,https://dlcdn.apache.org/,;
$url =~ s,^mirror://bloc/,https://bioconductor.statistik.tu-dortmund.de/packages/,;
$url =~ s,^mirror://bitlbee/,https://get.bitlbee.org/,;
$url =~ s,^mirror://gcc/,ftp://gcc.gnu.org/pub/gcc/,;
$url =~ s,^mirror://gnome/,https://download.gnome.org/,;
$url =~ s,^mirror://gnu/,https://ftpmirror.gnu.org/,;
$url =~ s,^mirror://gnupg/,https://gnupg.org/ftp/gcrypt/,;
$url =~ s,^mirror://ibiblioPubLinux/,https://www.ibiblio.org/pub/Linux/,;
$url =~ s,^mirror://imagemagick/,https://www.imagemagick.org/download/,;
$url =~ s,^mirror://kde/,https://download.kde.org/download.php?url=,;
$url =~ s,^mirror://kernel/,https://cdn.kernel.org/pub/,;
$url =~ s,^mirror://mysql/,https://cdn.mysql.com/Downloads/,;
$url =~ s,^mirror://maven/,https://repo1.maven.org/maven2/,;
$url =~ s,^mirror://mozilla/,https://download.cdn.mozilla.net/pub/mozilla.org/,;
$url =~ s,^mirror://osdn/,https://osdn.dl.osdn.jp/,;
$url =~ s,^mirror://postgresql/,https://ftp.postgresql.org/pub/,;
$url =~ s,^mirror://qt/,https://download.qt.io/,;
$url =~ s,^mirror://roy/,https://roy.marples.name/downloads/,;
$url =~ s,^mirror://sageupstream/,https://www-ftp.lip6.fr/pub/math/sagemath/spkg/upstream/,;
$url =~ s,^mirror://samba/,https://www.samba.org/ftp/,;
$url =~ s,^mirror://sourceforge/,https://downloads.sourceforge.net/,;
$url =~ s,^mirror://steamrt/,https://repo.steampowered.com/steamrt/,;
$url =~ s,^mirror://tcsh/,https://astron.com/pub/tcsh/,;
$url =~ s,^mirror://xfce/,https://archive.xfce.org/,;
$url =~ s,^mirror://xorg/,https://xorg.freedesktop.org/releases/,;
$url =~ s,^mirror://cpan/,https://cpan.metacpan.org/,;
$url =~ s,^mirror://hackage/,https://hackage.haskell.org/package/,;
$url =~ s,^mirror://luarocks/,https://luarocks.org/,;
$url =~ s,^mirror://pypi/,https://pypi.io/packages/source/,;
$url =~ s,^mirror://testpypi/,https://test.pypi.io/packages/source/,;
$url =~ s,^mirror://centos/,https://vault.centos.org/,;
$url =~ s,^mirror://debian/,https://httpredir.debian.org/debian/,;
$url =~ s,^mirror://fedora/,https://archives.fedoraproject.org/pub/fedora/,;
$url =~ s,^mirror://gentoo/,https://distfiles.gentoo.org/,;
$url =~ s,^mirror://opensuse/,https://ftp.opensuse.org/pub/opensuse/distribution/,;
$url =~ s,^mirror://ubuntu/,https://nl.archive.ubuntu.com/ubuntu/,;
$url =~ s,^mirror://openbsd/,https://ftp.openbsd.org/pub/OpenBSD/,;
if ($val->{f}) {
my $TMPFILE = `mktemp /tmp/patch.XXXXXXXXXXXXXXX`;
chomp($TMPFILE);
open(OUT, ">","/tmp/script.sh");
print OUT "#!/usr/bin/env nix-shell\n";
print OUT "#! nix-shell -i bash -p patchutils_0_3_3\n";
print OUT "export LC_ALL=C\n";
print OUT "curl -L -o $TMPFILE $url\n";
print OUT "out=\"$TMPFILE\"\n";
print OUT "$val->{f}\n";
`sed 's,.*/lsdiff.*,lsdiff \\\\,g ; s,.*/filterdiff.*,filterdiff \\\\,g' -i /tmp/script.sh`;
`chmod +x /tmp/script.sh`;
`/tmp/script.sh "$url" "$TMPFILE"`;
my $return = `nix-instantiate --eval -E 'builtins.fetchurl { url = "file://$TMPFILE" ; sha256 = "$val->{hash}"; }'`;
print $return;
if ($val->{isPatch}) {
$return = `nix-instantiate '<nixpkgs>' -A fetchpatch --argstr url "$val->{url}" --argstr name "$val->{name}" --argstr sha256 "$val->{hash}"`;
print $return;
} else {
my $return = `nix-instantiate --eval -E 'builtins.fetchurl { url = $url ; sha256 = "$val->{hash}"; }'`;
$return = `nix-instantiate '<nixpkgs>' -A fetchurl --argstr url "$val->{url}" --argstr sha256 "$val->{hash}"`;
print $return;
}
}