From 5144abe5b67628d6968d0ab829aa52a6428a77a6 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 27 Mar 2012 11:40:47 +0200 Subject: [PATCH] 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. --- scripts/nix-build.in | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/nix-build.in b/scripts/nix-build.in index cc80089fb..9e051101c 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.