@@ -13,6 +13,9 @@
1313use strict;
1414use warnings;
1515
16+use File::Basename;
17+use File::Spec::Functions;
18+
1619my $tmpDir = "/tmp/xorg-unpack";
1720
1821
@@ -43,7 +46,6 @@ $pcMap{"\$DRI2PROTO"} = "dri2proto";
4346
4447
4548my $downloadCache = "./download-cache";
46−$ENV{'NIX_DOWNLOAD_CACHE'} = $downloadCache;
4749mkdir $downloadCache, 0755;
4850
4951
@@ -76,7 +78,17 @@ while (<>) {
7678 $pkgURLs{$pkg} = $tarball;
7779 $pkgNames{$pkg} = $pkgName;
7880
79− my ($hash, $path) = `PRINT_PATH=1 QUIET=1 nix-prefetch-url '$tarball'`;
81+ my $cachePath = catdir($downloadCache, basename($tarball));
82+ my $hash;
83+ my $path;
84+ if (-e $cachePath) {
85+ $path = readlink($cachePath);
86+ $hash = `nix-hash --type sha256 --base32 --flat $cachePath`;
87+ }
88+ else {
89+ ($hash, $path) = `PRINT_PATH=1 QUIET=1 nix-prefetch-url '$tarball'`;
90+ `nix-store --realise --add-root $cachePath --indirect $path`;
91+ }
8092 chomp $hash;
8193 chomp $path;
8294 $pkgHashes{$pkg} = $hash;