From b44457af3a0d52368361c1749d437c86c754475d Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Sat, 9 Nov 2024 02:38:29 +0100 Subject: [PATCH] moves bootloader directives to hardware specific files and adds bootloader question to setup.sh --- config/nixos/configuration.nix | 4 -- config/nixos/docker/golink.nix | 1 - config/nixos/hardware/mennos-gamingpc.nix | 4 ++ config/nixos/hardware/mennos-laptop.nix | 4 ++ config/nixos/hardware/mennos-server.nix | 4 ++ setup.sh | 64 +++++++++++++++++------ 6 files changed, 61 insertions(+), 20 deletions(-) diff --git a/config/nixos/configuration.nix b/config/nixos/configuration.nix index 8981750..d15fe7d 100644 --- a/config/nixos/configuration.nix +++ b/config/nixos/configuration.nix @@ -20,10 +20,6 @@ # Include docker if this is a server, otherwise include nothing because we don't intend on running docker services on workstations. ++ lib.optional isServer ./docker/default.nix; - # Bootloader. - boot.loader.systemd-boot.enable = true; - boot.loader.efi.canTouchEfiVariables = true; - # Enable networking networking.networkmanager.enable = true; diff --git a/config/nixos/docker/golink.nix b/config/nixos/docker/golink.nix index 77b7d69..89cd7e6 100644 --- a/config/nixos/docker/golink.nix +++ b/config/nixos/docker/golink.nix @@ -1,5 +1,4 @@ { config, pkgs, ... }: - { environment.etc."docker/golink/docker-compose.yml".source = ./golink/docker-compose.yml; environment.etc."docker/golink/.env".source = ./golink/.env; diff --git a/config/nixos/hardware/mennos-gamingpc.nix b/config/nixos/hardware/mennos-gamingpc.nix index 342fe62..4a7c346 100644 --- a/config/nixos/hardware/mennos-gamingpc.nix +++ b/config/nixos/hardware/mennos-gamingpc.nix @@ -9,6 +9,10 @@ imports = [ /etc/nixos/hardware-configuration.nix ]; networking.hostName = "mennos-gamingpc"; + # Bootloader. + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + # Enable Vulkan support for AMD graphics cards hardware.opengl.extraPackages32 = with pkgs.pkgsi686Linux; [ amdvlk ]; diff --git a/config/nixos/hardware/mennos-laptop.nix b/config/nixos/hardware/mennos-laptop.nix index 36e197e..0e21653 100644 --- a/config/nixos/hardware/mennos-laptop.nix +++ b/config/nixos/hardware/mennos-laptop.nix @@ -9,6 +9,10 @@ imports = [ /etc/nixos/hardware-configuration.nix ]; networking.hostName = "mennos-laptop"; + # Bootloader. + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + # Enable OpenGL hardware.opengl.enable = true; diff --git a/config/nixos/hardware/mennos-server.nix b/config/nixos/hardware/mennos-server.nix index b9d0fcf..350972d 100644 --- a/config/nixos/hardware/mennos-server.nix +++ b/config/nixos/hardware/mennos-server.nix @@ -9,6 +9,10 @@ imports = [ /etc/nixos/hardware-configuration.nix ]; networking.hostName = "mennos-server"; + # Bootloader. + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + # Enable OpenGL # hardware.opengl.enable = true; diff --git a/setup.sh b/setup.sh index 5b81dde..889cad9 100755 --- a/setup.sh +++ b/setup.sh @@ -81,28 +81,60 @@ 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"; - } +{ + config, + lib, + pkgs, + modulesPath, + ... +}: +{ + imports = [ /etc/nixos/hardware-configuration.nix ]; + networking.hostName = "%s"; + +%s +} EOF ) - printf "$template" "$hostname" > "$config_file" || \ + # Generate the configuration file with hostname and boot configuration + printf "$template" "$hostname" "$boot_config" > "$config_file" || \ die "Failed to create hardware configuration" - log_success "Hardware configuration created successfully." - log_info "Consider adding additional hardware configuration to $config_file" - # Ensure interactive input before system type selection ensure_interactive @@ -139,6 +171,8 @@ EOF "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