148 lines
4.5 KiB
Bash
148 lines
4.5 KiB
Bash
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
# Define a wrapper for gum to handle Nix run fallback and TTY redirection
|
|
gum() {
|
|
local cmd="$1"
|
|
shift
|
|
local GUM_CMD
|
|
if command -v gum >/dev/null 2>&1; then
|
|
GUM_CMD="gum"
|
|
else
|
|
# Use --quiet to avoid progress bars in captured output
|
|
GUM_CMD="nix run --quiet --extra-experimental-features nix-command --extra-experimental-features flakes nixpkgs#gum --"
|
|
fi
|
|
|
|
case "$cmd" in
|
|
input|confirm|choose|filter|write)
|
|
$GUM_CMD "$cmd" "$@" < /dev/tty
|
|
;;
|
|
*)
|
|
$GUM_CMD "$cmd" "$@"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
clear
|
|
gum style \
|
|
--foreground 212 --border-foreground 212 --border double \
|
|
--align center --width 50 --margin "1 2" --padding "2 4" \
|
|
"NOMARCHY" "The Omarchy-flavored NixOS"
|
|
|
|
echo "This script will generate your private downstream environment."
|
|
echo ""
|
|
|
|
# 1. Gather User Information
|
|
USERNAME=$(gum input --placeholder "Enter your Linux username")
|
|
HOSTNAME=$(gum input --placeholder "Enter a hostname for this machine (e.g., nomarchy-sys)")
|
|
|
|
# 2. Setup the Local Directory
|
|
LOCAL_DIR="$HOME/.nomarchy"
|
|
echo "Creating local downstream repository at $LOCAL_DIR..."
|
|
mkdir -p "$LOCAL_DIR"/{system,home,secrets}
|
|
|
|
# 3. Harvest the Hardware Configuration
|
|
# A barebones install leaves this in /etc/nixos. We need it.
|
|
echo "Copying hardware configuration..."
|
|
sudo cp /etc/nixos/hardware-configuration.nix "$LOCAL_DIR/system/"
|
|
sudo chown "$USER:users" "$LOCAL_DIR/system/hardware-configuration.nix"
|
|
|
|
# 4. Generate the Downstream Flake
|
|
echo "Drafting your private flake.nix..."
|
|
cat <<EOF > "$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
|
|
|
|
# 5. Generate the Scaffolding Files
|
|
cat <<EOF > "$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 <<EOF > "$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
|
|
|
|
# 6. Initialize Version Control
|
|
echo "Initializing Git repository..."
|
|
nix run nixpkgs#git -- -C "$LOCAL_DIR" init
|
|
nix run nixpkgs#git -- -C "$LOCAL_DIR" add .
|
|
|
|
# 7. Execution
|
|
clear
|
|
gum style \
|
|
--foreground 212 --border-foreground 212 --border normal \
|
|
--align center --width 50 --margin "1 2" --padding "1 2" \
|
|
"Ready for Genesis"
|
|
echo "Your private downstream configuration has been generated."
|
|
|
|
if gum confirm "Build Nomarchy OS now? (This will take a few minutes)"; then
|
|
echo "Building System Engine..."
|
|
sudo nixos-rebuild switch --flake "$LOCAL_DIR#$HOSTNAME" --extra-experimental-features "nix-command flakes"
|
|
|
|
echo "Building User Interface..."
|
|
nix run home-manager/release-25.11 -- switch --flake "$LOCAL_DIR#$USERNAME"
|
|
|
|
clear
|
|
gum style \
|
|
--foreground 212 --border-foreground 212 --border double \
|
|
--align center --width 50 --margin "1 2" --padding "2 4" \
|
|
"Installation Complete"
|
|
echo "Welcome to Nomarchy OS. Reboot to enter your new environment."
|
|
else
|
|
echo "Aborted. You can review your files in $LOCAL_DIR and run the build manually later."
|
|
fi
|