mirror of
https://gitlab.com/ahoneybun/nyxi-installer.git
synced 2025-05-13 03:23:01 -06:00
Compare commits
No commits in common. "24febde5f70749ae12a11d8c5702d5816f60b5f7" and "4e567a79b00e748d5ec9232723c78bc33ab66a71" have entirely different histories.
24febde5f7
...
4e567a79b0
3 changed files with 26 additions and 113 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,5 +1 @@
|
||||||
/target
|
/target
|
||||||
flake.nix
|
|
||||||
configuration.nix
|
|
||||||
home.nix
|
|
||||||
garrus.nix
|
|
||||||
|
|
|
@ -5,6 +5,6 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
curl = "0.4.47"
|
curl = "0.4.47"
|
||||||
nix = { version = "0.29.0", features = ["mount"] }
|
nix = "0.29.0"
|
||||||
rsfdisk = "0.1.0"
|
rsfdisk = "0.1.0"
|
||||||
sys_metrics = "0.2.7"
|
sys_metrics = "0.2.7"
|
||||||
|
|
133
src/main.rs
133
src/main.rs
|
@ -1,16 +1,12 @@
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::fs;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::path::Path;
|
|
||||||
use sys_metrics::disks;
|
use sys_metrics::disks;
|
||||||
use rsfdisk::fdisk::Fdisk;
|
use rsfdisk::fdisk::Fdisk;
|
||||||
use rsfdisk::core::partition_table::PartitionTableKind;
|
use rsfdisk::core::partition_table::PartitionTableKind;
|
||||||
use rsfdisk::core::partition::{Guid, Partition, PartitionKind};
|
use rsfdisk::core::partition::{Guid, Partition, PartitionKind};
|
||||||
|
|
||||||
use nix::mount::{mount, MsFlags};
|
|
||||||
use std::os::unix::ffi::OsStrExt;
|
|
||||||
use curl::easy::Easy;
|
use curl::easy::Easy;
|
||||||
|
|
||||||
fn format_drive(drive_name: &str) -> rsfdisk::Result<()> {
|
fn format_drive(drive_name: &str) -> rsfdisk::Result<()> {
|
||||||
|
@ -38,11 +34,9 @@ fn format_drive(drive_name: &str) -> rsfdisk::Result<()> {
|
||||||
let root = Partition::builder()
|
let root = Partition::builder()
|
||||||
.partition_type(partition_type)
|
.partition_type(partition_type)
|
||||||
.name("Root")
|
.name("Root")
|
||||||
// Flash drive testing
|
.size_in_sectors(121_634_816)
|
||||||
// .size_in_sectors(121_634_816)
|
// 500GB
|
||||||
// Internal drive testing
|
//.size_in_sectors(499_033_071_61)
|
||||||
.size_in_sectors(499_033_071_61)
|
|
||||||
// replace static int with a variable
|
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
let _ = disk.partition_add(root)?;
|
let _ = disk.partition_add(root)?;
|
||||||
|
@ -52,80 +46,11 @@ fn format_drive(drive_name: &str) -> rsfdisk::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_partitions() {
|
// fn mount_parts() {}
|
||||||
let _efi_partition = Command::new("mkfs.fat")
|
|
||||||
.arg("-F32")
|
|
||||||
.arg("-n")
|
|
||||||
.arg("EFI")
|
|
||||||
// replace static path with a variable
|
|
||||||
.arg("/dev/nvme1n1p1")
|
|
||||||
.output()
|
|
||||||
.expect("Failed to partition boot partition as FAT32");
|
|
||||||
|
|
||||||
let _root_partition = Command::new("mkfs.ext4")
|
|
||||||
// replace static path with a variable
|
|
||||||
.arg("/dev/nvme1n1p2")
|
|
||||||
.output()
|
|
||||||
.expect("Failed to partition root partition as ext4");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mount_root() {
|
|
||||||
// replace static path with a variable
|
|
||||||
let root_source = Some(Path::new("/dev/nvme1n1p2"));
|
|
||||||
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(
|
|
||||||
root_source,
|
|
||||||
root_target,
|
|
||||||
Some("ext4"),
|
|
||||||
MsFlags::empty(),
|
|
||||||
None::<&[u8]>,
|
|
||||||
)
|
|
||||||
.expect("Failed to mount root partition");
|
|
||||||
|
|
||||||
// Deletes the boot directory
|
|
||||||
// Shouldn't be needed with a blank drive
|
|
||||||
// So just for testing
|
|
||||||
let _delete_boot_directory = Command::new("rm")
|
|
||||||
.arg("-r")
|
|
||||||
.arg("/mnt/boot")
|
|
||||||
.output()
|
|
||||||
.expect("Failed to delete boot directory");
|
|
||||||
|
|
||||||
// Creates the boot directory in /mnt/boot
|
|
||||||
let _create_boot_directory = Command::new("mkdir")
|
|
||||||
.arg("/mnt/boot")
|
|
||||||
.output()
|
|
||||||
.expect("Failed to create boot directory");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mount_boot() {
|
|
||||||
// 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");
|
|
||||||
|
|
||||||
println!("");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn grab_flake() {
|
fn grab_flake() {
|
||||||
let mut easy = Easy::new();
|
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("flake.nix").unwrap();
|
||||||
|
|
||||||
|
@ -141,7 +66,7 @@ fn grab_flake() {
|
||||||
|
|
||||||
fn grab_config() {
|
fn grab_config() {
|
||||||
let mut easy = Easy::new();
|
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("configuration.nix").unwrap();
|
||||||
|
|
||||||
|
@ -157,7 +82,7 @@ fn grab_config() {
|
||||||
|
|
||||||
fn grab_home() {
|
fn grab_home() {
|
||||||
let mut easy = Easy::new();
|
let mut easy = Easy::new();
|
||||||
easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/rust-rewrite/home.nix").unwrap();
|
easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/home.nix").unwrap();
|
||||||
|
|
||||||
let mut file = File::create("home.nix").unwrap();
|
let mut file = File::create("home.nix").unwrap();
|
||||||
|
|
||||||
|
@ -194,8 +119,6 @@ fn main() {
|
||||||
|
|
||||||
println!("");
|
println!("");
|
||||||
println!("Use the full drive path such as /dev/nvme0n1 or /dev/sda");
|
println!("Use the full drive path such as /dev/nvme0n1 or /dev/sda");
|
||||||
println!("If you're on the Lemur nvme1n1 is the test drive");
|
|
||||||
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()
|
io::stdin()
|
||||||
|
@ -208,12 +131,18 @@ fn main() {
|
||||||
let _ = format_drive(drive_name);
|
let _ = format_drive(drive_name);
|
||||||
|
|
||||||
// Formatting the partitions
|
// Formatting the partitions
|
||||||
format_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");
|
||||||
|
|
||||||
// Mounting the partitions
|
let _root_partition = Command::new("mkfs.ext4")
|
||||||
mount_root();
|
.arg("/dev/sda2")
|
||||||
|
.output()
|
||||||
// mount_boot();
|
.expect("Failed to partition root partition as ext4");
|
||||||
|
|
||||||
// Download nix files
|
// Download nix files
|
||||||
grab_flake();
|
grab_flake();
|
||||||
|
@ -227,19 +156,10 @@ fn main() {
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to execute command");
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
println!("");
|
|
||||||
println!("-------------------------");
|
|
||||||
println!("Water packed!");
|
|
||||||
println!("Treats packed!");
|
|
||||||
println!("We're ready for our walk!");
|
|
||||||
println!("-------------------------");
|
|
||||||
|
|
||||||
// Host selection
|
// Host selection
|
||||||
loop {
|
loop {
|
||||||
println!("");
|
println!("");
|
||||||
println!("Host selection:");
|
println!("Host selection");
|
||||||
println!("---------------");
|
|
||||||
println!("");
|
|
||||||
println!("1. Lemur Pro 13 (Garrus)");
|
println!("1. Lemur Pro 13 (Garrus)");
|
||||||
println!("2. Device 2");
|
println!("2. Device 2");
|
||||||
println!("3. Quit");
|
println!("3. Quit");
|
||||||
|
@ -255,7 +175,7 @@ fn main() {
|
||||||
let mut garrus_config = Easy::new();
|
let mut garrus_config = Easy::new();
|
||||||
garrus_config.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/hosts/x86_64/garrus/configuration.nix").unwrap();
|
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("configuration.nix").unwrap();
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut transfer = garrus_config.transfer();
|
let mut transfer = garrus_config.transfer();
|
||||||
|
@ -265,17 +185,14 @@ fn main() {
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
transfer.perform().unwrap();
|
transfer.perform().unwrap();
|
||||||
}
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
"2" => {
|
||||||
let _nixos_install = Command::new("nixos-install")
|
let _nixos_install = Command::new("nixos-install")
|
||||||
.arg("--flake")
|
.arg("--flake")
|
||||||
.arg("/mnt/etc/nixos#garrus")
|
.arg("/mnt/etc/nixos#garrus")
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to execute command");
|
.expect("Fiale to execute command");
|
||||||
|
|
||||||
break
|
|
||||||
}
|
|
||||||
"2" => {
|
|
||||||
println!("Nix the world!");
|
|
||||||
},
|
},
|
||||||
"3" => {
|
"3" => {
|
||||||
println!("Goodbye!");
|
println!("Goodbye!");
|
||||||
|
@ -284,4 +201,4 @@ fn main() {
|
||||||
_ => println!("Invalid choice, try again."),
|
_ => println!("Invalid choice, try again."),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue