From c5427604c76fa5a4bf33f113fe54e4a3f64e1e8d Mon Sep 17 00:00:00 2001 From: nsfisis <54318333+nsfisis@users.noreply.github.com> Date: Mon, 12 May 2025 01:11:32 +0900 Subject: [PATCH] gomi: embed version information (#403076) --- pkgs/by-name/go/gomi/package.nix | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/go/gomi/package.nix b/pkgs/by-name/go/gomi/package.nix index 82f16f3de703..84403bd18a61 100644 --- a/pkgs/by-name/go/gomi/package.nix +++ b/pkgs/by-name/go/gomi/package.nix @@ -12,13 +12,32 @@ buildGoModule rec { owner = "b4b4r07"; repo = "gomi"; tag = "v${version}"; - hash = "sha256-FZCvUG6lQH8CFivV/hbIgGQx4FCk1UtreiWXTQVi4+4="; + hash = "sha256-0C+us4GO8Jd51ATaaf0aRU3NnhmDvu0I3qDDXBoaiXU="; + # populate values that require us to use git. By doing this in postFetch we + # can delete .git afterwards and maintain better reproducibility of the src. + leaveDotGit = true; + postFetch = '' + cd $out + git show --format='%h' HEAD --quiet > ldflags_revision + date --utc --date="@$(git show --format='%ct' HEAD --quiet)" +'%Y-%m-%dT%H:%M:%SZ' > ldflags_buildDate + find . -type d -name .git -print0 | xargs -0 rm -rf + ''; }; vendorHash = "sha256-8aw81DKBmgNsQzgtHCsUkok5e5+LeAC8BUijwKVT/0s="; subPackages = [ "." ]; + # Add version information fetched from the repository to ldflags. + # https://github.com/babarot/gomi/blob/v1.6.0/.goreleaser.yaml#L20-L22 + ldflags = [ + "-X main.version=v${version}" + ]; + preBuild = '' + ldflags+=" -X main.revision=$(cat ldflags_revision)" + ldflags+=" -X main.buildDate=$(cat ldflags_buildDate)" + ''; + meta = { description = "Replacement for UNIX rm command"; homepage = "https://github.com/b4b4r07/gomi";