about summary refs log blame commit diff
path: root/scripts/nix-push.in
blob: e51f903b87fe4e15ab1f905ec8d21a4080f68563 (plain) (tree)
1
2
3
4
5
6
7
8
9

                   



                                      
 
                        
 
                                         


                                                                 


                                             
              
 
                                                                                                    
                     
              
                                   
                        


                
                                                                  






                                                                             
 



                                                                     
                                                        
                        
                        
 

                                                                  
                           


                                                
                                   

                                                                
                      
                                               
                                                                              

               

                                      
                           
 

     
 











                                                       
 
 











                                                                


                                             


                                                                                                        
#! /usr/bin/perl -w

my $fixfile = "/tmp/nix-push-tmp.fix";
open FIX, ">$fixfile";
print FIX "[";
my $first = 1;

foreach my $id (@ARGV) {

    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>) {
        chomp;
        die "bad: $_" unless /^\//;
        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) {

	next unless ($path =~ /\/([0-9a-z]{32})[^\/]*/);
	print "$path\n";
	my $pathid = $1;

        # Construct a name for the Nix archive.  If the file is an
        # fstate successor, encode this into the name.
        my $name = $pathid;
        if ($path =~ /-s-([0-9a-z]{32}).nix$/) {
            $name = "$name-s-$1";
        }
        $name = $name . ".nar.bz2";

        # Construct a Fix expression that creates a Nix archive.
        my $fixexpr = 
          "App(IncludeFix(\"nar/nar.fix\"), " .
          "[ (\"path\", Slice([\"$path\"], [(\"$path\", \"$pathid\", [])]))" .
          "])";
	
	print FIX "," unless ($first);
	$first = 0;
        print FIX $fixexpr;

    }
}

print FIX "]";
close FIX;

# 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 /^([0-9a-z]{32})$/;
    push @nids, $1;
}


# Realise the Nix expression.
my @pushlist;
print STDERR "creating archives...\n";
system "nix --install @nids > /dev/null";
if ($?) { die "`nix --install' failed"; }

open NIDS, "nix --query --list @nids |" or die "cannot run nix";
while (<NIDS>) {
    chomp;
    die unless (/^\//);
    print "$_\n";
    push @pushlist, "$_/*";
}

# 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/";
}