#! @perl@ -w @perlFlags@ use strict; use Nix::Config; use Nix::Store; use File::Temp qw(tempdir); my $dryRun = 0; my $verbose = 0; my $runEnv = 0; my @instArgs = (); my @buildArgs = (); my @exprs = (); my $shell = $ENV{SHELL} || "/bin/sh"; my $envCommand = "p=\$PATH; source \$stdenv/setup; PATH=\$PATH:\$p; exec $shell"; my @envExclude = (); my $tmpDir = tempdir("nix-build.XXXXXX", CLEANUP => 1, TMPDIR => 1) or die "cannot create a temporary directory"; my $outLink = "./result"; my $drvLink = "$tmpDir/derivation"; # Ensure that the $tmpDir is deleted. $SIG{'INT'} = sub { exit 1 }; for (my $n = 0; $n < scalar @ARGV; $n++) { my $arg = $ARGV[$n]; if ($arg eq "--help") { print STDERR <) {chomp; push @drvPaths, $_;} if (!close DRVPATHS) { die "nix-instantiate killed by signal " . ($? & 127) . "\n" if ($? & 127); exit 1; } if ($runEnv) { die "$0: ‘--run-env’ requires a single derivation\n" if scalar @drvPaths != 1; my $drvPath = readlink $drvPaths[0] or die "cannot read symlink `$drvPaths[0]'"; my $drv = derivationFromPath($drvPath); # Build or fetch all dependencies of the derivation. 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. $ENV{'NIX_BUILD_TOP'} = $ENV{'TMPDIR'} || "/tmp"; foreach (keys %{$drv->{env}}) { $ENV{$_} = $drv->{env}->{$_}; } # Run a shell using the derivation's environment. For # convenience, source $stdenv/setup to setup additional # environment variables. Also don't lose the current $PATH # directories. exec($ENV{SHELL}, "-c", $envCommand); die; } foreach my $drvPath (@drvPaths) { my $target = readlink $drvPath or die "cannot read symlink `$drvPath'"; print STDERR "derivation is $target\n" if $verbose; } # Build. my @outPaths; $pid = open(OUTPATHS, "-|") || exec "$Nix::Config::binDir/nix-store", "--add-root", $outLink, "--indirect", "-r", @buildArgs, @drvPaths; while () {chomp; push @outPaths, $_;} if (!close OUTPATHS) { die "nix-store killed by signal " . ($? & 127) . "\n" if ($? & 127); exit 1; } next if $dryRun; foreach my $outPath (@outPaths) { my $target = readlink $outPath or die "cannot read symlink `$outPath'"; print "$target\n"; } }