refactor: reorganize Ansible tasks for better structure and include common package installations
All checks were successful
Nix Format Check / check-format (pull_request) Successful in 40s
All checks were successful
Nix Format Check / check-format (pull_request) Successful in 40s
This commit is contained in:
109
setup.sh
109
setup.sh
@@ -4,10 +4,10 @@ set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
# Constants
|
||||
readonly NIXOS_RELEASE="24.11"
|
||||
readonly GIT_REPO="https://git.mvl.sh/vleeuwenmenno/dotfiles.git"
|
||||
readonly DOTFILES_DIR="${HOME}/dotfiles"
|
||||
readonly SETUP_MARKER="${HOME}/.dotfiles-setup"
|
||||
readonly NIXOS_RELEASE="24.11" # Home Manager release version (Must match NixOS version)
|
||||
readonly GIT_REPO="https://git.mvl.sh/vleeuwenmenno/dotfiles.git" # Dotfiles repository URL
|
||||
readonly DOTFILES_DIR="${HOME}/dotfiles" # Dotfiles directory
|
||||
readonly SETUP_MARKER="${HOME}/.dotfiles-setup" # Setup marker file indicates setup has been run
|
||||
|
||||
# Color constants
|
||||
readonly RED='\033[0;31m'
|
||||
@@ -81,107 +81,6 @@ validate_hostname() {
|
||||
return 0
|
||||
}
|
||||
|
||||
create_hardware_config() {
|
||||
local hostname="$1"
|
||||
log_info "Creating hardware configuration for $hostname..."
|
||||
|
||||
# Get boot configuration type
|
||||
local boot_config
|
||||
while true; do
|
||||
log_info "Is this a virtual machine? (y/n)"
|
||||
read -r -p "(y/n): " yn
|
||||
case $yn in
|
||||
[Yy]* )
|
||||
boot_config=$(cat << 'EOF'
|
||||
# Boot configuration for VM
|
||||
boot.loader.grub.enable = true;
|
||||
boot.loader.grub.device = "nodev";
|
||||
boot.loader.grub.efiSupport = false;
|
||||
EOF
|
||||
)
|
||||
break
|
||||
;;
|
||||
[Nn]* )
|
||||
boot_config=$(cat << 'EOF'
|
||||
# Boot configuration for physical machine
|
||||
boot.loader.systemd-boot.enable = true;
|
||||
boot.loader.efi.canTouchEfiVariables = true;
|
||||
EOF
|
||||
)
|
||||
break
|
||||
;;
|
||||
* )
|
||||
log_error "Please answer yes or no."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Create the full hardware configuration
|
||||
local config_file="$DOTFILES_DIR/config/nixos/hardware/$hostname.nix"
|
||||
local template=$(cat << 'EOF'
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
modulesPath,
|
||||
...
|
||||
}:
|
||||
{
|
||||
imports = [ /etc/nixos/hardware-configuration.nix ];
|
||||
networking.hostName = "%s";
|
||||
|
||||
%s
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
# Generate the configuration file with hostname and boot configuration
|
||||
printf "$template" "$hostname" "$boot_config" > "$config_file" || \
|
||||
die "Failed to create hardware configuration"
|
||||
|
||||
# Ensure interactive input before system type selection
|
||||
ensure_interactive
|
||||
|
||||
# System type selection
|
||||
local systemType
|
||||
while true; do
|
||||
log_info "Is this a server or workstation? (s/w)"
|
||||
read -r -p "(s/w): " systemType
|
||||
if [[ "$systemType" =~ ^[sw]$ ]]; then
|
||||
break
|
||||
fi
|
||||
log_error "Invalid input. Please enter 's' for server or 'w' for workstation."
|
||||
done
|
||||
|
||||
local isServer="false"
|
||||
local isWorkstation="false"
|
||||
if [ "$systemType" = "s" ]; then
|
||||
isServer="true"
|
||||
else
|
||||
isWorkstation="true"
|
||||
fi
|
||||
|
||||
# Update flake configurations
|
||||
update_nixos_flake "$hostname" "$isServer" "$isWorkstation" || \
|
||||
die "Failed to update NixOS flake configuration"
|
||||
|
||||
update_home_manager_flake "$hostname" "$isServer" || \
|
||||
die "Failed to update Home Manager flake configuration"
|
||||
|
||||
# Add new files to git
|
||||
git -C "$DOTFILES_DIR" add \
|
||||
"config/nixos/hardware/$hostname.nix" \
|
||||
"config/nixos/flake.nix" \
|
||||
"config/home-manager/flake.nix" || \
|
||||
die "Failed to add files to git"
|
||||
|
||||
log_success "Hardware configuration created successfully."
|
||||
log_info "Consider adding additional hardware configuration to $config_file\n"
|
||||
log_info "\nDon't forget to commit and push the changes to the dotfiles repo after testing."
|
||||
git -C "$DOTFILES_DIR" status
|
||||
echo
|
||||
}
|
||||
|
||||
update_nixos_flake() {
|
||||
local hostname="$1"
|
||||
local isServer="$2"
|
||||
|
Reference in New Issue
Block a user