refactor: remove NixOS specific configuration and update installation messages for broader compatibility
All checks were successful
Nix Format Check / check-format (push) Successful in 37s

This commit is contained in:
Menno van Leeuwen 2025-01-22 15:39:49 +01:00
parent bfea159a0f
commit 7a39c2c962
Signed by: vleeuwenmenno
SSH Key Fingerprint: SHA256:OJFmjANpakwD3F2Rsws4GLtbdz1TJ5tkQF0RZmF0TRE

View File

@ -81,65 +81,6 @@ validate_hostname() {
return 0
}
update_nixos_flake() {
local hostname="$1"
local isServer="$2"
local isWorkstation="$3"
local flake_file="$DOTFILES_DIR/config/nixos/flake.nix"
# Determine which common module to use
local common_module="./common/workstation.nix"
if [ "$isServer" = "true" ]; then
common_module="./common/server.nix"
fi
# Create new configuration entry
local new_config=" \"$hostname\" = nixpkgs.lib.nixosSystem {
inherit system;
modules = [
./hardware/$hostname.nix
$common_module
./configuration.nix
];
specialArgs = {
inherit pkgs-unstable;
isWorkstation = $isWorkstation;
isServer = $isServer;
};
};
"
# Create temporary file
local temp_file=$(mktemp)
# Find the line number where nixosConfigurations = { appears
local config_line=$(grep -n "nixosConfigurations = {" "$flake_file" | cut -d: -f1)
if [ -z "$config_line" ]; then
rm "$temp_file"
die "Could not find nixosConfigurations in flake.nix"
fi
# Copy the file up to the line after nixosConfigurations = {
head -n "$config_line" "$flake_file" > "$temp_file"
# Add the new configuration
echo "$new_config" >> "$temp_file"
# Add the rest of the file starting from the line after nixosConfigurations = {
tail -n +"$((config_line + 1))" "$flake_file" >> "$temp_file"
# Validate the new file
if ! nix-shell -p nixfmt --run "nixfmt $temp_file"; then
rm "$temp_file"
return 1
fi
# Replace original file
mv "$temp_file" "$flake_file" || return 1
log_success "NixOS Flake configuration added successfully."
}
update_home_manager_flake() {
local hostname="$1"
local isServer="$2"
@ -190,11 +131,11 @@ update_home_manager_flake() {
install_nix() {
if command -v nix-channel >/dev/null 2>&1; then
log_success "Detected NixOS, skipping Nix setup."
log_success "Detected Nix, skipping Nix setup."
return 0
fi
log_info "NixOS not detected, installing Nix..."
log_info "Nix not detected, installing Nix..."
if ! sh <(curl -L https://nixos.org/nix/install) --daemon; then
die "Failed to install Nix"
fi
@ -221,17 +162,6 @@ setup_symlinks() {
ln -s "$DOTFILES_DIR/config/home-manager" "$HOME/.config/home-manager" || \
die "Failed to create home-manager symlink"
# Handle NixOS configuration with proper sudo permissions
if [ -d "/etc/nixos" ]; then
if [ -f "/etc/nixos/configuration.nix" ]; then
backup_file "/etc/nixos/configuration.nix" true
fi
log_info "Linking /etc/nixos/configuration.nix to $DOTFILES_DIR/config/nixos/configuration.nix..."
sudo ln -s "$DOTFILES_DIR/config/nixos/configuration.nix" "/etc/nixos/configuration.nix" || \
die "Failed to create nixos configuration symlink"
fi
# Verify symlinks
confirm_symlink "$HOME/.config/home-manager" "Failed to set up home-manager symlink"
log_success "Symlinks set up successfully."
@ -298,7 +228,7 @@ warning_prompt() {
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/Fedora installation."
log_info "This script works best on a fresh Fedora, Ubuntu or Arch Linux installation."
log_info "Type 'continue' to continue or Ctrl+C to exit."
read -r -p "> " continue < /dev/tty
if [ "$continue" != "continue" ]; then