at 21.11-pre 1.5 kB view raw
1#! @perl@/bin/perl -w 2 3use strict; 4use DBI; 5use DBD::SQLite; 6use String::ShellQuote; 7use Config; 8 9my $program = $ARGV[0]; 10 11my $dbPath = "@dbPath@"; 12 13my $dbh = DBI->connect("dbi:SQLite:dbname=$dbPath", "", "") 14 or die "cannot open database `$dbPath'"; 15$dbh->{RaiseError} = 0; 16$dbh->{PrintError} = 0; 17 18my $system = $ENV{"NIX_SYSTEM"} // $Config{myarchname}; 19 20my $res = $dbh->selectall_arrayref( 21 "select package from Programs where system = ? and name = ?", 22 { Slice => {} }, $system, $program); 23 24if (!defined $res || scalar @$res == 0) { 25 print STDERR "$program: command not found\n"; 26} elsif (scalar @$res == 1) { 27 my $package = @$res[0]->{package}; 28 if ($ENV{"NIX_AUTO_INSTALL"} // "") { 29 print STDERR <<EOF; 30The program '$program' is currently not installed. It is provided by 31the package '$package', which I will now install for you. 32EOF 33 ; 34 exit 126 if system("nix-env", "-iA", "nixos.$package") == 0; 35 } elsif ($ENV{"NIX_AUTO_RUN"} // "") { 36 exec("nix-shell", "-p", $package, "--run", shell_quote("exec", @ARGV)); 37 } else { 38 print STDERR <<EOF; 39The program '$program' is not in your PATH. You can make it available in an 40ephemeral shell by typing: 41 nix-shell -p $package 42EOF 43 } 44} else { 45 print STDERR <<EOF; 46The program '$program' is not in your PATH. It is provided by several packages. 47You can make it available in an ephemeral shell by typing one of the following: 48EOF 49 print STDERR " nix-shell -p $_->{package}\n" foreach @$res; 50} 51 52exit 127;