diff --git a/pkgs/by-name/sh/shfmt/package.nix b/pkgs/by-name/sh/shfmt/package.nix index 4e8073ae4840..31cfdee9097d 100644 --- a/pkgs/by-name/sh/shfmt/package.nix +++ b/pkgs/by-name/sh/shfmt/package.nix @@ -3,28 +3,35 @@ buildGoModule, fetchFromGitHub, installShellFiles, + replaceVars, scdoc, + versionCheckHook, }: buildGoModule (finalAttrs: { pname = "shfmt"; - version = "3.12.0"; + version = "3.13.0"; src = fetchFromGitHub { owner = "mvdan"; repo = "sh"; rev = "v${finalAttrs.version}"; - hash = "sha256-3a0N5GsqZvJVx1qhsTzwtC2SBtexdXJMalerM+joNIc="; + hash = "sha256-VFLnQNhySXB/VE0u9u2X4jAHq+083+QjhWM7vfyxhM8="; }; - vendorHash = "sha256-jvsX0nn9cHq2cZUrD9E1eMtOiy5I4wfpngAc+6qUbEE="; + vendorHash = "sha256-WLGHcmBslXJO4OKdUK7HqimdUCOtdCdK+AOdlo4hgWk="; + + patches = [ + (replaceVars ./version.patch { + inherit (finalAttrs) version; + }) + ]; subPackages = [ "cmd/shfmt" ]; ldflags = [ "-s" "-w" - "-X main.version=${finalAttrs.version}" ]; nativeBuildInputs = [ @@ -37,6 +44,10 @@ buildGoModule (finalAttrs: { installManPage shfmt.1 ''; + doInstallCheck = true; + nativeInstallCheckInputs = [ versionCheckHook ]; + versionCheckProgramArg = "--version"; + meta = { homepage = "https://github.com/mvdan/sh"; description = "Shell parser and formatter"; diff --git a/pkgs/by-name/sh/shfmt/version.patch b/pkgs/by-name/sh/shfmt/version.patch new file mode 100644 index 000000000000..3c80c472d46c --- /dev/null +++ b/pkgs/by-name/sh/shfmt/version.patch @@ -0,0 +1,37 @@ +diff --git a/cmd/shfmt/main.go b/cmd/shfmt/main.go +index c6c08e37..e59128ec 100644 +--- a/cmd/shfmt/main.go ++++ b/cmd/shfmt/main.go +@@ -153,13 +153,12 @@ For more information and to report bugs, see https://github.com/mvdan/sh. + flag.Parse() + + if versionFlag.val { +- version := "(unknown)" ++ version := "@version@" + if info, ok := debug.ReadBuildInfo(); ok { + mod := &info.Main + if mod.Replace != nil { + mod = mod.Replace + } +- version = mod.Version + } + fmt.Println(version) + return +diff --git a/cmd/shfmt/testdata/script/flags.txtar b/cmd/shfmt/testdata/script/flags.txtar +index 012912cb..54305a03 100644 +--- a/cmd/shfmt/testdata/script/flags.txtar ++++ b/cmd/shfmt/testdata/script/flags.txtar +@@ -9,11 +9,11 @@ exec shfmt --help + stderr 'usage: shfmt' + + exec shfmt -version +-stdout 'devel|v3' ++stdout '@version@' + ! stderr . + + exec shfmt --version +-stdout 'devel|v3' ++stdout '@version@' + ! stderr . + + ! exec shfmt -ln=bash -p