about summary refs log tree commit diff
path: root/scripts/nix-push-prebuilts
blob: 2e3029b1699f461d11529829894ec356b98ae0b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /usr/bin/perl -w

my $prefix = $ENV{"NIX"} || "/nix"; # !!! use prefix
my $etcdir = "$prefix/etc/nix";
my $exportdir = "$prefix/var/nix/prebuilts/exports";
my $knowns = "$prefix/var/nix/known-prebuilts";

# For performance, put the known hashes in an associative array.
my %knowns = ();
open KNOWNS, "<$knowns";
while (<KNOWNS>) {
    next unless /([0-9a-z]{32})/;
    $knowns{$1} = 1;
}
close KNOWNS;

# For each installed package, check whether a prebuilt is known.

open PKGS, "nix listinst|";
open KNOWNS, ">>$knowns";

while (<PKGS>) {
    chomp;
    next unless /([0-9a-z]{32})/;
    my $pkghash = $1;
    if (!defined $knowns{$1}) {
        # No known prebuilt exists for this package; so export it.
        print "exporting $pkghash...\n";
        system "nix export '$exportdir' $pkghash";
        if ($?) { die "`nix export' failed"; }
        print KNOWNS "$pkghash\n";
    }
}

close KNOWNS;
close PKGS;

# Push the prebuilts to the server. !!! FIXME

system "rsync -av -e ssh '$exportdir' losser:/home/eelco/public_html/nix-prebuilts/";