lix/scripts/nix-push.in

143 lines
3.1 KiB
Text
Raw Normal View History

#! /usr/bin/perl -w
use strict;
use POSIX qw(tmpnam);
my $tmpdir;
do { $tmpdir = tmpnam(); }
until mkdir $tmpdir, 0777;
my $fixfile = "$tmpdir/create-nars.fix";
my $manifest = "$tmpdir/MANIFEST";
END { unlink $manifest; unlink $fixfile; rmdir $tmpdir; }
2003-08-05 12:30:06 +00:00
open FIX, ">$fixfile";
print FIX "[";
my $first = 1;
my @paths;
2003-07-16 20:00:51 +00:00
foreach my $id (@ARGV) {
die unless $id =~ /^\//;
# Get all paths referenced by the normalisation of the given
# Nix expression.
system "nix --install $id > /dev/null";
if ($?) { die "`nix --install' failed"; }
open PATHS, "nix --query --requisites --include-successors $id 2> /dev/null |" or die "nix -qr";
while (<PATHS>) {
2003-07-10 19:27:46 +00:00
chomp;
die "bad: $_" unless /^\//;
2003-07-10 19:27:46 +00:00
push @paths, $_;
}
close PATHS;
# For each path, create a Fix expression that turns the path into
# a Nix archive.
foreach my $path (@paths) {
die unless ($path =~ /\/[0-9a-z]{32}.*$/);
2003-08-05 12:30:06 +00:00
print "$path\n";
2003-07-10 20:13:32 +00:00
# Construct a Fix expression that creates a Nix archive.
2003-07-10 19:27:46 +00:00
my $fixexpr =
"Call(IncludeFix(\"nar/nar.fix\"), " .
"[ (\"path\", Closure([\"$path\"], [(\"$path\", [])]))" .
"])";
2003-08-05 12:30:06 +00:00
print FIX "," unless ($first);
$first = 0;
2003-07-10 19:27:46 +00:00
print FIX $fixexpr;
2003-08-05 12:30:06 +00:00
}
}
2003-08-05 12:30:06 +00:00
print FIX "]";
close FIX;
2003-08-05 12:30:06 +00:00
# Instantiate a Nix expression from the Fix expression.
my @nids;
print STDERR "running fix...\n";
open NIDS, "fix $fixfile |" or die "cannot run fix";
while (<NIDS>) {
chomp;
die unless /^\//;
push @nids, $_;
2003-08-05 12:30:06 +00:00
}
close NIDS;
2003-08-05 12:30:06 +00:00
# Realise the Nix expression.
print STDERR "creating archives...\n";
system "nix --install -v @nids > /dev/null";
2003-08-05 12:30:06 +00:00
if ($?) { die "`nix --install' failed"; }
my @narpaths;
2003-08-05 12:30:06 +00:00
open NIDS, "nix --query --list @nids |" or die "cannot run nix";
while (<NIDS>) {
chomp;
die unless (/^\//);
push @narpaths, "$_";
}
close NIDS;
# Create the manifest.
print STDERR "creating manifest...\n";
open MANIFEST, ">$manifest";
my @pushlist;
push @pushlist, $manifest;
for (my $n = 0; $n < scalar @paths; $n++) {
my $storepath = $paths[$n];
my $nardir = $narpaths[$n];
$storepath =~ /\/([^\/]*)$/;
my $basename = $1;
defined $basename or die;
my $narname = "$basename.nar.bz2";
my $narfile = "$nardir/$narname";
(-f $narfile) or die "narfile for $storepath not found";
push @pushlist, $narfile;
open MD5, "$nardir/md5" or die "cannot open hash";
my $hash = <MD5>;
chomp $hash;
$hash =~ /^[0-9a-z]{32}$/ or die "invalid hash";
close MD5;
print MANIFEST "{\n";
print MANIFEST " StorePath: $storepath\n";
2003-10-20 09:08:44 +00:00
print MANIFEST " NarName: $narname\n";
print MANIFEST " MD5: $hash\n";
if ($storepath =~ /\.nix$/) {
open PREDS, "nix --query --predecessors $storepath |" or die "cannot run nix";
while (<PREDS>) {
chomp;
die unless (/^\//);
print MANIFEST " SuccOf: $_\n";
}
close PREDS;
}
print MANIFEST "}\n";
}
close MANIFEST;
# Push the prebuilts to the server. !!! FIXME
print STDERR "pushing to server...\n";
if (scalar @pushlist > 0) {
system "rsync -av -e ssh @pushlist eelco\@losser.st-lab.cs.uu.nl:/home/eelco/public_html/nix-dist/";
}