Skip to content

Commit

Permalink
regclient: add shell completions and fix version output
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunet committed Feb 14, 2024
1 parent 009e4ff commit 925c482
Showing 1 changed file with 62 additions and 11 deletions.
73 changes: 62 additions & 11 deletions pkgs/development/tools/regclient/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{ stdenv, lib, buildGoModule, fetchFromGitHub }:
{ stdenv
, lib
, buildGoModule
, fetchFromGitHub
, testers
, go
, installShellFiles
, regclient
}:

let bins = [ "regbot" "regctl" "regsync" ]; in

Expand All @@ -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 ];
};
}

0 comments on commit 925c482

Please sign in to comment.