diff --git a/generate-programs-index.pl b/generate-programs-index.pl index d2c0169..ed75494 100755 --- a/generate-programs-index.pl +++ b/generate-programs-index.pl @@ -45,16 +45,28 @@ sub process_dir { for my $system ("x86_64-linux", "i686-linux") { print STDERR "indexing programs for $system...\n"; - my $out = `nix-env -f $nixExprs -qaP \\* --out-path --argstr system $system`; + my $out = `nix-env -f $nixExprs -qaP \\* --drv-path --out-path --argstr system $system`; die "cannot evaluate Nix expressions for $system" if $? != 0; + my %packages; + foreach my $line (split "\n", $out) { - my ($attrName, $name, $outPath) = split ' ', $line; + my ($attrName, $name, $drvPath, $outPath) = split ' ', $line; die unless $attrName && $name && $outPath; next unless defined $narFiles{$outPath}; next unless -d $outPath; - process_dir($system, $attrName, "$outPath/bin"); - process_dir($system, $attrName, "$outPath/sbin"); + my $prev = $packages{$drvPath}; + # Prefer shorter attribute names. + next if defined $prev && + (length($prev->{attrName}) < length($attrName) || + (length($prev->{attrName}) == length($attrName) && $prev->{attrName} le $attrName)); + $packages{$drvPath} = { attrName => $attrName, outPath => $outPath }; + } + + foreach my $drvPath (keys %packages) { + my $pkg = $packages{$drvPath}; + process_dir($system, $pkg->{attrName}, "$pkg->{outPath}/bin"); + process_dir($system, $pkg->{attrName}, "$pkg->{outPath}/sbin"); } }