diff --git a/.gitignore b/.gitignore index d1ff78e..94eb0df 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,10 @@ result # Main nix files -/data +flake.nix +configuration.nix +home.nix + +# Extra nix files +garrus.nix +gnome.nix diff --git a/README.md b/README.md index fd5496f..a664e69 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,6 @@ mkpasswd -m sha-512 curl $PATH ``` -## Older Bash installer - -```bash -sh <(curl -L https://gitlab.com/ahoneybun/nyxi-installer/-/raw/main/install.sh) -``` - # Development ![docs/development](https://gitlab.com/ahoneybun/nyxi-installer/-/blob/rust-rewrite/docs/development.md) diff --git a/docs/development.md b/docs/development.md index 5808ad7..3bc6b7f 100644 --- a/docs/development.md +++ b/docs/development.md @@ -20,14 +20,6 @@ This is if you are already running NixOS or using the `nix` packagemanager on yo nix-shell ``` -## Flakes - -If you have flakes enabled you can use `nix develop` instead. - -```bash -nix develop -``` - ## Ubuntu Install these packages for developing using `apt`. diff --git a/src/main.rs b/src/main.rs index 4b9f9e9..4cbaff9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,15 @@ -use rsfdisk::core::partition::{Guid, Partition, PartitionKind}; -use rsfdisk::core::partition_table::PartitionTableKind; -use rsfdisk::fdisk::Fdisk; -use std::fs::File; use std::io; use std::io::Write; -use std::path::Path; +use std::fs::File; use std::process::{Command, Stdio}; +use std::path::Path; use sys_metrics::disks; +use rsfdisk::fdisk::Fdisk; +use rsfdisk::core::partition_table::PartitionTableKind; +use rsfdisk::core::partition::{Guid, Partition, PartitionKind}; -use curl::easy::Easy; use nix::mount::{mount, MsFlags}; +use curl::easy::Easy; fn format_drive(drive_name: &str) -> rsfdisk::Result<()> { let mut disk = Fdisk::builder() @@ -20,7 +20,9 @@ fn format_drive(drive_name: &str) -> rsfdisk::Result<()> { disk.partition_table_create(PartitionTableKind::GPT)?; - let partition_type = PartitionKind::builder().guid(Guid::EfiSystem).build()?; + let partition_type = PartitionKind::builder() + .guid(Guid::EfiSystem) + .build()?; let boot = Partition::builder() .partition_type(partition_type) @@ -88,100 +90,80 @@ fn mount_partitions(drive_name: &str) { .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"); - let _mount_boot = Command::new("mount") - .args(["-t", "vfat"]) - .args(["-o", "umask=0077"]) - .arg(&efi_path) - .arg("/mnt/boot") - .output() - .expect("Failed to mount boot partition"); - - // mount( - // boot_source, - // boot_target, - // Some("vfat"), - // MsFlags::empty(), - // None::<&[u8]>, - // ) - // .expect("Failed to mount boot partition"); + mount( + boot_source, + boot_target, + Some("vfat"), + MsFlags::empty(), + None::<&[u8]>, + ) + .expect("Failed to mount boot partition"); } fn grab_flake() { let mut easy = Easy::new(); - easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/flake.nix") - .unwrap(); + easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/rust-rewrite/flake.nix").unwrap(); - let mut file = File::create("data/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.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(); + easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/rust-rewrite/configuration.nix").unwrap(); - let mut file = File::create("data/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.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(); + easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/rust-rewrite/home.nix").unwrap(); - let mut file = File::create("data/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.write_function(|data| { + file.write_all(data).unwrap(); + Ok(data.len()) + }).unwrap(); transfer.perform().unwrap(); } } -fn grab_gnome() { +fn grab_gnome(){ let mut gnome_config = Easy::new(); - gnome_config - .url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/desktops/gnome.nix") - .unwrap(); + gnome_config.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/desktops/gnome.nix").unwrap(); - let mut config_file = File::create("data/gnome.nix").unwrap(); + let mut config_file = File::create("gnome.nix").unwrap(); { let mut transfer = gnome_config.transfer(); - transfer - .write_function(|data| { - config_file.write_all(data).unwrap(); - Ok(data.len()) - }) - .unwrap(); + transfer.write_function(|data| { + config_file.write_all(data).unwrap(); + Ok(data.len()) + }).unwrap(); transfer.perform().unwrap(); } } @@ -202,7 +184,7 @@ fn main() { println!("Disk: {}", disk.device_name); } } - Err(_e) => println!("{}", _e), + Err(_e) => println!("{}",_e), } let mut drive_name = String::new(); @@ -210,10 +192,7 @@ fn main() { println!(""); println!("Use the full drive path such as /dev/nvme0n1 or /dev/sda"); println!(""); - println!( - "Which drive do we want to use for this installation?: {}", - drive_name - ); + println!("Which drive do we want to use for this installation?: {}", drive_name); io::stdin() .read_line(&mut drive_name) @@ -245,25 +224,17 @@ fn main() { // Copies the nix files to /mnt/etc/nixos/ let _nix_move = Command::new("mv") - .args([ - "-f", - "data/flake.nix", - "data/configuration.nix", - "data/home.nix", - ]) - .arg("/mnt/etc/nixos") + .args(["-f", "flake.nix", "configuration.nix", "home.nix", "/mnt/etc/nixos"]) .output() .expect("Failed to move nix files over"); // Fixes a security issue with boot let _boot_fix = Command::new("sed") .arg("-i") - .arg( - r#"/fsType = "vfat"/ { + .arg(r#"/fsType = "vfat"/ { n s/\(options = \[.*\)\]/\1"umask=0077 "]/ - }"#, - ) + }"#) .arg("/mnt/etc/nixos/hardware-configuration.nix") .output() .expect("Failed to apply boot fix"); @@ -289,22 +260,20 @@ fn main() { let mut garrus_config = Easy::new(); garrus_config.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/hosts/x86_64/garrus/configuration.nix").unwrap(); - let mut config_file = File::create("data/garrus.nix").unwrap(); + let mut config_file = File::create("garrus.nix").unwrap(); { let mut transfer = garrus_config.transfer(); - transfer - .write_function(|data| { - config_file.write_all(data).unwrap(); - Ok(data.len()) - }) - .unwrap(); + transfer.write_function(|data| { + config_file.write_all(data).unwrap(); + Ok(data.len()) + }).unwrap(); transfer.perform().unwrap(); } // Copies the system nix files to /mnt/etc/nixos/ let _garrus_nix_copy = Command::new("mv") - .args(["data/garrus.nix", "data/gnome.nix", "/mnt/etc/nixos"]) + .args(["garrus.nix", "gnome.nix", "/mnt/etc/nixos"]) .output() .expect("Failed to copy nix files over"); @@ -320,28 +289,26 @@ fn main() { let install_status = nixos_install.wait(); println!("Exited with status {:?}", install_status); - break; - } + break + }, "2" => { let mut vm_config = Easy::new(); vm_config.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/hosts/x86_64/vm/configuration.nix").unwrap(); - let mut config_file = File::create("data/vm.nix").unwrap(); + let mut config_file = File::create("vm.nix").unwrap(); { let mut transfer = vm_config.transfer(); - transfer - .write_function(|data| { - config_file.write_all(data).unwrap(); - Ok(data.len()) - }) - .unwrap(); + transfer.write_function(|data| { + config_file.write_all(data).unwrap(); + Ok(data.len()) + }).unwrap(); transfer.perform().unwrap(); } // Copies the system nix files to /mnt/etc/nixos/ let _garrus_nix_copy = Command::new("mv") - .args(["data/vm.nix", "/mnt/etc/nixos"]) + .args(["vm.nix", "/mnt/etc/nixos"]) .output() .expect("Failed to copy nix files over"); @@ -373,7 +340,7 @@ fn main() { println!("Exited with status {:?}", install_status); break; - } + }, _ => println!("Invalid choice, try again."), } }