* Use SHA-256 for nix-push.
This commit is contained in:
parent
155c91b335
commit
e52ae1c0ff
|
@ -1,6 +1,5 @@
|
||||||
{system, path}: derivation {
|
{system, path, hashAlgo}: derivation {
|
||||||
name = "nar";
|
name = "nar";
|
||||||
builder = ./nar.sh;
|
builder = ./nar.sh;
|
||||||
system = system;
|
inherit system path hashAlgo;
|
||||||
path = path;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ dst=$out/tmp.nar.bz2
|
||||||
|
|
||||||
@bzip2@ < tmp > $dst
|
@bzip2@ < tmp > $dst
|
||||||
|
|
||||||
@bindir@/nix-hash -vvvvv --flat --type sha1 --base32 tmp > $out/nar-hash
|
@bindir@/nix-hash -vvvvv --flat --type $hashAlgo --base32 tmp > $out/nar-hash
|
||||||
|
|
||||||
@bindir@/nix-hash --flat --type sha1 --base32 $dst > $out/narbz2-hash
|
@bindir@/nix-hash --flat --type $hashAlgo --base32 $dst > $out/narbz2-hash
|
||||||
|
|
||||||
mv $out/tmp.nar.bz2 $out/$(cat $out/narbz2-hash).nar.bz2
|
mv $out/tmp.nar.bz2 $out/$(cat $out/narbz2-hash).nar.bz2
|
||||||
|
|
|
@ -6,7 +6,7 @@ use readmanifest;
|
||||||
|
|
||||||
die unless scalar @ARGV == 5;
|
die unless scalar @ARGV == 5;
|
||||||
|
|
||||||
my $hashAlgo = "sha1";
|
my $hashAlgo = "sha256";
|
||||||
|
|
||||||
my $cacheDir = $ARGV[0];
|
my $cacheDir = $ARGV[0];
|
||||||
my $patchesDir = $ARGV[1];
|
my $patchesDir = $ARGV[1];
|
||||||
|
|
|
@ -5,6 +5,8 @@ use IPC::Open2;
|
||||||
use POSIX qw(tmpnam);
|
use POSIX qw(tmpnam);
|
||||||
use readmanifest;
|
use readmanifest;
|
||||||
|
|
||||||
|
my $hashAlgo = "sha256";
|
||||||
|
|
||||||
my $tmpdir;
|
my $tmpdir;
|
||||||
do { $tmpdir = tmpnam(); }
|
do { $tmpdir = tmpnam(); }
|
||||||
until mkdir $tmpdir, 0777;
|
until mkdir $tmpdir, 0777;
|
||||||
|
@ -90,7 +92,7 @@ foreach my $storePath (@storePaths) {
|
||||||
# Construct a Nix expression that creates a Nix archive.
|
# Construct a Nix expression that creates a Nix archive.
|
||||||
my $nixexpr =
|
my $nixexpr =
|
||||||
"((import $dataDir/nix/corepkgs/nar/nar.nix) " .
|
"((import $dataDir/nix/corepkgs/nar/nar.nix) " .
|
||||||
"{path = \"$storePath\"; system = \"@system@\";}) ";
|
"{path = \"$storePath\"; system = \"@system@\"; hashAlgo = \"$hashAlgo\";}) ";
|
||||||
|
|
||||||
print NIX $nixexpr;
|
print NIX $nixexpr;
|
||||||
}
|
}
|
||||||
|
@ -102,13 +104,18 @@ close NIX;
|
||||||
# Instantiate store expressions from the Nix expression.
|
# Instantiate store expressions from the Nix expression.
|
||||||
my @storeExprs;
|
my @storeExprs;
|
||||||
print STDERR "instantiating store expressions...\n";
|
print STDERR "instantiating store expressions...\n";
|
||||||
open STOREEXPRS, "$binDir/nix-instantiate $nixfile |" or die "cannot run nix-instantiate";
|
my $pid = open2(\*READ, \*WRITE, "$binDir/nix-instantiate $nixfile")
|
||||||
while (<STOREEXPRS>) {
|
or die "cannot run nix-instantiate";
|
||||||
|
close WRITE;
|
||||||
|
while (<READ>) {
|
||||||
chomp;
|
chomp;
|
||||||
die unless /^\//;
|
die unless /^\//;
|
||||||
push @storeExprs, $_;
|
push @storeExprs, $_;
|
||||||
}
|
}
|
||||||
close STOREEXPRS;
|
close READ;
|
||||||
|
|
||||||
|
waitpid $pid, 0;
|
||||||
|
$? == 0 or die "nix-instantiate failed";
|
||||||
|
|
||||||
|
|
||||||
# Realise the store expressions.
|
# Realise the store expressions.
|
||||||
|
@ -123,13 +130,18 @@ while (scalar @tmp > 0) {
|
||||||
my @tmp2 = @tmp[0..$n - 1];
|
my @tmp2 = @tmp[0..$n - 1];
|
||||||
@tmp = @tmp[$n..scalar @tmp - 1];
|
@tmp = @tmp[$n..scalar @tmp - 1];
|
||||||
|
|
||||||
open NARPATHS, "$binDir/nix-store --realise @tmp2 |" or die "cannot run nix-store";
|
my $pid = open2(\*READ, \*WRITE, "$binDir/nix-store --realise @tmp2")
|
||||||
while (<NARPATHS>) {
|
or die "cannot run nix-store";
|
||||||
|
close WRITE;
|
||||||
|
while (<READ>) {
|
||||||
chomp;
|
chomp;
|
||||||
die unless (/^\//);
|
die unless (/^\//);
|
||||||
push @narPaths, "$_";
|
push @narPaths, "$_";
|
||||||
}
|
}
|
||||||
close NARPATHS;
|
close READ;
|
||||||
|
|
||||||
|
waitpid $pid, 0;
|
||||||
|
$? == 0 or die "nix-store failed";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,17 +160,17 @@ for (my $n = 0; $n < scalar @storePaths; $n++) {
|
||||||
my $basename = $1;
|
my $basename = $1;
|
||||||
defined $basename or die;
|
defined $basename or die;
|
||||||
|
|
||||||
open SHA1, "$narDir/narbz2-hash" or die "cannot open narbz2-hash";
|
open HASH, "$narDir/narbz2-hash" or die "cannot open narbz2-hash";
|
||||||
my $narbz2Hash = <SHA1>;
|
my $narbz2Hash = <HASH>;
|
||||||
chomp $narbz2Hash;
|
chomp $narbz2Hash;
|
||||||
$narbz2Hash =~ /^[0-9a-z]{32}$/ or die "invalid hash";
|
$narbz2Hash =~ /^[0-9a-z]+$/ or die "invalid hash";
|
||||||
close SHA1;
|
close HASH;
|
||||||
|
|
||||||
open SHA1, "$narDir/nar-hash" or die "cannot open nar-hash";
|
open HASH, "$narDir/nar-hash" or die "cannot open nar-hash";
|
||||||
my $narHash = <SHA1>;
|
my $narHash = <HASH>;
|
||||||
chomp $narHash;
|
chomp $narHash;
|
||||||
$narHash =~ /^[0-9a-z]{32}$/ or die "invalid hash";
|
$narHash =~ /^[0-9a-z]+$/ or die "invalid hash";
|
||||||
close SHA1;
|
close HASH;
|
||||||
|
|
||||||
my $narName = "$narbz2Hash.nar.bz2";
|
my $narName = "$narbz2Hash.nar.bz2";
|
||||||
|
|
||||||
|
@ -185,9 +197,9 @@ for (my $n = 0; $n < scalar @storePaths; $n++) {
|
||||||
}
|
}
|
||||||
$narFiles{$storePath} = [
|
$narFiles{$storePath} = [
|
||||||
{ url => $url
|
{ url => $url
|
||||||
, hash => "sha1:$narbz2Hash"
|
, hash => "$hashAlgo:$narbz2Hash"
|
||||||
, size => $narbz2Size
|
, size => $narbz2Size
|
||||||
, narHash => "sha1:$narHash"
|
, narHash => "$hashAlgo:$narHash"
|
||||||
, references => $references
|
, references => $references
|
||||||
, deriver => $deriver
|
, deriver => $deriver
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue