-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
127 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,6 @@ impl CastImage for Goldboot { | |
let mut qemu = QemuBuilder::new(&worker, OsCategory::Linux) | ||
.vga("cirrus") | ||
.source(&worker.element.source)? | ||
.prepare_ssh()? | ||
.start()?; | ||
|
||
// Start HTTP | ||
|
@@ -73,19 +72,14 @@ impl CastImage for Goldboot { | |
// Login as root | ||
enter!("root"), | ||
enter!("r00tme"), | ||
// Install goldboot | ||
enter!(format!("curl https://github.com/fossable/goldboot/releases/download/v0.0.3/goldboot_0.0.3_linux_{}.tar.gz | tar xf - -C /usr/bin goldboot", worker.arch)), | ||
// Skip getty login | ||
enter!("sed -i 's|ExecStart=.*$|ExecStart=/usr/bin/goldboot|' /usr/lib/systemd/system/[email protected]"), | ||
// Stop gracefully | ||
enter!("poweroff"), | ||
])?; | ||
|
||
// Wait for SSH | ||
let mut ssh = qemu.ssh("root")?; | ||
|
||
// Install executable | ||
// ssh.upload( | ||
// std::fs::read(&self.executable)?, | ||
// "/mnt/usr/bin/goldboot-linux", | ||
// )?; | ||
|
||
// Shutdown | ||
ssh.shutdown("poweroff")?; | ||
qemu.shutdown_wait()?; | ||
Ok(()) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use anyhow::Result; | ||
use dialoguer::theme::Theme; | ||
use goldboot_image::ImageArch; | ||
use serde::{Deserialize, Serialize}; | ||
use std::{collections::HashMap, fmt::Display}; | ||
use strum::{Display, EnumIter, IntoEnumIterator}; | ||
use validator::Validate; | ||
|
||
use crate::{ | ||
cli::prompt::{Prompt, PromptNew}, | ||
enter, | ||
foundry::{ | ||
options::{hostname::Hostname, unix_account::RootPassword}, | ||
qemu::{OsCategory, QemuBuilder}, | ||
sources::ImageSource, | ||
Foundry, FoundryWorker, | ||
}, | ||
wait, wait_screen_rect, | ||
}; | ||
|
||
use super::{CastImage, DefaultSource}; | ||
|
||
/// Produces [NixOS](https://www.nixos.org) images. | ||
#[derive(Clone, Serialize, Deserialize, Validate, Debug, Default)] | ||
pub struct Nix { | ||
pub config: String, | ||
} | ||
|
||
impl Nix { | ||
fn load_config(&self) -> Result<Vec<u8>> { | ||
if self.config.starts_with("http") { | ||
todo!() | ||
} | ||
|
||
let bytes = std::fs::read(&self.config)?; | ||
Ok(bytes) | ||
} | ||
} | ||
|
||
impl DefaultSource for Nix { | ||
fn default_source(&self, _: ImageArch) -> Result<ImageSource> { | ||
Ok(ImageSource::Iso { | ||
url: "https://channels.nixos.org/nixos-23.11/latest-nixos-minimal-x86_64-linux.iso" | ||
.to_string(), | ||
checksum: None, | ||
}) | ||
} | ||
} | ||
|
||
// TODO proc macro | ||
impl Prompt for Nix { | ||
fn prompt(&mut self, _foundry: &Foundry, _theme: Box<dyn Theme>) -> Result<()> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl CastImage for Nix { | ||
fn cast(&self, worker: &FoundryWorker) -> Result<()> { | ||
let mut qemu = QemuBuilder::new(&worker, OsCategory::Linux) | ||
.source(&worker.element.source)? | ||
// Add Nix config | ||
.drive_files(HashMap::from([( | ||
"configuration.nix".to_string(), | ||
self.load_config()?, | ||
)]))? | ||
.start()?; | ||
|
||
// Send boot command | ||
#[rustfmt::skip] | ||
qemu.vnc.run(vec![ | ||
// Initial wait | ||
wait!(30), | ||
// Wait for automatic login | ||
wait_screen_rect!("94a2520c082650cc01a4b5eac8719b697a4bbf63", 100, 100, 100, 100), | ||
enter!("sudo su -"), | ||
// Mount config partition and copy configuration.nix | ||
enter!("mkdir /goldboot"), | ||
enter!("mount /dev/vdb /goldboot"), | ||
enter!("cp /goldboot/configuration.nix /mnt/etc/nixos/configuration.nix"), | ||
enter!("umount /goldboot"), | ||
// Run install | ||
enter!("nixos-install"), | ||
])?; | ||
|
||
// Shutdown | ||
qemu.shutdown_wait()?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.