use std::io; use std::io::{stdout, Write}; use std::fs::File; use std::process::Command; use sys_metrics::disks; use rsfdisk::fdisk::Fdisk; use rsfdisk::core::partition_table::PartitionTableKind; use rsfdisk::core::partition::{Guid, Partition, PartitionKind, PartitionList}; use curl::easy::Easy; fn format_drive(drive_name: &str) -> rsfdisk::Result<()> { let mut disk = Fdisk::builder() .assign_device(drive_name) .enable_read_write() .wipe_device_metadata() .build()?; disk.partition_table_create(PartitionTableKind::GPT)?; let partition_type = PartitionKind::builder() .guid(Guid::LinuxRootx86_64) .build()?; let boot = Partition::builder() .partition_type(partition_type.clone()) .name("EFI") //Assuming 512 bytes per sector, 2_097_152 sectors <=> 1 GiB. .size_in_sectors(2_097_152) .build()?; let _ = disk.partition_add(boot)?; let root = Partition::builder() .partition_type(partition_type) .name("Root") .size_in_sectors(121_634_816) // 500GB //.size_in_sectors(499_033_071_61) .build()?; let _ = disk.partition_add(root)?; disk.partition_table_write_to_disk()?; Ok(()) } fn mount_parts() {} fn grab_flake() { let mut easy = Easy::new(); easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/flake.nix").unwrap(); let mut file = File::create("flake.nix").unwrap(); { let mut transfer = easy.transfer(); transfer.write_function(|data| { file.write_all(data).unwrap(); Ok(data.len()) }).unwrap(); transfer.perform().unwrap(); } } fn grab_config() { let mut easy = Easy::new(); easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/configuration.nix").unwrap(); let mut file = File::create("configuration.nix").unwrap(); { let mut transfer = easy.transfer(); transfer.write_function(|data| { file.write_all(data).unwrap(); Ok(data.len()) }).unwrap(); transfer.perform().unwrap(); } } fn grab_home() { let mut easy = Easy::new(); easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/home.nix").unwrap(); let mut file = File::create("home.nix").unwrap(); { let mut transfer = easy.transfer(); transfer.write_function(|data| { file.write_all(data).unwrap(); Ok(data.len()) }).unwrap(); transfer.perform().unwrap(); } } fn main() { println!("--------------------------------------"); println!("| Welcome to the Nyxi Installer 2.0! |"); println!("--------------------------------------"); println!(""); println!("Availble disks for installation:"); println!("---------------------------------"); println!(""); match disks::get_physical_ioblocks() { Ok(disk_list) => { for disk in disk_list { println!("Disk: {}", disk.device_name); } } Err(_e) => println!("{}",_e), } let mut drive_name = String::new(); println!(""); println!("Use the full drive path such as /dev/nvme0n1 or /dev/sda"); println!("Which drive do we want to use for this installation?: {}", drive_name); io::stdin() .read_line(&mut drive_name) .expect("Failed to read line"); let drive_name = drive_name.trim(); // Partitioning the selected drive format_drive(drive_name); // Formatting the partitions let efi_partition = Command::new("mkfs.fat") .arg("-F32") .arg("-n") .arg("EFI") .arg("/dev/sda1") .output() .expect("Failed to partition boot partition as FAT32"); let root_partition = Command::new("mkfs.ext4") .arg("/dev/sda2") .output() .expect("Failed to partition root partition as ext4"); // Download nix files grab_flake(); grab_config(); grab_home(); let nixos_gen_config = Command::new("nixos-generate-config") .arg("no-file-systems") .arg("--root") .arg("/mnt") .output() .expect("Failed to execute command"); // Host selection loop { println!(""); println!("Host selection"); println!("1. Lemur Pro 13 (Garrus)"); println!("2. Device 2"); println!("3. Quit"); println!(""); println!("Enter your host for installation:"); let mut choice = String::new(); io::stdin().read_line(&mut choice).unwrap(); match choice.trim() { "1" => { let mut garrusConfig = Easy::new(); garrusConfig.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/hosts/x86_64/garrus/configuration.nix").unwrap(); let mut configFile = File::create("configuration.nix").unwrap(); { let mut transfer = garrusConfig.transfer(); transfer.write_function(|data| { configFile.write_all(data).unwrap(); Ok(data.len()) }).unwrap(); transfer.perform().unwrap(); } break } "2" => { let nixos_install = Command::new("nixos-install") .arg("--flake") .arg("/mnt/etc/nixos#garrus") .output() .expect("Fiale to execute command"); }, "3" => { println!("Goodbye!"); break; }, _ => println!("Invalid choice, try again."), } } }