diff --git a/pkg/qemu/qemu.go b/pkg/qemu/qemu.go index 49f55f03eef..f093e8a4c12 100644 --- a/pkg/qemu/qemu.go +++ b/pkg/qemu/qemu.go @@ -7,6 +7,7 @@ import ( "io/fs" "os" "os/exec" + "os/user" "path/filepath" "runtime" "strconv" @@ -615,11 +616,20 @@ func getFirmware(qemuExe string, arch limayaml.Arch) (string, error) { default: return "", fmt.Errorf("unexpected architecture: %q", arch) } - binDir := filepath.Dir(qemuExe) // "/usr/local/bin" - localDir := filepath.Dir(binDir) // "/usr/local" + currentUser, err := user.Current() + if err != nil { + return "", err + } + + binDir := filepath.Dir(qemuExe) // "/usr/local/bin" + localDir := filepath.Dir(binDir) // "/usr/local" + userLocalDir := filepath.Join(currentUser.HomeDir, ".local") // "$HOME/.local" + + relativePath := fmt.Sprintf("share/qemu/edk2-%s-code.fd", arch) candidates := []string{ - filepath.Join(localDir, fmt.Sprintf("share/qemu/edk2-%s-code.fd", arch)), // macOS (homebrew) + filepath.Join(userLocalDir, relativePath), // XDG-like + filepath.Join(localDir, relativePath), // macOS (homebrew) } switch arch { @@ -648,5 +658,5 @@ func getFirmware(qemuExe string, arch limayaml.Arch) (string, error) { if arch == limayaml.X8664 { return "", fmt.Errorf("could not find firmware for %q (hint: try setting `firmware.legacyBIOS` to `true`)", qemuExe) } - return "", fmt.Errorf("could not find firmware for %q", qemuExe) + return "", fmt.Errorf("could not find firmware for %q (hint: try copying the \"edk-%s-code.fd\" firmware to $HOME/.local/share/qemu/)", arch, qemuExe) }