add stdin for nixos-install output

This commit is contained in:
Aaron Honeycutt 2025-04-11 21:36:21 -06:00
parent d401322fde
commit db4741c423

View file

@ -1,7 +1,7 @@
use std::io;
use std::io::Write;
use std::fs::File;
use std::process::Command;
use std::process::{Command, Stdio};
use std::path::Path;
use sys_metrics::disks;
use rsfdisk::fdisk::Fdisk;
@ -20,12 +20,12 @@ fn format_drive(drive_name: &str) -> rsfdisk::Result<()> {
disk.partition_table_create(PartitionTableKind::GPT)?;
let boot_type = PartitionKind::builder()
let partition_type = PartitionKind::builder()
.guid(Guid::EfiSystem)
.build()?;
let boot = Partition::builder()
.partition_type(boot_type.clone())
.partition_type(partition_type)
.name("EFI")
//Assuming 512 bytes per sector, 2_097_152 sectors <=> 1 GiB.
.size_in_sectors(2_097_152)
@ -33,17 +33,17 @@ fn format_drive(drive_name: &str) -> rsfdisk::Result<()> {
let _ = disk.partition_add(boot)?;
let root_type = PartitionKind::builder()
let partition_type = PartitionKind::builder()
.guid(Guid::LinuxRootx86_64)
.build()?;
let root = Partition::builder()
.partition_type(root_type)
.partition_type(partition_type)
.name("Root")
// Flash drive testing
// .size_in_sectors(121_634_816)
.size_in_sectors(121_634_816)
// Internal drive testing
.size_in_sectors(499_033_071_61)
// .size_in_sectors(499_033_071_61)
// replace static int with a variable
.build()?;
@ -60,29 +60,22 @@ fn format_partitions() {
.arg("-n")
.arg("EFI")
// replace static path with a variable
.arg("/dev/nvme1n1p1")
.arg("/dev/sda1")
.output()
.expect("Failed to partition boot partition as FAT32");
let _root_partition = Command::new("mkfs.ext4")
// replace static path with a variable
.arg("/dev/nvme1n1p2")
.arg("/dev/sda2")
.output()
.expect("Failed to partition root partition as ext4");
}
fn mount_root() {
// replace static path with a variable
let root_source = Some(Path::new("/dev/nvme1n1p2"));
let root_source = Some(Path::new("/dev/sda2"));
let root_target = Path::new("/mnt");
// unmounts root before hand to fix bugs
let _umount_root = Command::new("umount")
// replace static path with a variable
.arg("/dev/nvme1n1p2")
.output()
.expect("Failed to unmount root");
mount(
root_source,
root_target,
@ -110,7 +103,7 @@ fn mount_root() {
fn mount_boot() {
// replace static path with a variable
let boot_source = Some(Path::new("/dev/nvme1n1p1"));
let boot_source = Some(Path::new("/dev/sda1"));
let boot_target = Path::new("/mnt/boot");
mount(
@ -229,7 +222,6 @@ fn main() {
// Mounting the partitions
mount_root();
mount_boot();
// Download nix files
@ -290,13 +282,16 @@ fn main() {
.output()
.expect("Failed to copy nix files over");
let nixos_install = Command::new("nixos-install")
let mut nixos_install = Command::new("nixos-install")
.arg("--flake")
.arg("/mnt/etc/nixos#garrus")
.output()
.expect("Failed to execute command");
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()
.unwrap();
println!("stdout:\n{}", String::from_utf8_lossy(&nixos_install.stdout));
let install_status = nixos_install.wait();
println!("Exited with status {:?}", install_status);
break
}