Skip to content

Commit 0e97063

Browse files
committed
More NixOS fixes
- Override UEFI firmware path - Provide python-libvirt to Ansible's main environment too
1 parent bdb0fa3 commit 0e97063

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

roles/create-vm/defaults/main.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,13 @@ install_iso_virtio_win: "{{ lookup('first_found', 'target') }}/virtio-win.iso"
2121
install_exe_spice_guest_tools_url: https://www.spice-space.org/download/windows/spice-guest-tools/spice-guest-tools-0.141/spice-guest-tools-0.141.exe
2222
install_exe_spice_guest_tools_checksum: sha256:b5be0754802bcd7f7fe0ccdb877f8a6224ba13a2af7d84eb087a89b3b0237da2
2323
install_exe_spice_guest_tools: "{{ lookup('first_found', 'guest-files') }}/spice-guest-tools.exe"
24+
25+
# Some distributions don't ship firmware selection manifests, so we need to
26+
# provide an override ourselves.
27+
# vm_firmware_override will be set to the first candidate that exists, if any.
28+
vm_firmware_override: null
29+
vm_firmware_override_candidates:
30+
# NixOS:
31+
# https://github.com/NixOS/nixpkgs/issues/115996, and
32+
# https://github.com/NixOS/nixpkgs/issues/318079
33+
- /run/libvirt/nix-ovmf/OVMF_CODE.fd

roles/create-vm/tasks/main.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
url: "{{ install_exe_spice_guest_tools_url }}"
2525
checksum: "{{ install_exe_spice_guest_tools_checksum }}"
2626

27+
- name: Find firmware path
28+
set_fact:
29+
vm_firmware_override: "{{ item }}"
30+
with_first_found:
31+
- files: "{{ vm_firmware_override_candidates }}"
32+
skip: True
33+
2734
- name: Create VM Network
2835
community.libvirt.virt_net:
2936
name: "{{ vm_network_hostnet_name }}"

roles/create-vm/templates/windows-vm.xml.j2

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
<memory unit="MiB">{{ vm_memory_mib }}</memory>
99
<currentMemory unit="MiB">{{ vm_memory_mib }}</currentMemory>
1010
<vcpu placement="static">{{ vm_vcpus }}</vcpu>
11-
<os firmware="efi">
12-
<type arch="x86_64" machine="pc-q35-9.0">hvm</type>
11+
<os
12+
{% if not vm_firmware_override %}
13+
firmware="efi"
14+
{% endif %}>
15+
<type arch="x86_64" machine="pc-q35-8.0">hvm</type>
16+
{% if vm_firmware_override %}
17+
<loader type='pflash'>{{ vm_firmware_override }}</loader>
18+
{% endif %}
1319
</os>
1420
<features>
1521
<acpi/>

shell.nix

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
{ sources ? import nix/sources.nix
22
, pkgs ? import sources.nixpkgs {} }:
33

4-
with pkgs;
4+
let
5+
python = pkgs.python3;
6+
extraAnsibleDeps = pypkgs: [ pypkgs.libvirt pypkgs.lxml ];
7+
in
8+
pkgs.mkShell rec {
9+
# buildInputs = [ pkgs.ansible ];
10+
buildInputs = [ ansible ];
511

6-
mkShell {
7-
buildInputs = [ pkgs.ansible ];
12+
# Ansible runs plugins in its own interpreter, so we need to add plugin dependencies to
13+
# its Python environment
14+
ansible = python.pkgs.toPythonApplication
15+
(python.pkgs.ansible-core.overridePythonAttrs (old: {
16+
propagatedBuildInputs = old.propagatedBuildInputs ++ extraAnsibleDeps python.pkgs;
17+
}));
818

919
# Ansible runs modules in a separate interpreter, which bypasses Nix's added packages
1020
# Hence, override that interpreter with one that has the required dependencies installed
11-
ANSIBLE_PYTHON_INTERPRETER = pkgs.python3.withPackages (pkgs: [
12-
# community.libvirt
13-
pkgs.libvirt pkgs.lxml
14-
]) + "/bin/python";
21+
ansiblePython = pkgs.python3.withPackages extraAnsibleDeps;
22+
ANSIBLE_PYTHON_INTERPRETER = ansiblePython + "/bin/python";
1523
}

0 commit comments

Comments
 (0)