-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
/
Copy pathdefault.nix
95 lines (82 loc) · 2.71 KB
/
default.nix
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,
installShellFiles,
qemu,
sigtool,
makeWrapper,
nix-update-script,
apple-sdk_15,
lima,
}:
buildGoModule rec {
pname = "lima";
version = "1.0.3";
src = fetchFromGitHub {
owner = "lima-vm";
repo = "lima";
rev = "v${version}";
hash = "sha256-S0Mk7h4gH5syP/ayK5g1g8HG5f23sKCQCCbM6xOj+n0=";
};
vendorHash = "sha256-1SHiz+lfG4nl1qavq/Fd73UV8LkErILk7d8XZJSbHd0=";
nativeBuildInputs = [
makeWrapper
installShellFiles
] ++ lib.optionals stdenv.hostPlatform.isDarwin [ sigtool ];
buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ apple-sdk_15 ];
postPatch = ''
substituteInPlace Makefile \
--replace-fail 'codesign -f -v --entitlements vz.entitlements -s -' 'codesign -f --entitlements vz.entitlements -s -'
'';
# It attaches entitlements with codesign and strip removes those,
# voiding the entitlements and making it non-operational.
dontStrip = stdenv.hostPlatform.isDarwin;
buildPhase = ''
runHook preBuild
make "VERSION=v${version}" "CC=${stdenv.cc.targetPrefix}cc" binaries
runHook postBuild
'';
preCheck = ''
# Workaround for: could not create "/homeless-shelter/.lima/_config" directory: mkdir /homeless-shelter: permission denied
export LIMA_HOME="$(mktemp -d)"
'';
installPhase =
''
runHook preInstall
mkdir -p $out
cp -r _output/* $out
wrapProgram $out/bin/limactl \
--prefix PATH : ${lib.makeBinPath [ qemu ]}
''
+ lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
installShellCompletion --cmd limactl \
--bash <($out/bin/limactl completion bash) \
--fish <($out/bin/limactl completion fish) \
--zsh <($out/bin/limactl completion zsh)
''
+ ''
runHook postInstall
'';
doInstallCheck = true;
# Workaround for: "panic: $HOME is not defined" at https://github.com/lima-vm/lima/blob/v1.0.3/pkg/limayaml/defaults.go#L52
# Don't use versionCheckHook for this package. It cannot inject environment variables.
installCheckPhase = ''
if [[ "$(HOME="$(mktemp -d)" "$out/bin/limactl" --version | cut -d ' ' -f 3)" == "${version}" ]]; then
echo '${pname} smoke check passed'
else
echo '${pname} smoke check failed'
return 1
fi
USER=nix $out/bin/limactl validate templates/default.yaml
'';
passthru.updateScript = nix-update-script { };
meta = with lib; {
homepage = "https://github.com/lima-vm/lima";
description = "Linux virtual machines (on macOS, in most cases)";
changelog = "https://github.com/lima-vm/lima/releases/tag/v${version}";
license = licenses.asl20;
maintainers = with maintainers; [ anhduy ];
};
}