From e468488a13f5d42a6f0029bb5a74dac47e4b17be Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 25 Mar 2013 13:17:47 +0000 Subject: [PATCH] * 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 --- generate-programs-index.pl | 57 ++++++++++++++++++++++++++++++++++++++ mirror-nixos.sh | 8 ++++++ 2 files changed, 65 insertions(+) create mode 100755 generate-programs-index.pl diff --git a/generate-programs-index.pl b/generate-programs-index.pl new file mode 100755 index 0000000..3d3d921 --- /dev/null +++ b/generate-programs-index.pl @@ -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(<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; diff --git a/mirror-nixos.sh b/mirror-nixos.sh index a131ddb..778dac2 100755 --- a/mirror-nixos.sh +++ b/mirror-nixos.sh @@ -37,6 +37,14 @@ else /data/releases/binary-cache http://nixos.org/binary-cache \ /data/releases/patches/all-patches "$url/nixos.channel/download/1" + # Generate the programs.sqlite database and put it in nixexprs.tar.xz. + mkdir $tmpDir/unpack + tar xfJ $tmpDir/nixexprs.tar.xz -C $tmpDir/unpack + exprDir=$(echo $tmpDir/unpack/*) + ./generate-programs-index.pl "$exprDir" "$exprDir/programs.sqlite" + tar cfJ $tmpDir/nixexprs.tar.xz -C $tmpDir/unpack "$(basename "$exprDir")" + rm -rf $tmpDir/unpack + mv $tmpDir $releaseDir fi