From 3628b1c6bf84f00e67c4a81e9063607f0348a4d6 Mon Sep 17 00:00:00 2001
From: Peter Hoeg <peter@hoeg.com>
Date: Wed, 29 Apr 2020 13:58:15 +0800
Subject: [PATCH] libeatmydata: allow building from checkout

Also include note about running tests.
---
 .../libraries/libeatmydata/default.nix        | 38 ++++++++++++++-----
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/pkgs/development/libraries/libeatmydata/default.nix b/pkgs/development/libraries/libeatmydata/default.nix
index aeaa45a7905..da7a186bea6 100644
--- a/pkgs/development/libraries/libeatmydata/default.nix
+++ b/pkgs/development/libraries/libeatmydata/default.nix
@@ -1,23 +1,41 @@
-{ stdenv, fetchurl, makeWrapper }:
+{ stdenv, fetchFromGitHub, autoreconfHook, strace, which }:
 
 stdenv.mkDerivation rec {
-  name = "libeatmydata-105";
+  pname = "libeatmydata";
+  version = "105";
 
-  src = fetchurl {
-    url = "https://www.flamingspork.com/projects/libeatmydata/${name}.tar.gz";
-    sha256 = "1pd8sc73cgc41ldsvq6g8ics1m5k8gdcb91as9yg8z5jnrld1lmx";
+  src = fetchFromGitHub {
+    owner = "stewartsmith";
+    repo = pname;
+    rev = "${pname}-${version}";
+    sha256 = "0sx803h46i81h67xbpd3c7ky0nhaw4gij214nsx4lqig70223v9r";
   };
 
   patches = [ ./find-shell-lib.patch ];
+
   patchFlags = "-p0";
+
   postPatch = ''
-    substituteInPlace eatmydata.in --replace NIX_OUT_DIR $out
+    substituteInPlace eatmydata.in \
+      --replace NIX_OUT_DIR $out
+
+    patchShebangs .
   '';
 
-  meta = {
-    homepage = "https://www.flamingspork.com/projects/libeatmydata/";
-    license = stdenv.lib.licenses.gpl3Plus;
+  nativeBuildInputs = [
+    autoreconfHook
+  ] ++ stdenv.lib.optionals doCheck [ strace which ];
+
+  # while we can *build* in parallel, the tests also run in parallel which does
+  # not work with v105. Later versions (unreleased) have a fix for that. The
+  # problem is that on hydra we cannot use strace, so the tests don't run there.
+  enableParallelBuilding = true;
+  doCheck = false;
+
+  meta = with stdenv.lib; {
     description = "Small LD_PRELOAD library to disable fsync and friends";
-    platforms = stdenv.lib.platforms.unix;
+    homepage = "https://www.flamingspork.com/projects/libeatmydata/";
+    license = licenses.gpl3Plus;
+    platforms = platforms.unix;
   };
 }