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