Skip to content

Commit

Permalink
add: build-vm command to os subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
xiro-codes committed Mar 8, 2024
1 parent 3f148b0 commit ba3b0c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
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

0 comments on commit ba3b0c4

Please sign in to comment.