diff --git a/pkgs/by-name/ya/yamlfmt/package.nix b/pkgs/by-name/ya/yamlfmt/package.nix index 1dd51cfd7202..4e5cea9eae03 100644 --- a/pkgs/by-name/ya/yamlfmt/package.nix +++ b/pkgs/by-name/ya/yamlfmt/package.nix @@ -2,8 +2,7 @@ lib, buildGoModule, fetchFromGitHub, - testers, - yamlfmt, + versionCheckHook, }: buildGoModule (finalAttrs: { @@ -14,7 +13,12 @@ buildGoModule (finalAttrs: { owner = "google"; repo = "yamlfmt"; tag = "v${finalAttrs.version}"; - hash = "sha256-EYOtxb2Xq4bQpWbITmPieVMqJz3/2chgNirZEjiyjAY="; + hash = "sha256-WSw4WhWNyvkCwRCQYFAKhtkvOSSCrSlX3+i6cMHRtOQ="; + leaveDotGit = true; + postFetch = '' + git -C "$out" rev-parse --short HEAD > "$out/.git_head" + rm -rf "$out/.git" + ''; }; vendorHash = "sha256-Cy1eBvKkQ90twxjRL2bHTk1qNFLQ22uFrOgHKmnoUIQ="; @@ -23,16 +27,21 @@ buildGoModule (finalAttrs: { "-s" "-w" "-X=main.version=${finalAttrs.version}" - "-X=main.commit=${finalAttrs.src.rev}" ]; + preBuild = '' + ldflags+=" -X=main.commit=$(<.git_head)" + ''; + # Test failure in vendored yaml package, see: # https://github.com/google/yamlfmt/issues/256 checkFlags = [ "-run=!S/TestNodeRoundtrip" ]; - passthru.tests.version = testers.testVersion { - package = yamlfmt; - }; + nativeInstallCheckInputs = [ + versionCheckHook + ]; + doInstallCheck = true; + versionCheckProgramArg = "--version"; meta = { description = "Extensible command line tool or library to format yaml files";