mirror of
https://gitlab.com/ahoneybun/nyxi-installer.git
synced 2025-05-12 11:04:02 -06:00
add stdin for nixos-install output
This commit is contained in:
parent
d401322fde
commit
db4741c423
1 changed files with 18 additions and 23 deletions
41
src/main.rs
41
src/main.rs
|
@ -1,7 +1,7 @@
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::process::Command;
|
use std::process::{Command, Stdio};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use sys_metrics::disks;
|
use sys_metrics::disks;
|
||||||
use rsfdisk::fdisk::Fdisk;
|
use rsfdisk::fdisk::Fdisk;
|
||||||
|
@ -20,12 +20,12 @@ fn format_drive(drive_name: &str) -> rsfdisk::Result<()> {
|
||||||
|
|
||||||
disk.partition_table_create(PartitionTableKind::GPT)?;
|
disk.partition_table_create(PartitionTableKind::GPT)?;
|
||||||
|
|
||||||
let boot_type = PartitionKind::builder()
|
let partition_type = PartitionKind::builder()
|
||||||
.guid(Guid::EfiSystem)
|
.guid(Guid::EfiSystem)
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
let boot = Partition::builder()
|
let boot = Partition::builder()
|
||||||
.partition_type(boot_type.clone())
|
.partition_type(partition_type)
|
||||||
.name("EFI")
|
.name("EFI")
|
||||||
//Assuming 512 bytes per sector, 2_097_152 sectors <=> 1 GiB.
|
//Assuming 512 bytes per sector, 2_097_152 sectors <=> 1 GiB.
|
||||||
.size_in_sectors(2_097_152)
|
.size_in_sectors(2_097_152)
|
||||||
|
@ -33,17 +33,17 @@ fn format_drive(drive_name: &str) -> rsfdisk::Result<()> {
|
||||||
|
|
||||||
let _ = disk.partition_add(boot)?;
|
let _ = disk.partition_add(boot)?;
|
||||||
|
|
||||||
let root_type = PartitionKind::builder()
|
let partition_type = PartitionKind::builder()
|
||||||
.guid(Guid::LinuxRootx86_64)
|
.guid(Guid::LinuxRootx86_64)
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
let root = Partition::builder()
|
let root = Partition::builder()
|
||||||
.partition_type(root_type)
|
.partition_type(partition_type)
|
||||||
.name("Root")
|
.name("Root")
|
||||||
// Flash drive testing
|
// Flash drive testing
|
||||||
// .size_in_sectors(121_634_816)
|
.size_in_sectors(121_634_816)
|
||||||
// Internal drive testing
|
// Internal drive testing
|
||||||
.size_in_sectors(499_033_071_61)
|
// .size_in_sectors(499_033_071_61)
|
||||||
// replace static int with a variable
|
// replace static int with a variable
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
|
@ -60,29 +60,22 @@ fn format_partitions() {
|
||||||
.arg("-n")
|
.arg("-n")
|
||||||
.arg("EFI")
|
.arg("EFI")
|
||||||
// replace static path with a variable
|
// replace static path with a variable
|
||||||
.arg("/dev/nvme1n1p1")
|
.arg("/dev/sda1")
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to partition boot partition as FAT32");
|
.expect("Failed to partition boot partition as FAT32");
|
||||||
|
|
||||||
let _root_partition = Command::new("mkfs.ext4")
|
let _root_partition = Command::new("mkfs.ext4")
|
||||||
// replace static path with a variable
|
// replace static path with a variable
|
||||||
.arg("/dev/nvme1n1p2")
|
.arg("/dev/sda2")
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to partition root partition as ext4");
|
.expect("Failed to partition root partition as ext4");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mount_root() {
|
fn mount_root() {
|
||||||
// replace static path with a variable
|
// 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");
|
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(
|
mount(
|
||||||
root_source,
|
root_source,
|
||||||
root_target,
|
root_target,
|
||||||
|
@ -110,7 +103,7 @@ fn mount_root() {
|
||||||
|
|
||||||
fn mount_boot() {
|
fn mount_boot() {
|
||||||
// replace static path with a variable
|
// 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");
|
let boot_target = Path::new("/mnt/boot");
|
||||||
|
|
||||||
mount(
|
mount(
|
||||||
|
@ -229,7 +222,6 @@ fn main() {
|
||||||
|
|
||||||
// Mounting the partitions
|
// Mounting the partitions
|
||||||
mount_root();
|
mount_root();
|
||||||
|
|
||||||
mount_boot();
|
mount_boot();
|
||||||
|
|
||||||
// Download nix files
|
// Download nix files
|
||||||
|
@ -290,13 +282,16 @@ fn main() {
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to copy nix files over");
|
.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("--flake")
|
||||||
.arg("/mnt/etc/nixos#garrus")
|
.arg("/mnt/etc/nixos#garrus")
|
||||||
.output()
|
.stdout(Stdio::inherit())
|
||||||
.expect("Failed to execute command");
|
.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
|
break
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue