summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/fa/faas-cli/package.nix
blob: 37592ba395034d56e72b79a9cc7cb28032550f58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
{
  lib,
  stdenv,
  buildGoModule,
  fetchFromGitHub,
  makeWrapper,
  git,
  installShellFiles,
  versionCheckHook,
}:
let
  faasPlatform =
    platform:
    let
      cpuName = platform.parsed.cpu.name;
    in
    {
      "aarch64" = "arm64";
      "armv7l" = "armhf";
      "armv6l" = "armhf";
    }
    .${cpuName} or cpuName;
in
buildGoModule (finalAttrs: {
  pname = "faas-cli";
  version = "0.18.12";

  __structuredAttrs = true;

  src = fetchFromGitHub {
    owner = "openfaas";
    repo = "faas-cli";
    tag = finalAttrs.version;
    hash = "sha256-I7P30c7rEVqemgUu/1AtM6jq2f4KB8xyDpjGBMvkLRU=";
  };

  vendorHash = null;

  env.CGO_ENABLED = 0;

  subPackages = [ "." ];

  ldflags = [
    "-s"
    "-X github.com/openfaas/faas-cli/version.GitCommit=ref/tags/${finalAttrs.version}"
    "-X github.com/openfaas/faas-cli/version.Version=${finalAttrs.version}"
    "-X github.com/openfaas/faas-cli/commands.Platform=${faasPlatform stdenv.hostPlatform}"
  ];

  nativeBuildInputs = [
    makeWrapper
    installShellFiles
  ];

  postInstall = ''
    wrapProgram "$out/bin/faas-cli" \
      --prefix PATH : ${lib.makeBinPath [ git ]}

    installShellCompletion --cmd metal \
      --bash <($out/bin/faas-cli completion --shell bash) \
      --zsh <($out/bin/faas-cli completion --shell zsh)
  '';

  nativeInstallCheckInputs = [ versionCheckHook ];
  versionCheckProgramArg = "version";
  doInstallCheck = true;

  meta = {
    description = "Official CLI for OpenFaaS";
    mainProgram = "faas-cli";
    homepage = "https://github.com/openfaas/faas-cli";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [
      welteki
      techknowlogick
    ];
  };
})