nix-super/scripts/nix-push.in

82 lines
2.3 KiB
Text
Raw Normal View History

#! /usr/bin/perl -w
my @pushlist;
2003-07-16 23:00:51 +03:00
foreach my $id (@ARGV) {
2003-07-16 23:00:51 +03:00
die unless $id =~ /^([0-9a-z]{32})$/;
# Get all paths referenced by the normalisation of the given
# fstate expression.
system "nix --install $id";
if ($?) { die "`nix --install' failed"; }
my @paths;
open PATHS, "nix --query --requisites --include-successors $id 2> /dev/null |" or die "nix -qr";
while (<PATHS>) {
2003-07-10 22:27:46 +03:00
chomp;
die "bad: $_" unless /^\//;
2003-07-10 22:27:46 +03:00
push @paths, $_;
}
close PATHS;
# Also add all normal forms that are contained in these paths.
# open PATHS, "nix --query --generators --path @paths |" or die "nix -qg";
# while (<PATHS>) {
# chomp;
# die "bad: $_" unless /^\//;
# push @paths, $_;
# }
# close PATHS;
# For each path, create a Fix expression that turns the path into
# a Nix archive.
foreach my $path (@paths) {
2003-07-16 23:00:51 +03:00
next unless ($path =~ /\/([0-9a-z]{32})[^\/]*/);
my $pathid = $1;
2003-07-10 23:13:32 +03:00
# Construct a name for the Nix archive. If the file is an
# fstate successor, encode this into the name.
2003-07-16 23:00:51 +03:00
my $name = $pathid;
2003-07-10 23:13:32 +03:00
if ($path =~ /-s-([0-9a-z]{32}).nix$/) {
$name = "$name-s-$1";
}
$name = $name . ".nar.bz2";
2003-07-10 23:13:32 +03:00
# Construct a Fix expression that creates a Nix archive.
2003-07-10 22:27:46 +03:00
my $fixexpr =
"App(IncludeFix(\"nar/nar.fix\"), " .
2003-07-16 23:00:51 +03:00
"[ (\"path\", Slice([\"$pathid\"], [(\"$path\", \"$pathid\", [])]))" .
"])";
2003-07-10 22:27:46 +03:00
my $fixfile = "/tmp/nix-push-tmp.fix";
open FIX, ">$fixfile";
print FIX $fixexpr;
close FIX;
2003-07-10 22:27:46 +03:00
# Instantiate a Nix expression from the Fix expression.
2003-07-16 23:00:51 +03:00
my $nid = `fix $fixfile`;
2003-07-10 22:27:46 +03:00
$? and die "instantiating Nix archive expression";
2003-07-16 23:00:51 +03:00
chomp $nid;
die unless $nid =~ /^([0-9a-z]{32})$/;
2003-07-10 22:27:46 +03:00
# Realise the Nix expression.
system "nix --install $nid";
if ($?) { die "`nix --install' failed"; }
my $npath = `nix --query --list $nid 2> /dev/null`;
$? and die "`nix --query --list' failed";
2003-07-10 22:27:46 +03:00
chomp $npath;
push @pushlist, "$npath/*";
2003-07-10 22:27:46 +03:00
print "$path -> $npath\n";
}
}
# Push the prebuilts to the server. !!! FIXME
if (scalar @pushlist > 0) {
system "rsync -av -e ssh @pushlist eelco\@losser.st-lab.cs.uu.nl:/home/eelco/public_html/nix-dist/";
}