summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/dc/dcp/package.nix
blob: ca68a3069adc42bab62cd9afbc664a98d1c69b8a (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{
  lib,
  stdenv,
  buildGoModule,
  fetchFromGitHub,
  bash,
  protobuf,
  protoc-gen-go,
  protoc-gen-go-grpc,
  kubernetes-controller-tools,
  installShellFiles,
  nix-update-script,
  writableTmpDirAsHomeHook,
}:

buildGoModule (finalAttrs: {
  pname = "dcp";
  version = "0.25.13";

  src = fetchFromGitHub {
    owner = "microsoft";
    repo = "dcp";
    tag = "v${finalAttrs.version}";
    hash = "sha256-dbgvKAsUw6950ig1/eUewUS++P803Bdg5qYmFYnqaGQ=";
  };

  vendorHash = "sha256-WBre4iBMYzx1unqz9+F1wDogYbPEsm3DyUgeceB8yko=";

  # This is required so we:
  # - Delete an inconsistent vendor directory from upstream
  # - Avoid running a preBuild before the codegen step
  overrideModAttrs = _: {
    preBuild = null;
    postUnpack = ''
      rm -rf $sourceRoot/vendor
    '';
  };

  nativeBuildInputs = [
    installShellFiles
    protoc-gen-go
    protoc-gen-go-grpc
    writableTmpDirAsHomeHook
  ];

  # Run code generation using the upstream Makefile.
  # Override SHELL for Nix sandbox compatibility.
  # Use full paths for PROTOC and CONTROLLER_GEN to avoid Makefile target conflicts.
  preBuild = ''
    make generate \
      SHELL="${bash}/bin/bash -o pipefail" \
      PROTOC="${protobuf}/bin/protoc" \
      CONTROLLER_GEN="${kubernetes-controller-tools}/bin/controller-gen"
  '';

  subPackages = [
    "cmd/dcp"
    "cmd/dcptun"
  ];

  ldflags =
    let
      pkg = "github.com/microsoft/dcp/internal/version";
    in
    [
      "-s"
      "-w"
      "-X ${pkg}.ProductVersion=${finalAttrs.version}"
      "-X ${pkg}.CommitHash=v${finalAttrs.version}"
    ];

  # The dcptun binary should be named dcptun_c for compatibility
  # https://github.com/microsoft/dcp/blob/3146b1dd5b2ea283947f846a55bf2e01c294e2ba/Makefile#L103
  postInstall = ''
    mv $out/bin/dcptun $out/bin/dcptun_c
  ''
  + lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
    installShellCompletion --cmd dcp \
      --bash <($out/bin/dcp completion bash) \
      --fish <($out/bin/dcp completion fish) \
      --zsh <($out/bin/dcp completion zsh)
  '';

  passthru.updateScript = nix-update-script { };

  meta = {
    description = "Developer Control Plane - API server and CLI for managing developer workloads";
    homepage = "https://github.com/microsoft/dcp";
    changelog = "https://github.com/microsoft/dcp/releases/tag/v${finalAttrs.version}";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ mtrsk ];
    mainProgram = "dcp";
    platforms = lib.platforms.unix;
  };
})