chroma: do version info substitution in postFetch

This should increase reproducibility of the derivation as we can delete
the .git directory in the src derivation.

authored by

sternenseemann and committed by
sterni
b5460f9c 801a040d

+17 -14
+17 -14
pkgs/tools/text/chroma/default.nix
··· 1 - { lib, buildGoModule, fetchFromGitHub, git }: 1 + { lib, buildGoModule, fetchFromGitHub }: 2 2 3 3 buildGoModule rec { 4 4 pname = "chroma"; ··· 8 8 owner = "alecthomas"; 9 9 repo = pname; 10 10 rev = "v${version}"; 11 - sha256 = "0g5l961sr05p0kfj56qcxs9f4x3ji3p6n96zrc16cij5ncncasxw"; 11 + sha256 = "19d7yr6q8kwrm91yyglmw9n7wa861sgi6dbwn8sl6dp55czfwvaq"; 12 + # populate values otherwise taken care of by goreleaser, 13 + # unfortunately these require us to use git. By doing 14 + # this in postFetch we can delete .git afterwards and 15 + # maintain better reproducibility of the src. 12 16 leaveDotGit = true; 13 - }; 17 + postFetch = '' 18 + cd "$out" 14 19 15 - nativeBuildInputs = [ git ]; 20 + commit="$(git rev-parse HEAD)" 21 + date=$(git show -s --format=%aI "$commit") 16 22 17 - # populate values otherwise taken care of by goreleaser 18 - # https://github.com/alecthomas/chroma/issues/435 19 - postPatch = '' 20 - commit="$(git rev-parse HEAD)" 21 - date=$(git show -s --format=%aI "$commit") 23 + substituteInPlace "$out/cmd/chroma/main.go" \ 24 + --replace 'version = "?"' 'version = "${version}"' \ 25 + --replace 'commit = "?"' "commit = \"$commit\"" \ 26 + --replace 'date = "?"' "date = \"$date\"" 22 27 23 - substituteInPlace cmd/chroma/main.go \ 24 - --replace 'version = "?"' 'version = "${version}"' \ 25 - --replace 'commit = "?"' "commit = \"$commit\"" \ 26 - --replace 'date = "?"' "date = \"$date\"" 27 - ''; 28 + find "$out" -name .git -print0 | xargs -0 rm -rf 29 + ''; 30 + }; 28 31 29 32 vendorSha256 = "0y8mp08zccn9qxrsj9j7vambz8dwzsxbbgrlppzam53rg8rpxhrg"; 30 33