1 { lib, buildGoModule, fetchFromGitHub }:
7 src = fetchFromGitHub {
11 hash = "sha256-FzlukSQSKeQY6H53UfWXwL8bXkOXRhaA92/Kgxh4oms=";
12 # Apparently upstream requires that the compiled executable will know the
13 # commit hash and the date of the commit. This information is also presented
14 # in the output of `pdfcpu version` which we use as a sanity check in the
15 # installCheckPhase. This was discussed upstream in:
17 # - https://github.com/pdfcpu/pdfcpu/issues/751
18 # - https://github.com/pdfcpu/pdfcpu/pull/752
20 # The trick used here is to write that information into files in `src`'s
21 # `$out`, and then read them into the `ldflags`. We also delete the `.git`
22 # directories in `src`'s $out afterwards, imitating what's done if
23 # `leaveDotGit = false;` See also:
24 # https://github.com/NixOS/nixpkgs/issues/8567
28 git rev-parse HEAD > $out/COMMIT
29 git log -1 --pretty=%cd --date=format:'%Y-%m-%dT%H:%M:%SZ' > $out/SOURCE_DATE
30 find "$out" -name .git -print0 | xargs -0 rm -rf
34 vendorHash = "sha256-jVX/CFf9dd9qD3gyGVDjbfINtPLCsgdjWFix4BCpDZ0=";
39 "-X main.version=v${version}"
42 # ldflags based on metadata from git and source
44 ldflags+=" -X main.commit=$(cat COMMIT)"
45 ldflags+=" -X main.date=$(cat SOURCE_DATE)"
51 doInstallCheck = true;
52 installCheckPhase = ''
53 export HOME=$(mktemp -d)
54 echo checking the version print of pdfcpu
55 $out/bin/pdfcpu version | grep ${version}
56 $out/bin/pdfcpu version | grep $(cat COMMIT | cut -c1-8)
57 $out/bin/pdfcpu version | grep $(cat SOURCE_DATE)
60 subPackages = [ "cmd/pdfcpu" ];
63 description = "A PDF processor written in Go";
64 homepage = "https://pdfcpu.io";
65 license = licenses.asl20;
66 maintainers = with maintainers; [ doronbehar ];
67 mainProgram = "pdfcpu";