Libvirt: Difference between revisions

Phobos (talk | contribs)
m Updated Formating
Marie (talk | contribs)
dnsmasq is provided in the package by default and does not need installation.
 
(4 intermediate revisions by 3 users not shown)
Line 5: Line 5:
Enable libvirt daemon
Enable libvirt daemon


{{file|/etc/nixos/configuration.nix|nix|<nowiki>
{{file|||<nowiki>
virtualisation.libvirtd.enable = true;
virtualisation.libvirtd.enable = true;


# Enable TPM emulation (optional)
# Enable TPM emulation (optional)
# install pkgs.swtpm system-wide for use in virt-manager (optional)
virtualisation.libvirtd.qemu = {
virtualisation.libvirtd.qemu = {
   swtpm.enable = true;
   swtpm.enable = true;
  ovmf.packages = [ pkgs.OVMFFull.fd ];
};
};


Line 17: Line 17:
virtualisation.spiceUSBRedirection.enable = true;
virtualisation.spiceUSBRedirection.enable = true;


</nowiki>}}
</nowiki>|name=/etc/nixos/configuration.nix|lang=nix}}


To enable local user access to libvirt, for example by using <code>virt-manager</code> or <code>gnome-boxes</code>, add yourself to the <code>libvirtd</code> group
To enable local user access to libvirt, for example by using <code>virt-manager</code> or <code>gnome-boxes</code>, add yourself to the <code>libvirtd</code> group
Line 38: Line 38:


{{file|||<nowiki>
{{file|||<nowiki>
boot.extraModprobeConfig = "options kvm_intel nested=1";
boot.extraModprobeConfig = ''
  options kvm_intel nested=1
'';
</nowiki>|name=/etc/nixos/configuration.nix|lang=nix}}
</nowiki>|name=/etc/nixos/configuration.nix|lang=nix}}


Line 45: Line 47:
==== Default networking ====
==== Default networking ====


To utilize the default libvirt network, you will need to install the {{nixos:package|dnsmasq}} package. This is required for DNS and DCHP functionality within the network:
Enable and start the default network using the following commands:
 
{{File|3=environment.systemPackages = with pkgs; [
  dnsmasq
];|name=/etc/nixos/configuration.nix|lang=nix}}
 
Once the package is installed, enable and start the default network using the following commands:


<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
Line 58: Line 54:
</syntaxhighlight>
</syntaxhighlight>


This will configure the default network to start automatically on boot and immediately activate it.
This will configure the default network to start automatically on boot and immediately activate it. You may need to whitelist the interface for the firewall like so:
 
{{File|3=networking.firewall.trustedInterfaces = [ "virbr0" ];|name=/etc/nixos/configuration.nix|lang=nix}}


==== Bridge networking ====
==== Bridge networking ====