1{ lib
2, stdenv
3, buildGoModule
4, fetchFromGitHub
5, installShellFiles
6, qemu
7, xcbuild
8, sigtool
9, makeWrapper
10}:
11
12buildGoModule rec {
13 pname = "lima";
14 version = "0.18.0";
15
16 src = fetchFromGitHub {
17 owner = "lima-vm";
18 repo = pname;
19 rev = "v${version}";
20 sha256 = "sha256-sOOpqgEvDBVvD/o1wFL3ebqWw0XpSdEqY8cZmtdXyxE=";
21 };
22
23 vendorHash = "sha256-vJlnptEja3nBfj/c1hSZjY9DZPQ970ZIMnHBPndd2vQ=";
24
25 nativeBuildInputs = [ makeWrapper installShellFiles ]
26 ++ lib.optionals stdenv.isDarwin [ xcbuild.xcrun sigtool ];
27
28 # clean fails with read only vendor dir
29 postPatch = ''
30 substituteInPlace Makefile \
31 --replace 'binaries: clean' 'binaries:' \
32 --replace 'codesign --entitlements vz.entitlements -s -' 'codesign --force --entitlements vz.entitlements -s -'
33 '';
34
35 # It attaches entitlements with codesign and strip removes those,
36 # voiding the entitlements and making it non-operational.
37 dontStrip = stdenv.isDarwin;
38
39 buildPhase = ''
40 runHook preBuild
41 make "VERSION=v${version}" binaries
42 runHook postBuild
43 '';
44
45 installPhase = ''
46 runHook preInstall
47 mkdir -p $out
48 cp -r _output/* $out
49 wrapProgram $out/bin/limactl \
50 --prefix PATH : ${lib.makeBinPath [ qemu ]}
51 installShellCompletion --cmd limactl \
52 --bash <($out/bin/limactl completion bash) \
53 --fish <($out/bin/limactl completion fish) \
54 --zsh <($out/bin/limactl completion zsh)
55 runHook postInstall
56 '';
57
58 doInstallCheck = true;
59 installCheckPhase = ''
60 USER=nix $out/bin/limactl validate examples/default.yaml
61 '';
62
63 meta = with lib; {
64 homepage = "https://github.com/lima-vm/lima";
65 description = "Linux virtual machines (on macOS, in most cases)";
66 changelog = "https://github.com/lima-vm/lima/releases/tag/v${version}";
67 license = licenses.asl20;
68 maintainers = with maintainers; [ anhduy ];
69 };
70}