* Improved `nix-push': it now uses HTTP PUT (instead of rsync) to copy

files.  Target location is no longer hard-coded; it accepts a number
  of URLs on the command line.

* `nix-install-package': compatibility fixes.
This commit is contained in:
Eelco Dolstra 2004-01-14 11:13:08 +00:00
parent ff9af107d3
commit 16f9b133ec
2 changed files with 86 additions and 51 deletions

View file

@ -12,26 +12,26 @@ until mkdir $tmpdir, 0777;
# !!! remove tmpdir on exit # !!! remove tmpdir on exit
print "unpacking $pkgfile in $tmpdir...\n"; print "Unpacking $pkgfile in $tmpdir...\n";
system "bunzip2 < $pkgfile | (cd $tmpdir && tar xf -)"; system "bunzip2 < $pkgfile | (cd $tmpdir && tar xf -)";
die if $?; die if $?;
print "this package contains the following derivations:\n"; print "This package contains the following derivations:\n";
system "nix-env -qsf $tmpdir/default.nix"; system "nix-env -qasf $tmpdir/default.nix";
die if $?; die if $?;
print "do you wish to install them (y/n)? "; print "Do you wish to install these (Y/N)? ";
my $reply = <STDIN>; my $reply = <STDIN>;
chomp $reply; chomp $reply;
exit if (!($reply eq "y")); exit if (!($reply eq "y"));
print "pulling caches...\n"; print "Pulling caches...\n";
system "nix-pull `cat $tmpdir/caches`"; system "nix-pull `cat $tmpdir/caches`";
die if $?; die if $?;
print "installing package...\n"; print "Installing package...\n";
system "nix-env -i $tmpdir/default.nix '*'"; system "nix-env -if $tmpdir/default.nix '*'";
die if $?; die if $?;
print "installing succeeded! (enter to continue)\n"; print "Installation succeeded! Press Enter to continue.\n";
<STDIN>; <STDIN>;

View file

