Compare commits

..

2 commits

Author SHA1 Message Date
Aaron Honeycutt
d47bba478e Merge branch 'rust-rewrite' into 'main'
Draft: First Rust rewrite release! 🎉

See merge request ahoneybun/nyxi-installer!23
2025-04-20 11:01:22 -06:00
Aaron Honeycutt
bc2607c90e add logic for non-nvme drives 2025-04-20 11:01:15 -06:00
4 changed files with 89 additions and 116 deletions

8
.gitignore vendored
View file

@ -5,4 +5,10 @@
result result
# Main nix files # Main nix files
/data flake.nix
configuration.nix
home.nix
# Extra nix files
garrus.nix
gnome.nix

View file

@ -26,12 +26,6 @@ mkpasswd -m sha-512
curl $PATH curl $PATH
``` ```
## Older Bash installer
```bash
sh <(curl -L https://gitlab.com/ahoneybun/nyxi-installer/-/raw/main/install.sh)
```
# Development # Development
![docs/development](https://gitlab.com/ahoneybun/nyxi-installer/-/blob/rust-rewrite/docs/development.md) ![docs/development](https://gitlab.com/ahoneybun/nyxi-installer/-/blob/rust-rewrite/docs/development.md)

View file

@ -20,14 +20,6 @@ This is if you are already running NixOS or using the `nix` packagemanager on yo
nix-shell nix-shell
``` ```
## Flakes
If you have flakes enabled you can use `nix develop` instead.
```bash
nix develop
```
## Ubuntu ## Ubuntu
Install these packages for developing using `apt`. Install these packages for developing using `apt`.

View file

@ -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;
use std::io::Write; use std::io::Write;
use std::path::Path; use std::fs::File;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use std::path::Path;
use sys_metrics::disks; 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 nix::mount::{mount, MsFlags};
use curl::easy::Easy;
fn format_drive(drive_name: &str) -> rsfdisk::Result<()> { fn format_drive(drive_name: &str) -> rsfdisk::Result<()> {
let mut disk = Fdisk::builder() let mut disk = Fdisk::builder()
@ -20,7 +20,9 @@ fn format_drive(drive_name: &str) -> rsfdisk::Result<()> {
disk.partition_table_create(PartitionTableKind::GPT)?; 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() let boot = Partition::builder()
.partition_type(partition_type) .partition_type(partition_type)
@ -48,8 +50,15 @@ fn format_drive(drive_name: &str) -> rsfdisk::Result<()> {
} }
fn format_partitions(drive_name: &str) { fn format_partitions(drive_name: &str) {
let efi_path = format!("{}p1", drive_name); // Check if drive name ends with a digit (e.g., "nvme0n1")
let root_path = format!("{}p2", drive_name); let suffix = if drive_name.chars().last().map(|c| c.is_ascii_digit()).unwrap_or(false) {
"p"
} else {
""
};
let efi_path = format!("{}{}1", drive_name, suffix);
let root_path = format!("{}{}2", drive_name, suffix);
let _efi_partition = Command::new("mkfs.fat") let _efi_partition = Command::new("mkfs.fat")
.arg("-F32") .arg("-F32")
@ -66,8 +75,15 @@ fn format_partitions(drive_name: &str) {
} }
fn mount_partitions(drive_name: &str) { fn mount_partitions(drive_name: &str) {
let efi_path = format!("{}p1", drive_name); // Check if drive name ends with a digit (e.g., "nvme0n1")
let root_path = format!("{}p2", drive_name); let suffix = if drive_name.chars().last().map(|c| c.is_ascii_digit()).unwrap_or(false) {
"p"
} else {
""
};
let efi_path = format!("{}{}1", drive_name, suffix);
let root_path = format!("{}{}2", drive_name, suffix);
let root_source = Some(Path::new(&root_path)); let root_source = Some(Path::new(&root_path));
let root_target = Path::new("/mnt"); let root_target = Path::new("/mnt");
@ -88,100 +104,80 @@ fn mount_partitions(drive_name: &str) {
.output() .output()
.expect("Failed to create boot directory"); .expect("Failed to create boot directory");
// replace static path with a variable
let boot_source = Some(Path::new(&efi_path)); let boot_source = Some(Path::new(&efi_path));
let boot_target = Path::new("/mnt/boot"); let boot_target = Path::new("/mnt/boot");
let _mount_boot = Command::new("mount") mount(
.args(["-t", "vfat"]) boot_source,
.args(["-o", "umask=0077"]) boot_target,
.arg(&efi_path) Some("vfat"),
.arg("/mnt/boot") MsFlags::empty(),
.output() None::<&[u8]>,
.expect("Failed to mount boot partition"); )
.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() { fn grab_flake() {
let mut easy = Easy::new(); let mut easy = Easy::new();
easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/flake.nix") easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/rust-rewrite/flake.nix").unwrap();
.unwrap();
let mut file = File::create("data/flake.nix").unwrap(); let mut file = File::create("flake.nix").unwrap();
{ {
let mut transfer = easy.transfer(); let mut transfer = easy.transfer();
transfer transfer.write_function(|data| {
.write_function(|data| { file.write_all(data).unwrap();
file.write_all(data).unwrap(); Ok(data.len())
Ok(data.len()) }).unwrap();
})
.unwrap();
transfer.perform().unwrap(); transfer.perform().unwrap();
} }
} }
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/main/configuration.nix") easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/rust-rewrite/configuration.nix").unwrap();
.unwrap();
let mut file = File::create("data/configuration.nix").unwrap(); let mut file = File::create("configuration.nix").unwrap();
{ {
let mut transfer = easy.transfer(); let mut transfer = easy.transfer();
transfer transfer.write_function(|data| {
.write_function(|data| { file.write_all(data).unwrap();
file.write_all(data).unwrap(); Ok(data.len())
Ok(data.len()) }).unwrap();
})
.unwrap();
transfer.perform().unwrap(); transfer.perform().unwrap();
} }
} }
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/main/home.nix") easy.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/rust-rewrite/home.nix").unwrap();
.unwrap();
let mut file = File::create("data/home.nix").unwrap(); let mut file = File::create("home.nix").unwrap();
{ {
let mut transfer = easy.transfer(); let mut transfer = easy.transfer();
transfer transfer.write_function(|data| {
.write_function(|data| { file.write_all(data).unwrap();
file.write_all(data).unwrap(); Ok(data.len())
Ok(data.len()) }).unwrap();
})
.unwrap();
transfer.perform().unwrap(); transfer.perform().unwrap();
} }
} }
fn grab_gnome() { fn grab_gnome(){
let mut gnome_config = Easy::new(); let mut gnome_config = Easy::new();
gnome_config gnome_config.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/desktops/gnome.nix").unwrap();
.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(); let mut transfer = gnome_config.transfer();
transfer transfer.write_function(|data| {
.write_function(|data| { config_file.write_all(data).unwrap();
config_file.write_all(data).unwrap(); Ok(data.len())
Ok(data.len()) }).unwrap();
})
.unwrap();
transfer.perform().unwrap(); transfer.perform().unwrap();
} }
} }
@ -202,7 +198,7 @@ fn main() {
println!("Disk: {}", disk.device_name); println!("Disk: {}", disk.device_name);
} }
} }
Err(_e) => println!("{}", _e), Err(_e) => println!("{}",_e),
} }
let mut drive_name = String::new(); let mut drive_name = String::new();
@ -210,10 +206,7 @@ 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!(""); println!("");
println!( println!("Which drive do we want to use for this installation?: {}", drive_name);
"Which drive do we want to use for this installation?: {}",
drive_name
);
io::stdin() io::stdin()
.read_line(&mut drive_name) .read_line(&mut drive_name)
@ -245,25 +238,17 @@ fn main() {
// Copies the nix files to /mnt/etc/nixos/ // Copies the nix files to /mnt/etc/nixos/
let _nix_move = Command::new("mv") let _nix_move = Command::new("mv")
.args([ .args(["-f", "flake.nix", "configuration.nix", "home.nix", "/mnt/etc/nixos"])
"-f",
"data/flake.nix",
"data/configuration.nix",
"data/home.nix",
])
.arg("/mnt/etc/nixos")
.output() .output()
.expect("Failed to move nix files over"); .expect("Failed to move nix files over");
// Fixes a security issue with boot // Fixes a security issue with boot
let _boot_fix = Command::new("sed") let _boot_fix = Command::new("sed")
.arg("-i") .arg("-i")
.arg( .arg(r#"/fsType = "vfat"/ {
r#"/fsType = "vfat"/ {
n n
s/\(options = \[.*\)\]/\1"umask=0077 "]/ s/\(options = \[.*\)\]/\1"umask=0077 "]/
}"#, }"#)
)
.arg("/mnt/etc/nixos/hardware-configuration.nix") .arg("/mnt/etc/nixos/hardware-configuration.nix")
.output() .output()
.expect("Failed to apply boot fix"); .expect("Failed to apply boot fix");
@ -289,22 +274,20 @@ 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("data/garrus.nix").unwrap(); let mut config_file = File::create("garrus.nix").unwrap();
{ {
let mut transfer = garrus_config.transfer(); let mut transfer = garrus_config.transfer();
transfer transfer.write_function(|data| {
.write_function(|data| { config_file.write_all(data).unwrap();
config_file.write_all(data).unwrap(); Ok(data.len())
Ok(data.len()) }).unwrap();
})
.unwrap();
transfer.perform().unwrap(); transfer.perform().unwrap();
} }
// Copies the system nix files to /mnt/etc/nixos/ // Copies the system nix files to /mnt/etc/nixos/
let _garrus_nix_copy = Command::new("mv") 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() .output()
.expect("Failed to copy nix files over"); .expect("Failed to copy nix files over");
@ -320,28 +303,26 @@ fn main() {
let install_status = nixos_install.wait(); let install_status = nixos_install.wait();
println!("Exited with status {:?}", install_status); println!("Exited with status {:?}", install_status);
break; break
} },
"2" => { "2" => {
let mut vm_config = Easy::new(); let mut vm_config = Easy::new();
vm_config.url("https://gitlab.com/ahoneybun/nix-configs/-/raw/main/hosts/x86_64/vm/configuration.nix").unwrap(); 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(); let mut transfer = vm_config.transfer();
transfer transfer.write_function(|data| {
.write_function(|data| { config_file.write_all(data).unwrap();
config_file.write_all(data).unwrap(); Ok(data.len())
Ok(data.len()) }).unwrap();
})
.unwrap();
transfer.perform().unwrap(); transfer.perform().unwrap();
} }
// Copies the system nix files to /mnt/etc/nixos/ // Copies the system nix files to /mnt/etc/nixos/
let _garrus_nix_copy = Command::new("mv") let _garrus_nix_copy = Command::new("mv")
.args(["data/vm.nix", "/mnt/etc/nixos"]) .args(["vm.nix", "/mnt/etc/nixos"])
.output() .output()
.expect("Failed to copy nix files over"); .expect("Failed to copy nix files over");
@ -373,7 +354,7 @@ fn main() {
println!("Exited with status {:?}", install_status); println!("Exited with status {:?}", install_status);
break; break;
} },
_ => println!("Invalid choice, try again."), _ => println!("Invalid choice, try again."),
} }
} }