diff --git a/pkgs/development/tools/regclient/default.nix b/pkgs/development/tools/regclient/default.nix index bb8d79b6c44f64a..0d2a0015ffe17ba 100644 --- a/pkgs/development/tools/regclient/default.nix +++ b/pkgs/development/tools/regclient/default.nix @@ -1,4 +1,12 @@ -{ stdenv, lib, buildGoModule, fetchFromGitHub }: +{ stdenv +, lib +, buildGoModule +, fetchFromGitHub +, testers +, go +, installShellFiles +, regclient +}: let bins = [ "regbot" "regctl" "regsync" ]; in @@ -20,22 +28,65 @@ buildGoModule rec { ldflags = [ "-s" "-w" - "-X main.VCSTag=${tag}" + "-X github.com/regclient/regclient/internal/version.vcsTag=${tag}" ]; - postInstall = - lib.concatStringsSep "\n" ( - map (bin: '' - mkdir -p ''$${bin}/bin && - mv $out/bin/${bin} ''$${bin}/bin/ && - ln -s ''$${bin}/bin/${bin} $out/bin/ - '') bins - ); + nativeBuildInputs = [ installShellFiles ]; + + postInstall = lib.concatStringsSep "\n" ( + map + (bin: '' + export bin=''$${bin} + export outputBin=bin + + mkdir -p $bin/bin + mv $out/bin/${bin} $bin/bin + ln -s $bin/bin/${bin} $out/bin + + $bin/bin/${bin} completion bash >${bin}.bash + $bin/bin/${bin} completion fish >${bin}.fish + $bin/bin/${bin} completion zsh >${bin}.zsh + installShellCompletion ${bin}.{bash,fish,zsh} + + mkdir -p $out/share/zsh/site-functions + mkdir -p $out/share/fish/vendor_completions.d + mkdir -p $out/share/bash-completion/completions + ln -s $bin/share/zsh/site-functions/_${bin} $out/share/zsh/site-functions + ln -s $bin/share/fish/vendor_completions.d/${bin}.fish $out/share/fish/vendor_completions.d + ln -s $bin/share/bash-completion/completions/${bin}.bash $out/share/bash-completion/completions + + unset bin outputBin + '') + bins + ); + + passthru.tests = lib.attrsets.mergeAttrsList ( + map + (bin: { + "${bin}Version" = testers.testVersion { + package = regclient; + command = "${bin} version"; + version = '' + VCSTag: ${tag} + VCSRef: unknown + VCSCommit: unknown + VCSState: unknown + VCSDate: unknown + Platform: ${go.GOOS}/${go.GOARCH} + GoVer: go${go.version} + GoCompiler: gc + ''; + }; + }) + bins + ); + + __darwinAllowLocalNetworking = true; meta = with lib; { description = "Docker and OCI Registry Client in Go and tooling using those libraries"; homepage = "https://github.com/regclient/regclient"; license = licenses.asl20; - maintainers = with maintainers; [ ]; + maintainers = with maintainers; [ maxbrunet ]; }; }