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.
This commit is contained in:
parent
3e94ffffd6
commit
5144abe5b6
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue