summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2016-01-03 03:22:50 +0300
committerNikolay Amiantov <ab@fmap.me>2016-01-03 03:22:50 +0300
commite312276b012c2beb93a21890933d32ed1a31c791 (patch)
tree8d9650ae6c88d0a7a282757e0132c16eea7af3d8 /nixos
parent91fbdd3ee2aa9aed769520fefc8c5a2b8a1db60a (diff)
parente60c4995fdea8ab86115149f89fca84275480fb7 (diff)
downloadnixlib-e312276b012c2beb93a21890933d32ed1a31c791.tar
nixlib-e312276b012c2beb93a21890933d32ed1a31c791.tar.gz
nixlib-e312276b012c2beb93a21890933d32ed1a31c791.tar.bz2
nixlib-e312276b012c2beb93a21890933d32ed1a31c791.tar.lz
nixlib-e312276b012c2beb93a21890933d32ed1a31c791.tar.xz
nixlib-e312276b012c2beb93a21890933d32ed1a31c791.tar.zst
nixlib-e312276b012c2beb93a21890933d32ed1a31c791.zip
Merge pull request #12000 from nathan7/nix-auto-run
command-not-found: add NIX_AUTO_RUN option, to automatically invoke nix-shell
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/programs/command-not-found/command-not-found.nix6
-rw-r--r--nixos/modules/programs/command-not-found/command-not-found.pl3
2 files changed, 6 insertions, 3 deletions
diff --git a/nixos/modules/programs/command-not-found/command-not-found.nix b/nixos/modules/programs/command-not-found/command-not-found.nix
index 9524d91ea3bc..9741aa7ca539 100644
--- a/nixos/modules/programs/command-not-found/command-not-found.nix
+++ b/nixos/modules/programs/command-not-found/command-not-found.nix
@@ -16,7 +16,7 @@ let
     isExecutable = true;
     inherit (pkgs) perl;
     perlFlags = concatStrings (map (path: "-I ${path}/lib/perl5/site_perl ")
-      [ pkgs.perlPackages.DBI pkgs.perlPackages.DBDSQLite ]);
+      [ pkgs.perlPackages.DBI pkgs.perlPackages.DBDSQLite pkgs.perlPackages.StringShellQuote ]);
   };
 
 in
@@ -30,7 +30,7 @@ in
         local p=/run/current-system/sw/bin/command-not-found
         if [ -x $p -a -f /nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite ]; then
           # Run the helper program.
-          $p "$1"
+          $p "$@"
           # Retry the command if we just installed it.
           if [ $? = 126 ]; then
             "$@"
@@ -51,7 +51,7 @@ in
         local p=/run/current-system/sw/bin/command-not-found
         if [ -x $p -a -f /nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite ]; then
           # Run the helper program.
-          $p "$1"
+          $p "$@"
 
           # Retry the command if we just installed it.
           if [ $? = 126 ]; then
diff --git a/nixos/modules/programs/command-not-found/command-not-found.pl b/nixos/modules/programs/command-not-found/command-not-found.pl
index b233d973a4ab..5bdda26592e6 100644
--- a/nixos/modules/programs/command-not-found/command-not-found.pl
+++ b/nixos/modules/programs/command-not-found/command-not-found.pl
@@ -3,6 +3,7 @@
 use strict;
 use DBI;
 use DBD::SQLite;
+use String::ShellQuote;
 use Config;
 
 my $program = $ARGV[0];
@@ -31,6 +32,8 @@ the package ‘$package’, which I will now install for you.
 EOF
         ;
         exit 126 if system("nix-env", "-iA", "nixos.$package") == 0;
+    } elsif ($ENV{"NIX_AUTO_RUN"} // "") {
+        exec("nix-shell", "-p", $package, "--run", shell_quote("exec", @ARGV));
     } else {
         print STDERR <<EOF;
 The program ‘$program’ is currently not installed. You can install it by typing: