Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: build-vm command to os subcommand #74

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ pub enum OsRebuildType {
Boot(OsRebuildArgs),
/// Build and activate the new configuration
Test(OsRebuildArgs),
/// Build vm with the new configuration
BuildVm(OsRebuildArgs),
/// Show an overview of the system's info
#[command(hide = true)]
Info,
Expand Down
37 changes: 30 additions & 7 deletions src/nixos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use color_eyre::Result;
use tracing::{debug, info};

use crate::interface::NHRunnable;
use crate::interface::OsRebuildType::{self, Boot, Switch, Test};
use crate::interface::OsRebuildType::{self, Boot, Switch, Test, BuildVm};
use crate::interface::{self, OsRebuildArgs};
use crate::*;

Expand All @@ -18,7 +18,7 @@ const SPEC_LOCATION: &str = "/etc/specialisation";
impl NHRunnable for interface::OsArgs {
fn run(&self) -> Result<()> {
match &self.action {
Switch(args) | Boot(args) | Test(args) => args.rebuild(&self.action),
Switch(args) | Boot(args) | Test(args) | BuildVm(args) => args.rebuild(&self.action),
s => bail!("Subcommand {:?} not yet implemented", s),
}
}
Expand All @@ -41,11 +41,23 @@ impl OsRebuildArgs {
debug!("out_dir: {:?}", out_dir);
debug!("out_link {:?}", out_link);

let flake_output = format!(
"{}#nixosConfigurations.{:?}.config.system.build.toplevel",
&self.common.flakeref.deref(),
hostname
);
let flake_output = match rebuild_type {
Switch(_) | Boot(_) | Test(_) => {
format!(
"{}#nixosConfigurations.{:?}.config.system.build.toplevel",
&self.common.flakeref.deref(),
hostname
)
}
BuildVm(_) => {
format!(
"{}#nixosConfigurations.{:?}.config.system.build.vm",
&self.common.flakeref.deref(),
hostname
)
}
_ => bail!("Invalid rebuild type"),
};

if self.common.update {
commands::CommandBuilder::default()
Expand Down Expand Up @@ -141,6 +153,17 @@ impl OsRebuildArgs {
.build()?
.exec()?;
}
if let BuildVm(_) = rebuild_type {
// !! Use the base profile aka no spec-namespace
let run_vm = out_link.join("bin").join(format!("run-{}-vm", hostname.to_str().unwrap()));
let run_vm = run_vm.to_str().unwrap();

commands::CommandBuilder::default()
.args([run_vm])
.message("Activating configuration")
.build()?
.exec()?;
}

// Drop the out dir *only* when we are finished
drop(out_dir);
Expand Down