1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 06:31:14 +02:00

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.
This commit is contained in:
Eelco Dolstra 2014-02-19 17:08:01 +01:00
parent a897b58373
commit 36b90e72d7
2 changed files with 41 additions and 3 deletions

View file

@ -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;
}