lima: add withAdditionalGuestAgents and the tests

Without copying lima-additional-guestagents files, limactl does not
detect its agents even if added the package in inputs.
This commit is contained in:
Kenichi Kamiya
2025-06-10 16:24:17 +09:00
parent b1a45ed212
commit 1afe79e13c
3 changed files with 85 additions and 30 deletions

View File

@@ -18,7 +18,7 @@
- `base16-builder` node package has been removed due to lack of upstream maintenance.
- `gentium` package now provides `Gentium-*.ttf` files, and not `GentiumPlus-*.ttf` files like before. The font identifiers `Gentium Plus*` are available in the `gentium-plus` package, and if you want to use the more recently updated package `gentium` [by sil](https://software.sil.org/gentium/), you should update your configuration files to use the `Gentium` font identifier.
- `lima` package no longer includes guest agents except for the host's architecture; these are now in `lima-additional-guestagents` package. If your guest VM's architecture differs from your Lima host's, you should also install `lima-additional-guestagents`. See also [upstream issue](https://github.com/lima-vm/lima/issues/3563).
- `lima` package now only includes the guest agent for the host's architecture by default. If your guest VM's architecture differs from your Lima host's, you'll need to enable the `lima-additional-guestagents` package by setting `withAdditionalGuestAgents = true` when overriding lima with this input.
## Other Notable Changes {#sec-nixpkgs-release-25.11-notable-changes}

View File

@@ -63,14 +63,24 @@ buildGoModule (finalAttrs: {
runHook postInstallCheck
'';
passthru.updateScript = nix-update-script { };
passthru = {
updateScript = nix-update-script { };
};
meta = {
homepage = "https://github.com/lima-vm/lima";
description = "Lima Guest Agents for emulating non-native architectures";
longDescription = ''
Use this package only for a guest with a different architecture than the host.
This package requires "lima" to be available.
This package should only be used when your guest's architecture differs from the host's.
To enable its functionality in `limactl`, set `withAdditionalGuestAgents = true` in the `lima` package:
```nix
pkgs.lima.override {
withAdditionalGuestAgents = true;
}
```
Typically, you won't need to directly add this package to your *.nix files.
'';
changelog = "https://github.com/lima-vm/lima/releases/tag/v${finalAttrs.version}";
license = lib.licenses.asl20;

View File

@@ -9,9 +9,14 @@
makeWrapper,
nix-update-script,
apple-sdk_15,
withAdditionalGuestAgents ? false,
lima-additional-guestagents,
writableTmpDirAsHomeHook,
findutils,
gzip,
testers,
writeText,
runCommand,
lima,
jq,
}:
buildGoModule (finalAttrs: {
@@ -82,43 +87,83 @@ buildGoModule (finalAttrs: {
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
findutils
gzip
];
doInstallCheck = true;
# Don't use versionCheckHook for this package until Env solutions like #403971 or #411609 are available on the master branch.
installCheckPhase =
''
runHook preInstallCheck
installCheckPhase = ''
runHook preInstallCheck
[[ "$("$out/bin/limactl" --version | cut -d ' ' -f 3)" == "${finalAttrs.version}" ]]
USER=nix $out/bin/limactl validate templates/default.yaml
[[ "$(find "$out/share" -type f -name 'lima-guestagent.Linux-*.gz' | wc -l)" -eq 1 ]]
''
# This agent matches the host's architecture and is for Linux VMs, so it can only be tested on Linux.
+ lib.optionalString stdenv.hostPlatform.isLinux ''
cp $out/share/lima/lima-guestagent.*.gz ./
gzip -dc lima-guestagent.*.gz > lima-guestagent
chmod +x lima-guestagent
[[ "$(./lima-guestagent --version | cut -d ' ' -f 3)" == "${finalAttrs.version}" ]]
''
+ ''
runHook postInstallCheck
'';
[[ "$("$out/bin/limactl" --version | cut -d ' ' -f 3)" == "${finalAttrs.version}" ]]
USER=nix $out/bin/limactl validate templates/default.yaml
passthru.updateScript = nix-update-script { };
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 { };
};
meta = {
homepage = "https://github.com/lima-vm/lima";
description = "Linux virtual machines with automatic file sharing and port forwarding";
longDescription = ''
Guest agents for non-native architectures are in the "lima-additional-guestagents" package.
'';
changelog = "https://github.com/lima-vm/lima/releases/tag/v${finalAttrs.version}";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [