about summary refs log tree commit diff
path: root/scripts/nix-push.in
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/nix-push.in')
-rwxr-xr-xscripts/nix-push.in18
1 files changed, 17 insertions, 1 deletions
diff --git a/scripts/nix-push.in b/scripts/nix-push.in
index 2c392c4155d7..bdd128a6f5c2 100755
--- a/scripts/nix-push.in
+++ b/scripts/nix-push.in
@@ -10,6 +10,7 @@ use Nix::Config;
 use Nix::Store;
 use Nix::Manifest;
 use Nix::Utils;
+use Nix::Crypto;
 
 my $tmpDir = tempdir("nix-push.XXXXXX", CLEANUP => 1, TMPDIR => 1)
     or die "cannot create a temporary directory";
@@ -25,6 +26,8 @@ my $writeManifest = 0;
 my $manifestPath;
 my $archivesURL;
 my $link = 0;
+my $privateKeyFile;
+my $keyName;
 my @roots;
 
 for (my $n = 0; $n < scalar @ARGV; $n++) {
@@ -57,6 +60,14 @@ for (my $n = 0; $n < scalar @ARGV; $n++) {
         $archivesURL = $ARGV[$n];
     } elsif ($arg eq "--link") {
         $link = 1;
+    } elsif ($arg eq "--key") {
+        $n++;
+        die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
+        $privateKeyFile = $ARGV[$n];
+    } elsif ($arg eq "--key-name") {
+        $n++;
+        die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
+        $keyName = $ARGV[$n];
     } elsif (substr($arg, 0, 1) eq "-") {
         die "$0: unknown flag `$arg'\n";
     } else {
@@ -99,7 +110,7 @@ foreach my $storePath (@storePaths) {
     my $pathHash = substr(basename($storePath), 0, 32);
     my $narInfoFile = "$destDir/$pathHash.narinfo";
     if (-e $narInfoFile) {
-        my $narInfo = parseNARInfo($storePath, readFile($narInfoFile));
+        my $narInfo = parseNARInfo($storePath, readFile($narInfoFile), 0, $narInfoFile) or die "cannot read `$narInfoFile'\n";
         my $narFile = "$destDir/$narInfo->{url}";
         if (-e $narFile) {
             print STDERR "skipping existing $storePath\n";
@@ -245,6 +256,11 @@ for (my $n = 0; $n < scalar @storePaths2; $n++) {
         }
     }
 
+    if (defined $privateKeyFile && defined $keyName) {
+        my $sig = signString($privateKeyFile, $info);
+        $info .= "Signature: 1;$keyName;$sig\n";
+    }
+
     my $pathHash = substr(basename($storePath), 0, 32);
 
     $dst = "$destDir/$pathHash.narinfo";