From 4f7789c4a8eecd3fa6875851052f4cf2779b560d Mon Sep 17 00:00:00 2001 From: JMARyA Date: Mon, 6 Jan 2025 13:25:40 +0100 Subject: [PATCH] add libvirt support --- installs/full.toml | 3 +++ src/config.rs | 1 + src/install/mod.rs | 28 +++++++++++++++++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/installs/full.toml b/installs/full.toml index 1367d3c..97eeddc 100644 --- a/installs/full.toml +++ b/installs/full.toml @@ -61,6 +61,9 @@ doas_root= true # Add user to Docker group docker = true +# Add user to libvirt group +virtualization = true + # SSH Configuration # If `[ssh]` is set, openssh will be installed and enabled. [ssh] diff --git a/src/config.rs b/src/config.rs index 30fbecc..59531eb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -43,6 +43,7 @@ pub struct UserConfig { pub password: String, pub doas_root: Option, pub docker: Option, + pub virtualization: Option, } #[derive(Debug, Clone, Deserialize)] diff --git a/src/install/mod.rs b/src/install/mod.rs index 74aed52..1cc1ed5 100644 --- a/src/install/mod.rs +++ b/src/install/mod.rs @@ -31,8 +31,8 @@ pub mod user; pub mod zram; use crate::{ - config::InstallConfig, - linux::install_file, + config::{InstallConfig, InstallMode}, + linux::{arch_chroot, install_file, systemd_service_enable}, pkg::{self, install_pkgs, pacstrap}, print_status, }; @@ -126,7 +126,29 @@ pub fn install(conf: InstallConfig) { } if conf.pkg.virtualization.unwrap_or_default() { - // TODO : Enable virtualization + let user_conf = if let Some(user_conf) = &conf.user { + user_conf.clone() + } else { + Vec::new() + }; + + install_pkgs(&["libvirt"]); + + if matches!(conf.general.mode, InstallMode::Desktop) { + install_pkgs(&["virt-manager"]); + } + + systemd_service_enable("libvirtd.service"); + + for user in user_conf { + if user.virtualization.unwrap_or_default() { + arch_chroot( + &vec!["usermod", "-a", "-G", "libvirt", user.name.as_str()], + None, + false, + ); + } + } } if conf.pkg.docker.unwrap_or_default() {