-
-
Notifications
You must be signed in to change notification settings - Fork 20k
Expand file tree
/
Copy pathpackage.nix
More file actions
167 lines (147 loc) · 4.32 KB
/
Copy pathpackage.nix
File metadata and controls
167 lines (147 loc) · 4.32 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
{
lib,
stdenv,
buildGoModule,
callPackage,
installShellFiles,
qemu,
darwin,
makeWrapper,
nix-update-script,
apple-sdk_15,
withAdditionalGuestAgents ? false,
lima-additional-guestagents,
writableTmpDirAsHomeHook,
versionCheckHook,
testers,
writeText,
runCommand,
lima,
jq,
}:
let
source = callPackage ./source.nix { };
in
buildGoModule (finalAttrs: {
pname = "lima" + lib.optionalString withAdditionalGuestAgents "-full";
inherit (source) version src vendorHash;
nativeBuildInputs = [
makeWrapper
installShellFiles
# For checkPhase, and installPhase(required to build completion)
writableTmpDirAsHomeHook
]
++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.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 -' \
--replace-fail 'rm -rf _output vendor' 'rm -rf _output'
'';
# It attaches entitlements with codesign and strip removes those,
# voiding the entitlements and making it non-operational.
dontStrip = stdenv.hostPlatform.isDarwin;
buildPhase =
let
makeFlags = [
"VERSION=v${finalAttrs.version}"
"CC=${stdenv.cc.targetPrefix}cc"
];
in
''
runHook preBuild
make ${lib.escapeShellArgs makeFlags} native
runHook postBuild
'';
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
'';
postInstall = lib.optionalString withAdditionalGuestAgents ''
cp -rs '${lima-additional-guestagents}/share/lima/.' "$out/share/lima/"
'';
nativeInstallCheckInputs = [
# Workaround for: "panic: $HOME is not defined" at https://github.com/lima-vm/lima/blob/cb99e9f8d01ebb82d000c7912fcadcd87ec13ad5/pkg/limayaml/defaults.go#L53
writableTmpDirAsHomeHook
versionCheckHook
];
doInstallCheck = true;
versionCheckProgram = "${placeholder "out"}/bin/limactl";
versionCheckKeepEnvironment = [ "HOME" ];
installCheckPhase = ''
runHook preInstallCheck
USER=nix $out/bin/limactl validate templates/default.yaml
runHook postInstallCheck
'';
passthru = {
tests =
let
arch = stdenv.hostPlatform.parsed.cpu.name;
in
{
minimalAgent = testers.testEqualContents {
assertion = "limactl only detects host's architecture guest agent by default";
expected = writeText "expected" ''
true
1
'';
actual =
runCommand "actual"
{
nativeBuildInputs = [
writableTmpDirAsHomeHook
lima
jq
];
}
''
limactl info | jq '.guestAgents | has("${arch}")' >>"$out"
limactl info | jq '.guestAgents | length' >>"$out"
'';
};
additionalAgents = testers.testEqualContents {
assertion = "limactl also detects additional guest agents if specified";
expected = writeText "expected" ''
true
true
'';
actual =
runCommand "actual"
{
nativeBuildInputs = [
writableTmpDirAsHomeHook
(lima.override {
withAdditionalGuestAgents = true;
})
jq
];
}
''
limactl info | jq '.guestAgents | has("${arch}")' >>"$out"
limactl info | jq '.guestAgents | length >= 2' >>"$out"
'';
};
};
updateScript = nix-update-script {
extraArgs = [
"--override-filename"
./source.nix
];
};
};
meta = source.meta // {
description = "Linux virtual machines with automatic file sharing and port forwarding";
};
})