--- lcov-1.8/bin/geninfo	2010-01-29 11:14:46.000000000 +0100
+++ lcov-1.8/bin/geninfo	2010-04-18 23:33:43.000000000 +0200
@@ -51,6 +51,7 @@
 
 use strict;
 use File::Basename; 
+use Cwd qw(abs_path);
 use File::Spec::Functions qw /abs2rel catdir file_name_is_absolute splitdir
 			      splitpath rel2abs/;
 use Getopt::Long;
@@ -95,6 +96,7 @@ sub match_filename($@);
 sub solve_ambiguous_match($$$);
 sub split_filename($);
 sub solve_relative_path($$);
+sub find_source_file($$);
 sub read_gcov_header($);
 sub read_gcov_file($);
 sub info(@);
@@ -964,7 +966,7 @@ sub process_dafile($$)
 
 		if (defined($source))
 		{
-			$source = solve_relative_path($base_dir, $source);
+ 			$source = find_source_file($base_dir, $source);
 		}
 
 		# gcov will happily create output even if there's no source code
@@ -981,18 +983,9 @@ sub process_dafile($$)
 			die("ERROR: could not read source file $source\n");
 		}
 
-		@matches = match_filename(defined($source) ? $source :
-					  $gcov_file, keys(%{$instr}));
+		next if ! -r $source;
 
-		# Skip files that are not mentioned in the graph file
-		if (!@matches)
-		{
-			warn("WARNING: cannot find an entry for ".$gcov_file.
-			     " in $graph_file_extension file, skipping ".
-			     "file!\n");
-			unlink($gcov_file);
-			next;
-		}
+		@matches = ($source);
 
 		# Read in contents of gcov file
 		@result = read_gcov_file($gcov_file);
@@ -1242,6 +1235,25 @@ sub solve_relative_path($$)
 }
 
 
+sub find_source_file($$)
+{
+        my ($base_dir, $source) = @_;
+        my $dir = $base_dir;
+
+        # Hack to make absolute paths work on Nixpkgs coverage
+        # reports.  The source is in /nix/store/<bla>/.build/<bla>.
+        $source = $1 if $source =~ /^\/.*\/\.build\/(.*)$/;
+        
+        while (!-e "$dir/$source") {
+                $dir = $dir . "/..";
+                if (length $dir > 1000) {
+                        return "$base_dir/$source";
+                }
+        }
+        return abs_path("$dir/$source");
+}
+
+
 #
 # match_filename(gcov_filename, list)
 #
@@ -1918,7 +1930,7 @@ sub process_graphfile($$)
 
 	# Get path to data file in absolute and normalized form (begins with /,
 	# contains no more ../ or ./)
-	$graph_filename = solve_relative_path($cwd, $graph_filename);
+	$graph_filename = find_source_file($cwd, $graph_filename);
 
 	# Get directory and basename of data file
 	($graph_dir, $graph_basename) = split_filename($graph_filename);

