diff --git a/.gitignore b/.gitignore index 34537f4..94eb0df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,14 @@ +# Rust/Carge /target + +# Nix +result + # Main nix files flake.nix configuration.nix home.nix + # Extra nix files garrus.nix gnome.nix diff --git a/README.md b/README.md index 04c0632..a664e69 100644 --- a/README.md +++ b/README.md @@ -16,34 +16,16 @@ This sets the hashedPassword to my own so you will need to update it to match yo mkpasswd -m sha-512 ``` +# Usage + +1. Boot from a live disk of NixOS (ideally the minimal image) +2. Connect to network +3. Download from the releases page using curl + +```bash +curl $PATH +``` + # Development -## Clone the repository - -```bash -git clone https://gitlab.com/ahoneybun/nyxi-installer.git -``` - -## Enter the repository that you just cloned - -```bash -cd nyxi-installer -``` - -## Enter nix-shell - -This is if you are already running NixOS on your system where development will take place. This will install the needed system packages, set environment variables and such for development. - -```bash -nix-shell -``` - -## Building and testing - -You can use normal `cargo` commands like: - -- `cargo test` -- `cargo build` -- `cargo run` - -**NOTE:** you will need to build the program and run it with `sudo` currently so `cargo run` is not the best for testing. +![docs/development](https://gitlab.com/ahoneybun/nyxi-installer/-/blob/rust-rewrite/docs/development.md) diff --git a/docs/development.md b/docs/development.md new file mode 100644 index 0000000..3bc6b7f --- /dev/null +++ b/docs/development.md @@ -0,0 +1,39 @@ +# Development + +## Clone the repository + +```bash +git clone https://gitlab.com/ahoneybun/nyxi-installer.git +``` + +## Enter the repository that you just cloned + +```bash +cd nyxi-installer +``` + +## Enter nix-shell + +This is if you are already running NixOS or using the `nix` packagemanager on your system where development will take place. This will install the needed system packages, set environment variables and such for development. + +```bash +nix-shell +``` + +## Ubuntu + +Install these packages for developing using `apt`. + +```bash +sudo apt install build-essential pkg-config libcurl4-openssl-dev libfdisk-dev +``` + +## Building and testing + +You can use normal `cargo` commands like: + +- `cargo test` +- `cargo build` +- `cargo run` + +**NOTE:** you will need to build the program and run it with `sudo` currently so `cargo run` is not the best for testing. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1d51da6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,96 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1743800763, + "narHash": "sha256-YFKV+fxEpMgP5VsUcM6Il28lI0NlpM7+oB1XxbBAYCw=", + "owner": "nix-community", + "repo": "naersk", + "rev": "ed0232117731a4c19d3ee93aa0c382a8fe754b01", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1744536153, + "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1744536153, + "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs_2" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b73e439 --- /dev/null +++ b/flake.nix @@ -0,0 +1,40 @@ +{ + description = "Flake to build and develop Nyxi"; + + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + naersk.url = "github:nix-community/naersk"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + }; + + outputs = { self, flake-utils, naersk, nixpkgs }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = (import nixpkgs) { + inherit system; + }; + + naersk' = pkgs.callPackage naersk {}; + + # Setting variables that everything uses + LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; + CLANG_PATH = "${pkgs.llvmPackages.clang}/bin/clang"; + + in rec { + # For `nix build` & `nix run`: + defaultPackage = naersk'.buildPackage { + inherit LIBCLANG_PATH CLANG_PATH; + buildInputs = with pkgs; [ pkg-config openssl ]; + nativeBuildInputs = with pkgs; [ util-linux.dev ]; + src = ./.; + }; + + # For `nix develop` (optional, can be skipped): + devShell = pkgs.mkShell { + inherit LIBCLANG_PATH CLANG_PATH; + buildInputs = with pkgs; [ pkg-config openssl ]; + nativeBuildInputs = with pkgs; [ rustc cargo util-linux.dev ]; + }; + } + ); +} diff --git a/src/main.rs b/src/main.rs index 33c52a8..16020b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,11 +40,6 @@ fn format_drive(drive_name: &str) -> rsfdisk::Result<()> { let root = Partition::builder() .partition_type(partition_type) .name("Root") - // Flash drive testing - //.size_in_sectors(121_634_816) - // Internal drive testing - .size_in_sectors(499_033_071_61) - // replace static int with a variable .build()?; let _ = disk.partition_add(root)?; @@ -55,8 +50,6 @@ fn format_drive(drive_name: &str) -> rsfdisk::Result<()> { } 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); @@ -235,6 +228,17 @@ fn main() { .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"/ { + n + s/\(options = \[.*\)\]/\1"umask=0077 "]/ + }"#) + .arg("/mnt/etc/nixos/hardware-configuration.nix") + .output() + .expect("Failed to apply boot fix"); + // Host selection loop { println!(""); @@ -242,8 +246,7 @@ fn main() { println!("---------------"); println!(""); println!("1. Lemur Pro 13 (Garrus)"); - println!("2. Device 2"); - println!("3. Quit"); + println!("2. Generic"); println!(""); println!("Enter your host for installation:"); @@ -288,12 +291,20 @@ fn main() { break } "2" => { - println!("Nix the world!"); - }, - "3" => { - println!("Goodbye!"); + let mut nixos_install = Command::new("nixos-install") + .arg("--flake") + .arg("/mnt/etc/nixos#nixos") + .arg("--no-root-passwd") + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .spawn() + .unwrap(); + + let install_status = nixos_install.wait(); + println!("Exited with status {:?}", install_status); + break; - }, + }, _ => println!("Invalid choice, try again."), } }