about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-02-19T16·08+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-02-19T16·08+0100
commit36b90e72d7e09b983acfa08f9016e8b3ece5199d (patch)
tree8e34c7062af15c4e456ee5391cc4dc7449ce73fe /scripts
parenta897b583733aaf3ee7aa0efe495f9ea046567555 (diff)
nix-shell: Add --packages flag
This allows you to easily set up a build environment containing the
specified packages from Nixpkgs.  For example:

  $ nix-shell -p sqlite xorg.libX11 hello

will start a shell in which the given packages are present.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/nix-build.in12
1 files changed, 11 insertions, 1 deletions
diff --git a/scripts/nix-build.in b/scripts/nix-build.in
index cc6ab423d825..452cb901fac2 100755
--- a/scripts/nix-build.in
+++ b/scripts/nix-build.in
@@ -12,6 +12,7 @@ my $verbose = 0;
 my $runEnv = $0 =~ /nix-shell$/;
 my $pure = 0;
 my $fromArgs = 0;
+my $packages = 0;
 
 my @instArgs = ();
 my @buildArgs = ();
@@ -150,6 +151,10 @@ for (my $n = 0; $n < scalar @ARGV; $n++) {
         push @instArgs, "--expr";
     }
 
+    elsif ($arg eq "--packages" || $arg eq "-p") {
+        $packages = 1;
+    }
+
     elsif (substr($arg, 0, 1) eq "-") {
         push @buildArgs, $arg;
     }
@@ -159,7 +164,12 @@ for (my $n = 0; $n < scalar @ARGV; $n++) {
     }
 }
 
-if (!$fromArgs) {
+if ($packages) {
+    push @instArgs, "--expr";
+    @exprs = (
+        'with import <nixpkgs> { }; runCommand "shell" { buildInputs = [ '
+        . (join " ", map { "($_)" } @exprs) . ']; } ""');
+} elsif (!$fromArgs) {
     @exprs = ("shell.nix") if scalar @exprs == 0 && $runEnv && -e "shell.nix";
     @exprs = ("default.nix") if scalar @exprs == 0;
 }