From 784a9df0ca831222997b34e3d8d4e43a70c12e96 Mon Sep 17 00:00:00 2001 From: "aaron.honeycutt" Date: Tue, 15 Apr 2025 08:09:23 -0600 Subject: [PATCH 01/10] add nix flake --- flake.nix | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 flake.nix diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..60a3ffd --- /dev/null +++ b/flake.nix @@ -0,0 +1,58 @@ +{ + description = "Nyxi Installer flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-24.11"; + }; + + outputs = { nixpkgs, ... } @ inputs: + + let + system = "x86_64-linux"; + pkgs = import nixpkgs { + inherit system; + }; + in + { + checks.x86_64-linux.unitTests = (with pkgs; stdenv.mkDerivation { + pname = "nyxi-installer"; + version = "2.0.0"; + src = builtins.fetchGit { + url = "https://gitlab.com/ahoneybun/nyxi-installer.git"; + ref = "rust-rewrite"; + rev = "a0c8dafe6186de0c6eebc68d413d08bccd4e2405"; + }; + + buildInputs = with pkgs; [ cargo rustc ]; + + buildPhase = '' + cargo test + ''; + + }); + + devShells.x86_64-linux.default = pkgs.mkShell { + buildInputs = with pkgs; [ + cargo + rustc + gnumake + clang + llvmPackages.libclang + llvmPackages.clang + + # System + btrfs-progs + e2fsprogs + openssl + pkg-config + util-linux + ]; + shellHook = '' + export LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib" + export CLANG_PATH="${pkgs.llvmPackages.clang}/bin/clang" + export RUST_BACKTRACE=1 + echo "Ready to make some Rust!" + ''; + }; + }; +} From 22a35cae0ce487245b0a068d6977bc0c58fc59c1 Mon Sep 17 00:00:00 2001 From: Aaron Honeycutt Date: Wed, 16 Apr 2025 06:34:16 -0600 Subject: [PATCH 02/10] Work on docs for development and splitting the README up --- README.md | 40 +++++++++++----------------------------- docs/development.md | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 29 deletions(-) create mode 100644 docs/development.md 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..68d2d5a --- /dev/null +++ b/docs/development.md @@ -0,0 +1,37 @@ +# 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 +``` + +## For distros like Ubuntu install these packages + +```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. From 7a28998b82bdac8659564e357f29e8e68107bcdf Mon Sep 17 00:00:00 2001 From: Aaron Honeycutt Date: Wed, 16 Apr 2025 07:04:11 -0600 Subject: [PATCH 03/10] update docs/development --- docs/development.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/development.md b/docs/development.md index 68d2d5a..3bc6b7f 100644 --- a/docs/development.md +++ b/docs/development.md @@ -14,13 +14,15 @@ 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. +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 ``` -## For distros like Ubuntu install these packages +## Ubuntu + +Install these packages for developing using `apt`. ```bash sudo apt install build-essential pkg-config libcurl4-openssl-dev libfdisk-dev From f134004ddbc51008976b2cf6a28acf368f39fdea Mon Sep 17 00:00:00 2001 From: Aaron Honeycutt Date: Wed, 16 Apr 2025 20:39:37 -0600 Subject: [PATCH 04/10] remove unused variables --- src/main.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 33c52a8..2bb35d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,8 +55,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); From fb3e99f8e45c2c68fac690c7433f36d9048b72c8 Mon Sep 17 00:00:00 2001 From: Aaron Honeycutt Date: Thu, 17 Apr 2025 12:49:52 -0600 Subject: [PATCH 05/10] better flake? --- .gitignore | 6 ++++ flake.lock | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 75 +++++++++++++++--------------------------- 3 files changed, 128 insertions(+), 49 deletions(-) create mode 100644 flake.lock 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/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 index 60a3ffd..c4579d1 100644 --- a/flake.nix +++ b/flake.nix @@ -1,58 +1,35 @@ { - description = "Nyxi Installer flake"; + description = "Flake to build and develop Nyxi"; inputs = { - nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-24.11"; + flake-utils.url = "github:numtide/flake-utils"; + naersk.url = "github:nix-community/naersk"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; }; - outputs = { nixpkgs, ... } @ inputs: - - let - system = "x86_64-linux"; - pkgs = import nixpkgs { - inherit system; - }; - in - { - checks.x86_64-linux.unitTests = (with pkgs; stdenv.mkDerivation { - pname = "nyxi-installer"; - version = "2.0.0"; - src = builtins.fetchGit { - url = "https://gitlab.com/ahoneybun/nyxi-installer.git"; - ref = "rust-rewrite"; - rev = "a0c8dafe6186de0c6eebc68d413d08bccd4e2405"; - }; + outputs = { self, flake-utils, naersk, nixpkgs }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = (import nixpkgs) { + inherit system; + }; - buildInputs = with pkgs; [ cargo rustc ]; + naersk' = pkgs.callPackage naersk {}; - buildPhase = '' - cargo test - ''; + in rec { + # For `nix build` & `nix run`: + defaultPackage = naersk'.buildPackage { + LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; + CLANG_PATH = "${pkgs.llvmPackages.clang}/bin/clang"; + buildInputs = with pkgs; [ pkg-config openssl ]; + nativeBuildInputs = with pkgs; [ util-linux.dev ]; + src = ./.; + }; - }); - - devShells.x86_64-linux.default = pkgs.mkShell { - buildInputs = with pkgs; [ - cargo - rustc - gnumake - clang - llvmPackages.libclang - llvmPackages.clang - - # System - btrfs-progs - e2fsprogs - openssl - pkg-config - util-linux - ]; - shellHook = '' - export LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib" - export CLANG_PATH="${pkgs.llvmPackages.clang}/bin/clang" - export RUST_BACKTRACE=1 - echo "Ready to make some Rust!" - ''; - }; - }; + # For `nix develop` (optional, can be skipped): + devShell = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ rustc cargo ]; + }; + } + ); } From daa701753d8f0648b359b18e584968d367e91559 Mon Sep 17 00:00:00 2001 From: Aaron Honeycutt Date: Thu, 17 Apr 2025 12:57:41 -0600 Subject: [PATCH 06/10] nix develop works --- flake.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index c4579d1..c6b4877 100644 --- a/flake.nix +++ b/flake.nix @@ -28,7 +28,10 @@ # For `nix develop` (optional, can be skipped): devShell = pkgs.mkShell { - nativeBuildInputs = with pkgs; [ rustc cargo ]; + LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; + CLANG_PATH = "${pkgs.llvmPackages.clang}/bin/clang"; + buildInputs = with pkgs; [ pkg-config openssl ]; + nativeBuildInputs = with pkgs; [ rustc cargo util-linux.dev ]; }; } ); From e2450857bed3bd001565edc4c14ba6fd0c7e5766 Mon Sep 17 00:00:00 2001 From: Aaron Honeycutt Date: Thu, 17 Apr 2025 13:04:57 -0600 Subject: [PATCH 07/10] clean up the flake a bit --- flake.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index c6b4877..b73e439 100644 --- a/flake.nix +++ b/flake.nix @@ -16,11 +16,14 @@ 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 { - LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; - CLANG_PATH = "${pkgs.llvmPackages.clang}/bin/clang"; + inherit LIBCLANG_PATH CLANG_PATH; buildInputs = with pkgs; [ pkg-config openssl ]; nativeBuildInputs = with pkgs; [ util-linux.dev ]; src = ./.; @@ -28,8 +31,7 @@ # For `nix develop` (optional, can be skipped): devShell = pkgs.mkShell { - LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; - CLANG_PATH = "${pkgs.llvmPackages.clang}/bin/clang"; + inherit LIBCLANG_PATH CLANG_PATH; buildInputs = with pkgs; [ pkg-config openssl ]; nativeBuildInputs = with pkgs; [ rustc cargo util-linux.dev ]; }; From 4dccfd16b14956b8af0f8945330e2b7bf9b1eda8 Mon Sep 17 00:00:00 2001 From: Aaron Honeycutt Date: Sat, 19 Apr 2025 17:01:22 -0600 Subject: [PATCH 08/10] remove size_in_sectors for root partition as it completely fills the drive for the root partition --- src/main.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2bb35d6..c1b5ffc 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)?; From 0cd5007ae7e29e6c560bfdd92da56c5c4a8aaa6c Mon Sep 17 00:00:00 2001 From: Aaron Honeycutt Date: Sat, 19 Apr 2025 17:25:52 -0600 Subject: [PATCH 09/10] add boot permission fix --- src/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main.rs b/src/main.rs index c1b5ffc..b51cf5c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -228,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!(""); From c070fcac90f1bb8db33a5dba1d3942912672c686 Mon Sep 17 00:00:00 2001 From: Aaron Honeycutt Date: Sat, 19 Apr 2025 22:38:12 -0600 Subject: [PATCH 10/10] remove quit as it is after the formatting so pointless --- src/main.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index b51cf5c..16020b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -233,12 +233,12 @@ fn main() { .arg("-i") .arg(r#"/fsType = "vfat"/ { n - s/\(options = \[.*\)\]/\1"umask=0077 "]/ + s/\(options = \[.*\)\]/\1"umask=0077 "]/ }"#) .arg("/mnt/etc/nixos/hardware-configuration.nix") .output() .expect("Failed to apply boot fix"); - + // Host selection loop { println!(""); @@ -246,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:"); @@ -292,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."), } }