diff --git a/src/main.rs b/src/main.rs index 4e8c056..33c52a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,21 +54,61 @@ fn format_drive(drive_name: &str) -> rsfdisk::Result<()> { Ok(()) } -fn format_partitions() { +fn format_partitions(drive_name: &str) { + let efi_number = "p1"; + let root_number = "p2"; + let efi_path = format!("{}p1", drive_name); + let root_path = format!("{}p2", drive_name); + let _efi_partition = Command::new("mkfs.fat") .arg("-F32") .arg("-n") .arg("EFI") - // Replace with non static variable - .arg("/dev/nvme1n1p1") + .arg(&efi_path) .output() - .expect("Failed to partition boot partition as FAT32"); + .expect("Failed to format boot partition as FAT32"); let _root_partition = Command::new("mkfs.ext4") - // Replace with non static variable - .arg("/dev/nvme1n1p2") + .arg(&root_path) .output() - .expect("Failed to partition root partition as ext4"); + .expect("Failed to format root partition as ext4"); +} + +fn mount_partitions(drive_name: &str) { + let efi_path = format!("{}p1", drive_name); + let root_path = format!("{}p2", drive_name); + + let root_source = Some(Path::new(&root_path)); + let root_target = Path::new("/mnt"); + + mount( + root_source, + root_target, + Some("ext4"), + MsFlags::empty(), + None::<&[u8]>, + ) + .expect("Failed to mount root partition"); + + // Creates the boot directory in /mnt/boot + let _create_boot_directory = Command::new("mkdir") + .arg("-p") + .arg("/mnt/boot") + .output() + .expect("Failed to create boot directory"); + + // replace static path with a variable + let boot_source = Some(Path::new(&efi_path)); + let boot_target = Path::new("/mnt/boot"); + + mount( + boot_source, + boot_target, + Some("vfat"), + MsFlags::empty(), + None::<&[u8]>, + ) + .expect("Failed to mount boot partition"); } fn grab_flake() { @@ -167,52 +207,22 @@ fn main() { let drive_name = drive_name.trim(); - // Partitioning the selected drive - let _ = format_drive(drive_name); - - // Formatting the partitions - format_partitions(); - // Download nix files grab_flake(); grab_config(); grab_home(); grab_gnome(); + // Partitioning the selected drive + let _ = format_drive(drive_name); + + // Formatting the partitions + format_partitions(drive_name); + // Mounting the partitions - // replace static path with a variable - let root_source = Some(Path::new("/dev/nvme1n1p2")); - let root_target = Path::new("/mnt"); - - mount( - root_source, - root_target, - Some("ext4"), - MsFlags::empty(), - None::<&[u8]>, - ) - .expect("Failed to mount root partition"); - - // Creates the boot directory in /mnt/boot - let _create_boot_directory = Command::new("mkdir") - .arg("-p") - .arg("/mnt/boot") - .output() - .expect("Failed to create boot directory"); - - // replace static path with a variable - let boot_source = Some(Path::new("/dev/nvme1n1p1")); - let boot_target = Path::new("/mnt/boot"); - - mount( - boot_source, - boot_target, - Some("vfat"), - MsFlags::empty(), - None::<&[u8]>, - ) - .expect("Failed to mount boot partition"); + mount_partitions(drive_name); + // Creates the init nix config in /mnt/etc/nixos let _nixos_gen_config = Command::new("nixos-generate-config") .arg("--root") .arg("/mnt")