From ef0ed76841855b401ab67a81d7dd4f6e1f2fd705 Mon Sep 17 00:00:00 2001 From: Maxime Brunet Date: Sun, 11 Feb 2024 14:07:20 -0800 Subject: [PATCH] regclient: add shell completions and fix version output --- pkgs/development/tools/regclient/default.nix | 56 ++++++++++++++++---- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/pkgs/development/tools/regclient/default.nix b/pkgs/development/tools/regclient/default.nix index bb8d79b6c44f..9016f4704bc5 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 +, installShellFiles +, lndir +, testers +, regclient +}: let bins = [ "regbot" "regctl" "regsync" ]; in @@ -20,22 +28,48 @@ 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 lndir ]; + + postInstall = lib.concatMapStringsSep "\n" + (bin: '' + export bin=''$${bin} + export outputBin=bin + + mkdir -p $bin/bin + mv $out/bin/${bin} $bin/bin + + installShellCompletion --cmd ${bin} \ + --bash <($bin/bin/${bin} completion bash) \ + --fish <($bin/bin/${bin} completion fish) \ + --zsh <($bin/bin/${bin} completion zsh) + + lndir -silent $bin $out + + unset bin outputBin + '') + bins; + + passthru.tests = lib.mergeAttrsList ( + map + (bin: { + "${bin}Version" = testers.testVersion { + package = regclient; + command = "${bin} version"; + version = tag; + }; + }) + 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 ]; }; }