diff --git a/.gitignore b/.gitignore index 94eb0df..d1ff78e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,10 +5,4 @@ result # Main nix files -flake.nix -configuration.nix -home.nix - -# Extra nix files -garrus.nix -gnome.nix +/data diff --git a/README.md b/README.md index a664e69..fd5496f 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,12 @@ 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 3bc6b7f..5808ad7 100644 --- a/docs/development.md +++ b/docs/development.md @@ -20,6 +20,14 @@ 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 4cbaff9..4b9f9e9 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::fs::File; -use std::process::{Command, Stdio}; use std::path::Path; +use std::process::{Command, Stdio}; use sys_metrics::disks; -use rsfdisk::fdisk::Fdisk; -use rsfdisk::core::partition_table::PartitionTableKind; -use rsfdisk::core::partition::{Guid, Partition, PartitionKind}; -use nix::mount::{mount, MsFlags}; use curl::easy::Easy; +use nix::mount::{mount, MsFlags}; fn format_drive(drive_name: &str) -> rsfdisk::Result<()> { let mut disk = Fdisk::builder() @@ -20,9 +20,7 @@ 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) @@ -90,80 +88,100 @@ 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"); - mount( - boot_source, - boot_target, - Some("vfat"), - MsFlags::empty(), - None::<&[u8]>, - ) - .expect("Failed to mount boot partition"); + 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"); } fn grab_flake() { let mut easy = Easy::new(); - easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/rust-rewrite/flake.nix").unwrap(); + easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/flake.nix") + .unwrap(); - let mut file = File::create("flake.nix").unwrap(); + let mut file = File::create("data/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/rust-rewrite/configuration.nix").unwrap(); + easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/configuration.nix") + .unwrap(); - let mut file = File::create("configuration.nix").unwrap(); + let mut file = File::create("data/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/rust-rewrite/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(){ - let mut gnome_config = Easy::new(); - gnome_config.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/desktops/gnome.nix").unwrap(); +fn grab_home() { + let mut easy = Easy::new(); + easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/home.nix") + .unwrap(); - let mut config_file = File::create("gnome.nix").unwrap(); + let mut file = File::create("data/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 grab_gnome() { + let mut gnome_config = Easy::new(); + 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 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(); } } @@ -184,7 +202,7 @@ fn main() { println!("Disk: {}", disk.device_name); } } - Err(_e) => println!("{}",_e), + Err(_e) => println!("{}", _e), } let mut drive_name = String::new(); @@ -192,7 +210,10 @@ 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) @@ -224,17 +245,25 @@ fn main() { // Copies the nix files to /mnt/etc/nixos/ let _nix_move = Command::new("mv") - .args(["-f", "flake.nix", "configuration.nix", "home.nix", "/mnt/etc/nixos"]) + .args([ + "-f", + "data/flake.nix", + "data/configuration.nix", + "data/home.nix", + ]) + .arg("/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"); @@ -260,20 +289,22 @@ 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("garrus.nix").unwrap(); + let mut config_file = File::create("data/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(["garrus.nix", "gnome.nix", "/mnt/etc/nixos"]) + .args(["data/garrus.nix", "data/gnome.nix", "/mnt/etc/nixos"]) .output() .expect("Failed to copy nix files over"); @@ -289,26 +320,28 @@ 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("vm.nix").unwrap(); + let mut config_file = File::create("data/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(["vm.nix", "/mnt/etc/nixos"]) + .args(["data/vm.nix", "/mnt/etc/nixos"]) .output() .expect("Failed to copy nix files over"); @@ -340,7 +373,7 @@ fn main() { println!("Exited with status {:?}", install_status); break; - }, + } _ => println!("Invalid choice, try again."), } }