#!/usr/bin/env bash set -e # --- BULLETPROOF WRAPPERS FOR BAREBONES NIXOS --- # We explicitly invoke nix run with experimental features enabled # for every external tool so it never relies on global configurations. gum() { local cmd="$1" # Redirect TTY for interactive commands so it works even if piped via curl case "$cmd" in input|confirm|choose|filter|write) nix run --quiet --extra-experimental-features "nix-command flakes" nixpkgs#gum -- "$@" < /dev/tty ;; *) nix run --quiet --extra-experimental-features "nix-command flakes" nixpkgs#gum -- "$@" ;; esac } nix_git() { nix run --quiet --extra-experimental-features "nix-command flakes" nixpkgs#git -- "$@" } clear # --- TITLE SCREEN --- gum style \ --foreground 212 --border-foreground 212 --border double \ --align center --width 60 --margin "1 2" --padding "2 4" \ "NOMARCHY" "The Omarchy-flavored NixOS" gum format "This protocol will bootstrap your **private downstream** environment." echo "" # --- STEP 1: USER INPUT --- gum style --foreground 212 "👤 User Configuration" USERNAME=$(gum input --prompt " Username: " --placeholder "e.g., alan") HOSTNAME=$(gum input --prompt " Hostname: " --placeholder "e.g., nomarchy-sys") echo "" gum format "> **Target Directory:** \`$HOME/.nomarchy\`" gum format "> **System User:** \`$USERNAME\`" gum format "> **System Host:** \`$HOSTNAME\`" echo "" # --- STEP 2: DIRECTORY & HARDWARE SCAFFOLDING --- LOCAL_DIR="$HOME/.nomarchy" gum format "### ⚙️ Initializing Architecture" mkdir -p "$LOCAL_DIR"/{system,home,secrets} gum style --foreground 120 " ✔ Created local repository structure" # Harvest the Hardware Configuration sudo cp /etc/nixos/hardware-configuration.nix "$LOCAL_DIR/system/" sudo chown "$USER:users" "$LOCAL_DIR/system/hardware-configuration.nix" gum style --foreground 120 " ✔ Imported hardware-configuration.nix" # --- STEP 3: FLAKE GENERATION --- cat < "$LOCAL_DIR/flake.nix" { description = "Private Downstream Machine Config (Nomarchy)"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11"; home-manager = { url = "github:nix-community/home-manager/release-25.11"; inputs.nixpkgs.follows = "nixpkgs"; }; # The Public Upstream Core nomarchy.url = "git+https://git.bemagri.xyz/bernardo/Nomarchy.git"; }; outputs = { self, nixpkgs, home-manager, nomarchy, ... }@inputs: let system = "x86_64-linux"; targetUser = "$USERNAME"; in { # THE SYSTEM DOMAIN nixosConfigurations."$HOSTNAME" = nixpkgs.lib.nixosSystem { inherit system; specialArgs = { inputs = nomarchy.inputs // inputs; }; modules = [ ./system/hardware-configuration.nix ./system/configuration.nix nomarchy.nixosModules.system ]; }; # THE USER DOMAIN homeConfigurations."$USERNAME" = home-manager.lib.homeManagerConfiguration { pkgs = nixpkgs.legacyPackages."\${system}"; extraSpecialArgs = { inputs = nomarchy.inputs // inputs; inherit targetUser; }; modules = [ nomarchy.nixosModules.home ./home/home.nix ]; }; }; } EOF cat < "$LOCAL_DIR/system/configuration.nix" { pkgs, ... }: { networking.hostName = "$HOSTNAME"; # Add your private cryptography and C++ toolchains here later! environment.systemPackages = with pkgs; [ gcc cmake gdb ]; } EOF cat < "$LOCAL_DIR/home/home.nix" { ... }: { home.username = "$USERNAME"; home.homeDirectory = "/home/$USERNAME"; home.stateVersion = "25.11"; home.shellAliases = { update-sys = "sudo nixos-rebuild switch --flake ~/.nomarchy#$HOSTNAME"; update-home = "nix run home-manager/release-25.11 -- switch --flake ~/.nomarchy#$USERNAME"; }; } EOF gum style --foreground 120 " ✔ Generated unified flake.nix and sub-modules" # --- STEP 4: VERSION CONTROL --- gum spin --spinner dot --title " Initializing Version Control..." -- bash -c " nix run --quiet --extra-experimental-features 'nix-command flakes' nixpkgs#git -- -C \"$LOCAL_DIR\" init > /dev/null 2>&1 nix run --quiet --extra-experimental-features 'nix-command flakes' nixpkgs#git -- -C \"$LOCAL_DIR\" add . > /dev/null 2>&1 " gum style --foreground 120 " ✔ Version control active" echo "" # --- STEP 5: EXECUTION GATE --- gum style \ --foreground 212 --border-foreground 212 --border normal \ --align center --width 60 --margin "1 2" --padding "1 2" \ "Ready for Genesis" if gum confirm "Build Nomarchy OS now?"; then echo "" gum spin --spinner line --title " Compiling System Engine (Requires Sudo)..." -- \ sudo nixos-rebuild switch --flake "$LOCAL_DIR#$HOSTNAME" --extra-experimental-features "nix-command flakes" gum spin --spinner line --title " Building User Interface..." -- \ nix run --extra-experimental-features "nix-command flakes" home-manager/release-25.11 -- switch --flake "$LOCAL_DIR#$USERNAME" clear gum style \ --foreground 120 --border-foreground 120 --border double \ --align center --width 60 --margin "1 2" --padding "2 4" \ "Installation Complete" \ "Welcome to Nomarchy OS." gum format "Reboot your machine to enter the new environment." else echo "" gum style --foreground 196 "Deployment aborted." gum format "Your configuration files are safely stored in \`$LOCAL_DIR\`." gum format "You can inspect them and run the build manually later." fi