summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/co/colima/package.nix
blob: 038eeaa827b081ca368351439d57cb76be7037fe (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
96
97
{
  lib,
  stdenv,
  darwin,
  buildGoModule,
  fetchFromGitHub,
  installShellFiles,
  krunkit,
  lima-full,
  makeWrapper,
  procps,
  qemu,
  docker,
  testers,
  colima,
}:

buildGoModule (finalAttrs: {
  pname = "colima";
  version = "0.10.3";

  src = fetchFromGitHub {
    owner = "abiosoft";
    repo = "colima";
    tag = "v${finalAttrs.version}";
    hash = "sha256-FBFL3VO6t7SaGnZBT2qBD1DbRg14klBpiPiaELbRfIY=";
    # We need the git revision
    leaveDotGit = true;
    postFetch = ''
      git -C $out rev-parse --short HEAD > $out/.git-revision
      rm -rf $out/.git
    '';
  };

  nativeBuildInputs = [
    installShellFiles
    makeWrapper
  ]
  ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.DarwinTools ];

  vendorHash = "sha256-j1RuG3CTGfVNfT/v+C2pZgb58c9cxa2op3LA/F5rNWo=";

  # disable flaky Test_extractZones
  # https://hydra.nixos.org/build/212378003/log
  excludedPackages = "gvproxy";

  env.CGO_ENABLED = 1;

  postPatch = lib.optionalString (!stdenv.hostPlatform.isDarwin) ''
    substituteInPlace cmd/daemon/daemon.go \
      --replace-fail '/usr/bin/pkill' '${lib.getExe' procps "pkill"}'

    substituteInPlace daemon/process/vmnet/vmnet.go \
      --replace-fail '/usr/bin/pkill' '${lib.getExe' procps "pkill"}'
  '';

  preConfigure = ''
    ldflags="-s -w -X github.com/abiosoft/colima/config.appVersion=${finalAttrs.version} \
    -X github.com/abiosoft/colima/config.revision=$(cat .git-revision)"
  '';

  postInstall = ''
    wrapProgram $out/bin/colima \
      --prefix PATH : ${
        lib.makeBinPath (
          [
            # Suppress warning on `colima start`: https://github.com/abiosoft/colima/issues/1333
            lima-full
            qemu
            docker
          ]
          ++ lib.optional (lib.meta.availableOn stdenv.hostPlatform krunkit) krunkit
        )
      }

    installShellCompletion --cmd colima \
      --bash <($out/bin/colima completion bash) \
      --fish <($out/bin/colima completion fish) \
      --zsh <($out/bin/colima completion zsh)
  '';

  passthru.tests.version = testers.testVersion {
    package = colima;
    command = "HOME=$(mktemp -d) colima version";
  };

  meta = {
    description = "Container runtimes with minimal setup";
    homepage = "https://github.com/abiosoft/colima";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [
      aaschmid
      tricktron
    ];
    mainProgram = "colima";
  };
})