@ -12,40 +12,52 @@ my $manifest = "$tmpdir/MANIFEST";
END { unlink $manifest; unlink $nixfile; rmdir $tmpdir; } END { unlink $manifest; unlink $nixfile; rmdir $tmpdir; }
my @paths; my $curl = "curl --fail --silent";
foreach my $id (@ARGV) {
die unless $id =~ /^\//; # Parse the command line.
my $archives_put_url = shift @ARGV;
my $archives_get_url = shift @ARGV;
my $manifest_put_url = shift @ARGV;
# From the given store expressions, determine the requisite store
# paths.
my %storepaths;
foreach my $storeexpr (@ARGV) {
die unless $storeexpr =~ /^\//;
# Get all paths referenced by the normalisation of the given # Get all paths referenced by the normalisation of the given
# Nix expression. # Nix expression.
system "nix-store --realise $id > /dev/null"; system "nix-store --realise $storeexpr > /dev/null";
die if ($?); die if ($?);
open PATHS, "nix-store --query --requisites --include-successors $id 2> /dev/null |" or die; open PATHS, "nix-store --query --requisites --include-successors $storeexpr 2> /dev/null |" or die;
while (<PATHS>) { while (<PATHS>) {
chomp; chomp;
die "bad: $_" unless /^\//; die "bad: $_" unless /^\//;
push @paths, $_; $storepaths{$_} = "";
} }
close PATHS; close PATHS;
} }
my @storepaths = keys %storepaths;
# For each path, create a Nix expression that turns the path into # For each path, create a Nix expression that turns the path into
# a Nix archive. # a Nix archive.
open NIX, ">$nixfile"; open NIX, ">$nixfile";
print NIX "["; print NIX "[";
foreach my $path (@paths) { foreach my $storepath (@storepaths) {
die unless ($storepath =~ /\/[0-9a-z]{32}.*$/);
die unless ($path =~ /\/[0-9a-z]{32}.*$/);
print "$path\n";
# 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 should be represented as a closure # !!! $storepath should be represented as a closure
"{path = \"$path\"; system = \"@system@\";}) "; "{path = \"$storepath\"; system = \"@system@\";}) ";
print NIX $nixexpr; print NIX $nixexpr;
} }
@ -54,32 +66,41 @@ print NIX "]";
close NIX; close NIX;
# Instantiate a store expression from the Nix expression. # Instantiate store expressions from the Nix expression.
my @nids; my @storeexprs;
print STDERR "instantiating Nix expression...\n"; print STDERR "instantiating store expressions...\n";
open NIDS, "nix-instantiate $nixfile |" or die "cannot run nix-instantiate"; open STOREEXPRS, "nix-instantiate $nixfile |" or die "cannot run nix-instantiate";
while (<NIDS>) { while (<STOREEXPRS>) {
chomp; chomp;
die unless /^\//; die unless /^\//;
push @nids, $_; push @storeexprs, $_;
print "$_\n";
} }
close NIDS; close STOREEXPRS;
# Realise the store expression. # Realise the store expressions.
print STDERR "creating archives...\n"; print STDERR "creating archives...\n";
system "nix-store --realise -v @nids > /dev/null";
if ($?) { die "`nix-store --realise' failed"; }
my @narpaths; my @narpaths;
open NIDS, "nix-store --query --list @nids |" or die "cannot run nix";
while (<NIDS>) { my @tmp = @storeexprs;
while (scalar @tmp > 0) {
my $n = scalar @tmp;
if ($n > 256) { $n = 256 };
my @tmp2 = @tmp[0..$n - 1];
@tmp = @tmp[$n..scalar @tmp - 1];
system "nix-store --realise -B @tmp2 > /dev/null";
if ($?) { die "`nix-store --realise' failed"; }
open NARPATHS, "nix-store --query --list @tmp2 |" or die "cannot run nix";
while (<NARPATHS>) {
chomp; chomp;
die unless (/^\//); die unless (/^\//);
push @narpaths, "$_"; push @narpaths, "$_";
} }
close NIDS; close NARPATHS;
}
# Create the manifest. # Create the manifest.
@ -87,11 +108,9 @@ print STDERR "creating manifest...\n";
open MANIFEST, ">$manifest"; open MANIFEST, ">$manifest";
my @pushlist; my @nararchives;
push @pushlist, $manifest; for (my $n = 0; $n < scalar @storepaths; $n++) {
my $storepath = $storepaths[$n];
for (my $n = 0; $n < scalar @paths; $n++) {
my $storepath = $paths[$n];
my $nardir = $narpaths[$n]; my $nardir = $narpaths[$n];
$storepath =~ /\/([^\/]*)$/; $storepath =~ /\/([^\/]*)$/;
@ -102,7 +121,7 @@ for (my $n = 0; $n < scalar @paths; $n++) {
my $narfile = "$nardir/$narname"; my $narfile = "$nardir/$narname";
(-f $narfile) or die "narfile for $storepath not found"; (-f $narfile) or die "narfile for $storepath not found";
push @pushlist, $narfile; push @nararchives, $narfile;
open MD5, "$nardir/md5" or die "cannot open hash"; open MD5, "$nardir/md5" or die "cannot open hash";
my $hash = <MD5>; my $hash = <MD5>;
@ -112,10 +131,10 @@ for (my $n = 0; $n < scalar @paths; $n++) {
print MANIFEST "{\n"; print MANIFEST "{\n";
print MANIFEST " StorePath: $storepath\n"; print MANIFEST " StorePath: $storepath\n";
print MANIFEST " NarName: $narname\n"; print MANIFEST " NarURL: $archives_get_url/$narname\n";
print MANIFEST " MD5: $hash\n"; print MANIFEST " MD5: $hash\n";
if ($storepath =~ /\.nix$/) { if ($storepath =~ /\.store$/) {
open PREDS, "nix-store --query --predecessors $storepath |" or die "cannot run nix"; open PREDS, "nix-store --query --predecessors $storepath |" or die "cannot run nix";
while (<PREDS>) { while (<PREDS>) {
chomp; chomp;
@ -131,8 +150,24 @@ for (my $n = 0; $n < scalar @paths; $n++) {
close MANIFEST; close MANIFEST;
# Push the prebuilts to the server. !!! FIXME # Upload the archives.
print STDERR "pushing to server...\n"; print STDERR "uploading archives...\n";
if (scalar @pushlist > 0) { foreach my $nararchive (@nararchives) {
system "rsync -av -e ssh @pushlist eelco\@losser.st-lab.cs.uu.nl:/home/eelco/public_html/nix-dist/";
$nararchive =~ /\/([^\/]*)$/;
my $basename = $1;
if (system("$curl --head $archives_get_url/$basename > /dev/null") != 0) {
print STDERR " $nararchive\n";
system("$curl --show-error --upload-file " .
"'$nararchive' '$archives_put_url/$basename' > /dev/null") == 0 or
die "curl failed on $nararchive: $?";
} }
}
# Upload the manifest.
print STDERR "uploading manifest...\n";
system("$curl --show-error --upload-file " .
"'$manifest' '$manifest_put_url/' > /dev/null") == 0 or
die "curl failed on $manifest: $?";