about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-03-27T09·40+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-03-27T09·40+0200
commit5144abe5b67628d6968d0ab829aa52a6428a77a6 (patch)
tree09e51c80a4120161051816336e9667a53393b2d5
parent3e94ffffd61573624883c02744f20ac3544ff9cb (diff)
Add an option "--exclude" to filter dependencies in "nix-build --run-env"
Sometimes when doing "nix-build --run-env" you don't want all
dependencies to be built.  For instance, if we want to do "--run-env"
on the "build" attribute in Hydra's release.nix (to get Hydra's build
environment), we don't want its "tarball" dependency to be built.  So
we can do:

  $ nix-build --run-env release.nix -A build --exclude 'hydra-tarball'

This will skip the dependency whose name matches the "hydra-tarball"
regular expression.  The "--exclude" option can be repeated any number
of times.
-rwxr-xr-xscripts/nix-build.in10
1 files changed, 9 insertions, 1 deletions
diff --git a/scripts/nix-build.in b/scripts/nix-build.in
index cc80089fb683..9e051101c783 100755
--- a/scripts/nix-build.in
+++ b/scripts/nix-build.in
@@ -15,6 +15,7 @@ my @buildArgs = ();
 my @exprs = ();
 
 my $envCommand = "p=\$PATH; source \$stdenv/setup; PATH=\$PATH:\$p; exec $ENV{SHELL}";
+my @envExclude = ();
 
 
 my $tmpDir = tempdir("nix-build.XXXXXX", CLEANUP => 1, TMPDIR => 1)
@@ -133,6 +134,12 @@ EOF
         $envCommand = $ARGV[$n];
     }
 
+    elsif ($arg eq "--exclude") {
+        $n++;
+        die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
+        push @envExclude, $ARGV[$n];
+    }
+
     elsif (substr($arg, 0, 1) eq "-") {
         push @buildArgs, $arg;
     }
@@ -163,7 +170,8 @@ foreach my $expr (@exprs) {
         my $drv = derivationFromPath($drvPath);
 
         # Build or fetch all dependencies of the derivation.
-        system("$Nix::Config::binDir/nix-store -r @buildArgs @{$drv->{inputDrvs}} @{$drv->{inputSrcs}} > /dev/null") == 0
+        my @inputDrvs = grep { my $x = $_; (grep { $x =~ $_ } @envExclude) == 0 } @{$drv->{inputDrvs}};
+        system("$Nix::Config::binDir/nix-store -r @buildArgs @inputDrvs @{$drv->{inputSrcs}} > /dev/null") == 0
             or die "$0: failed to build all dependencies\n";
 
         # Set the environment.