refactor setup script to conditionally set hostname and rebuild NixOS only on NixOS systems
All checks were successful
Nix Format Check / check-format (push) Successful in 39s
All checks were successful
Nix Format Check / check-format (push) Successful in 39s
This commit is contained in:
parent
206cbfb564
commit
1d0ef3d31e
31
setup.sh
31
setup.sh
@ -377,11 +377,18 @@ prepare_hostname() {
|
||||
log_error "Invalid hostname. Please enter a valid hostname:"
|
||||
done
|
||||
|
||||
if [ ! -f "$DOTFILES_DIR/config/nixos/hardware/$hostname.nix" ]; then
|
||||
log_info "No hardware configuration found for $hostname."
|
||||
create_hardware_config "$hostname"
|
||||
else
|
||||
log_success "Hardware configuration found for $hostname. Continuing setup..."
|
||||
if [ ! command -v nixos-version >/dev/null 2>&1 ]; then
|
||||
log_info "Setting hostname to $hostname..."
|
||||
sudo hostnamectl set-hostname "$hostname" || die "Failed to set hostname"
|
||||
fi
|
||||
|
||||
if [ command -v nixos-version >/dev/null 2>&1 ]; then
|
||||
if [ ! -f "$DOTFILES_DIR/config/nixos/hardware/$hostname.nix" ]; then
|
||||
log_info "No hardware configuration found for $hostname."
|
||||
create_hardware_config "$hostname"
|
||||
else
|
||||
log_success "Hardware configuration found for $hostname. Continuing setup..."
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$hostname" > "$hostname_file" || die "Failed to save hostname"
|
||||
@ -389,7 +396,7 @@ prepare_hostname() {
|
||||
}
|
||||
|
||||
warning_prompt() {
|
||||
log_success "This script will set up your NixOS system using Menno's Dotfiles repository.\n"
|
||||
log_success "This script will set up your machine using Menno's Dotfiles repository.\n"
|
||||
log_error "Please ensure you have a backup of your data before proceeding."
|
||||
log_error "This script will modify system files and may require sudo permissions.\n"
|
||||
log_info "This script works best on a fresh NixOS installation."
|
||||
@ -427,11 +434,13 @@ main() {
|
||||
# Get hostname
|
||||
local hostname
|
||||
hostname=$(cat "$HOME/.hostname") || die "Failed to read hostname"
|
||||
|
||||
# Rebuild NixOS
|
||||
cd "$DOTFILES_DIR/config/nixos" || die "Failed to change to nixos config directory"
|
||||
sudo nixos-rebuild switch --flake ".#$hostname" --impure || \
|
||||
die "Failed to rebuild NixOS"
|
||||
|
||||
# Rebuild NixOS but only on NixOS systems
|
||||
if command -v nixos-version >/dev/null 2>&1; then
|
||||
cd "$DOTFILES_DIR/config/nixos" || die "Failed to change to nixos config directory"
|
||||
sudo nixos-rebuild switch --flake ".#$hostname" --impure || \
|
||||
die "Failed to rebuild NixOS"
|
||||
fi
|
||||
|
||||
# Rebuild Home Manager
|
||||
cd "$DOTFILES_DIR/config/home-manager" || die "Failed to change to home-manager config directory"
|
||||
|
Loading…
x
Reference in New Issue
Block a user