-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a programs.sqlite to the NixOS channel (for missing
command suggestions in NixOS). git-svn-id: https://nixos.org/repos/nix/release/trunk/channels@34697 70bd8c7a-acb8-0310-9f0d-9cc1c95dcdbb
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#! /run/current-system/sw/bin/perl -w | ||
|
||
use strict; | ||
use DBI; | ||
use DBD::SQLite; | ||
|
||
my $nixExprs = $ARGV[0] or die; | ||
my $dbPath = $ARGV[1] or die; | ||
|
||
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbPath", "", "") | ||
or die "cannot open database `$dbPath'"; | ||
$dbh->{RaiseError} = 1; | ||
$dbh->{PrintError} = 0; | ||
|
||
$dbh->do(<<EOF); | ||
create table if not exists Programs ( | ||
name text not null, | ||
system text not null, | ||
package text not null, | ||
primary key (name, system, package) | ||
); | ||
EOF | ||
|
||
my $insertProgram = $dbh->prepare("insert or replace into Programs(name, system, package) values (?, ?, ?)"); | ||
|
||
$dbh->begin_work; | ||
|
||
sub process_dir { | ||
my ($system, $pkgname, $dir) = @_; | ||
return unless -d $dir; | ||
print STDERR "indexing $dir\n"; | ||
opendir DH, "$dir" or die "opening $dir"; | ||
for my $program (readdir DH) { | ||
next if substr($program, 0, 1) eq "."; | ||
$insertProgram->execute($program, $system, $pkgname); | ||
} | ||
closedir DH; | ||
} | ||
|
||
for my $system ("x86_64-linux", "i686-linux") { | ||
print STDERR "indexing programs for $system...\n"; | ||
|
||
my $out = `nix-env -f $nixExprs -qa \\* --out-path --argstr system $system`; | ||
die "cannot evaluate Nix expressions for $system" if $? != 0; | ||
|
||
foreach my $line (split "\n", $out) { | ||
my ($name, $outPath) = split ' ', $line; | ||
die unless $name && $outPath; | ||
next unless -d $outPath; | ||
my $pkgname = $name; | ||
$pkgname =~ s/-\d.*//; | ||
process_dir($system, $pkgname, "$outPath/bin"); | ||
process_dir($system, $pkgname, "$outPath/sbin"); | ||
} | ||
} | ||
|
||
$dbh->commit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters