about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-09-06T12·58+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-09-06T12·58+0200
commit5904262640199599122fcf563e7d1c7c3f3f3128 (patch)
tree589a211b6848953cf46bff1ebd034f5ecafc324b /scripts
parent2c1ecf8e81f8ea5a9fa228aa22a57a6ba0a0e4df (diff)
nix-shell: Support a .drv as argument
Fixes #161.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/nix-build.in21
1 files changed, 13 insertions, 8 deletions
diff --git a/scripts/nix-build.in b/scripts/nix-build.in
index 73c92c9a7f6c..d7805f83c3f5 100755
--- a/scripts/nix-build.in
+++ b/scripts/nix-build.in
@@ -157,17 +157,22 @@ foreach my $expr (@exprs) {
 
     # Instantiate.
     my @drvPaths;
-    # !!! would prefer the perl 5.8.0 pipe open feature here.
-    my $pid = open(DRVPATHS, "-|") || exec "$Nix::Config::binDir/nix-instantiate", "--add-root", $drvLink, "--indirect", @instArgs, $expr;
-    while (<DRVPATHS>) {chomp; push @drvPaths, $_;}
-    if (!close DRVPATHS) {
-        die "nix-instantiate killed by signal " . ($? & 127) . "\n" if ($? & 127);
-        exit 1;
+    if ($expr !~ /^\/.*\.drv$/) {
+        # !!! would prefer the perl 5.8.0 pipe open feature here.
+        my $pid = open(DRVPATHS, "-|") || exec "$Nix::Config::binDir/nix-instantiate", "--add-root", $drvLink, "--indirect", @instArgs, $expr;
+        while (<DRVPATHS>) {chomp; push @drvPaths, $_;}
+        if (!close DRVPATHS) {
+            die "nix-instantiate killed by signal " . ($? & 127) . "\n" if ($? & 127);
+            exit 1;
+        }
+    } else {
+        push @drvPaths, $expr;
     }
 
     if ($runEnv) {
         die "$0: a single derivation is required\n" if scalar @drvPaths != 1;
-        my $drvPath = readlink $drvPaths[0] or die "cannot read symlink `$drvPaths[0]'";
+        my $drvPath = $drvPaths[0];
+        $drvPath = readlink $drvPath or die "cannot read symlink `$drvPath'" if -l $drvPath;
         my $drv = derivationFromPath($drvPath);
 
         # Build or fetch all dependencies of the derivation.
@@ -235,7 +240,7 @@ foreach my $expr (@exprs) {
 
     # Build.
     my @outPaths;
-    $pid = open(OUTPATHS, "-|") || exec "$Nix::Config::binDir/nix-store", "--add-root", $outLink, "--indirect", "-r",
+    my $pid = open(OUTPATHS, "-|") || exec "$Nix::Config::binDir/nix-store", "--add-root", $outLink, "--indirect", "-r",
         @buildArgs, @drvPaths2;
     while (<OUTPATHS>) {chomp; push @outPaths, $_;}
     if (!close OUTPATHS) {