2003-07-10 13:41:28 +00:00
|
|
|
#! /usr/bin/perl -w
|
|
|
|
|
2003-10-16 13:13:39 +00:00
|
|
|
use strict;
|
|
|
|
use POSIX qw(tmpnam);
|
|
|
|
|
|
|
|
my $tmpdir;
|
|
|
|
do { $tmpdir = tmpnam(); }
|
|
|
|
until mkdir $tmpdir, 0777;
|
|
|
|
|
2003-11-22 20:39:51 +00:00
|
|
|
my $nixfile = "$tmpdir/create-nars.nix";
|
2003-10-16 13:13:39 +00:00
|
|
|
my $manifest = "$tmpdir/MANIFEST";
|
|
|
|
|
|
|
|
END { unlink $manifest; unlink $fixfile; rmdir $tmpdir; }
|
|
|
|
|
2003-11-22 20:39:51 +00:00
|
|
|
open NIX, ">$nixfile";
|
|
|
|
print NIX "[";
|
2003-07-10 13:41:28 +00:00
|
|
|
|
2003-10-16 13:13:39 +00:00
|
|
|
my @paths;
|
|
|
|
|
2003-07-16 20:00:51 +00:00
|
|
|
foreach my $id (@ARGV) {
|
2003-07-10 13:41:28 +00:00
|
|
|
|
2003-10-16 13:13:39 +00:00
|
|
|
die unless $id =~ /^\//;
|
2003-07-10 13:41:28 +00:00
|
|
|
|
|
|
|
# Get all paths referenced by the normalisation of the given
|
2003-10-07 12:27:49 +00:00
|
|
|
# Nix expression.
|
2003-11-22 20:39:51 +00:00
|
|
|
system "nix-store --realise $id > /dev/null";
|
|
|
|
die if ($?);
|
2003-07-21 21:34:56 +00:00
|
|
|
|
2003-11-22 20:39:51 +00:00
|
|
|
open PATHS, "nix-store --query --requisites --include-successors $id 2> /dev/null |" or die;
|
2003-07-10 13:41:28 +00:00
|
|
|
while (<PATHS>) {
|
2003-07-10 19:27:46 +00:00
|
|
|
chomp;
|
2003-07-21 21:34:56 +00:00
|
|
|
die "bad: $_" unless /^\//;
|
2003-07-10 19:27:46 +00:00
|
|
|
push @paths, $_;
|
2003-07-10 13:41:28 +00:00
|
|
|
}
|
|
|
|
close PATHS;
|
|
|
|
|
2003-11-22 20:39:51 +00:00
|
|
|
# For each path, create a Nix expression that turns the path into
|
2003-07-10 13:41:28 +00:00
|
|
|
# a Nix archive.
|
|
|
|
foreach my $path (@paths) {
|
|
|
|
|
2003-11-22 20:39:51 +00:00
|
|
|
die unless ($path =~ /\/[0-9a-z]{32}.*$/);
|
|
|
|
print "$path\n";
|
2003-07-10 13:41:28 +00:00
|
|
|
|
2003-11-22 20:39:51 +00:00
|
|
|
# Construct a Nix expression that creates a Nix archive.
|
|
|
|
my $nixexpr =
|
|
|
|
"((import @datadir@/nix/corepkgs/nar/nar.nix) " .
|
|
|
|
# !!! $path should be represented as a closure
|
|
|
|
"{path = \"$path\"; system = \"@host@\"}) ";
|
|
|
|
|
|
|
|
print NIX $nixexpr;
|
2003-08-05 12:30:06 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-10 13:41:28 +00:00
|
|
|
|
2003-11-22 20:39:51 +00:00
|
|
|
print NIX "]";
|
|
|
|
close NIX;
|
2003-08-05 12:30:06 +00:00
|
|
|
|
2003-10-16 13:13:39 +00:00
|
|
|
|
2003-11-22 20:39:51 +00:00
|
|
|
# Instantiate a store expression from the Nix expression.
|
2003-08-05 12:30:06 +00:00
|
|
|
my @nids;
|
2003-11-22 20:39:51 +00:00
|
|
|
print STDERR "instantiating Nix expression...\n";
|
|
|
|
open NIDS, "nix-instantiate $nixfile |" or die "cannot run nix-instantiate";
|
2003-08-05 12:30:06 +00:00
|
|
|
while (<NIDS>) {
|
|
|
|
chomp;
|
2003-10-16 13:13:39 +00:00
|
|
|
die unless /^\//;
|
|
|
|
push @nids, $_;
|
2003-08-05 12:30:06 +00:00
|
|
|
}
|
2003-10-16 13:13:39 +00:00
|
|
|
close NIDS;
|
2003-07-10 13:41:28 +00:00
|
|
|
|
|
|
|
|
2003-11-22 20:39:51 +00:00
|
|
|
# Realise the store expression.
|
2003-08-05 12:30:06 +00:00
|
|
|
print STDERR "creating archives...\n";
|
2003-11-22 20:39:51 +00:00
|
|
|
system "nix-store --realise -v @nids > /dev/null";
|
|
|
|
if ($?) { die "`nix --realise' failed"; }
|
2003-08-05 12:30:06 +00:00
|
|
|
|
2003-10-16 13:13:39 +00:00
|
|
|
my @narpaths;
|
2003-11-22 20:39:51 +00:00
|
|
|
open NIDS, "nix-store --query --list @nids |" or die "cannot run nix";
|
2003-08-05 12:30:06 +00:00
|
|
|
while (<NIDS>) {
|
|
|
|
chomp;
|
|
|
|
die unless (/^\//);
|
2003-10-16 13:13:39 +00:00
|
|
|
push @narpaths, "$_";
|
2003-07-10 13:41:28 +00:00
|
|
|
}
|
2003-10-16 13:13:39 +00:00
|
|
|
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";
|
2003-10-16 13:13:39 +00:00
|
|
|
print MANIFEST " MD5: $hash\n";
|
|
|
|
|
|
|
|
if ($storepath =~ /\.nix$/) {
|
2003-11-22 20:39:51 +00:00
|
|
|
open PREDS, "nix-store --query --predecessors $storepath |" or die "cannot run nix";
|
|
|
|
while (<PREDS>) {
|
|
|
|
chomp;
|
|
|
|
die unless (/^\//);
|
|
|
|
print MANIFEST " SuccOf: $_\n";
|
|
|
|
}
|
|
|
|
close PREDS;
|
2003-10-16 13:13:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print MANIFEST "}\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
close MANIFEST;
|
|
|
|
|
2003-07-10 13:41:28 +00:00
|
|
|
|
|
|
|
# Push the prebuilts to the server. !!! FIXME
|
2003-10-16 13:13:39 +00:00
|
|
|
print STDERR "pushing to server...\n";
|
2003-07-10 20:34:29 +00:00
|
|
|
if (scalar @pushlist > 0) {
|
|
|
|
system "rsync -av -e ssh @pushlist eelco\@losser.st-lab.cs.uu.nl:/home/eelco/public_html/nix-dist/";
|
|
|
|
}
|