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:
parent
596a3574df
commit
c651722b73
@ -4,3 +4,4 @@ mennos-desktop ansible_connection=local
|
||||
|
||||
[servers]
|
||||
mennos-server ansible_connection=local
|
||||
homeserver-pc ansible_connection=local
|
||||
|
@ -3,69 +3,13 @@
|
||||
gather_facts: true
|
||||
|
||||
tasks:
|
||||
- name: Include symlinks tasks
|
||||
ansible.builtin.import_tasks: tasks/symlinks.yml
|
||||
- name: Include global tasks
|
||||
ansible.builtin.import_tasks: tasks/global/global.yml
|
||||
|
||||
- name: Gather package facts
|
||||
ansible.builtin.package_facts:
|
||||
manager: auto
|
||||
become: true
|
||||
|
||||
- name: Include Tailscale tasks
|
||||
ansible.builtin.import_tasks: tasks/tailscale.yml
|
||||
become: true
|
||||
|
||||
- name: Include VSCode tasks
|
||||
ansible.builtin.import_tasks: tasks/vscode.yml
|
||||
when: hostname in ['mennos-laptop', 'mennos-desktop']
|
||||
become: true
|
||||
|
||||
- name: Include Rust tasks
|
||||
ansible.builtin.import_tasks: tasks/rust.yml
|
||||
become: true
|
||||
|
||||
- name: Include Brave tasks
|
||||
ansible.builtin.import_tasks: tasks/brave.yml
|
||||
when: hostname in ['mennos-laptop', 'mennos-desktop']
|
||||
become: true
|
||||
|
||||
- name: Include 1Password tasks
|
||||
ansible.builtin.import_tasks: tasks/1password.yml
|
||||
when: hostname in ['mennos-laptop', 'mennos-desktop']
|
||||
become: true
|
||||
|
||||
- name: Include Docker tasks
|
||||
ansible.builtin.import_tasks: tasks/docker.yml
|
||||
become: true
|
||||
|
||||
- name: Include Ollama tasks
|
||||
ansible.builtin.import_tasks: tasks/ollama.yml
|
||||
become: true
|
||||
|
||||
- name: Include GNOME Extensions tasks
|
||||
ansible.builtin.import_tasks: tasks/gnome-extensions.yml
|
||||
|
||||
- name: Ensure common packages are installed
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- git
|
||||
- vim
|
||||
- pipx
|
||||
- trash-cli
|
||||
- curl
|
||||
- wget
|
||||
- flatpak
|
||||
# Required by Pano - Clipboard Manager (GNOME Extension)
|
||||
- libgda
|
||||
- libgda-sqlite
|
||||
# Required by Bubblemail - Email Notifications (GNOME Extension)
|
||||
- bubblemail
|
||||
state: present
|
||||
become: true
|
||||
|
||||
- name: Include flatpaks tasks
|
||||
ansible.builtin.import_tasks: tasks/flatpaks.yml
|
||||
- name: Include workstation tasks
|
||||
ansible.builtin.import_tasks: tasks/workstations/workstation.yml
|
||||
when: hostname in ['mennos-laptop', 'mennos-desktop']
|
||||
|
||||
- name: Include pipx tasks
|
||||
ansible.builtin.import_tasks: tasks/pipx.yml
|
||||
- name: Include server tasks
|
||||
ansible.builtin.import_tasks: tasks/servers/server.yml
|
||||
when: hostname in ['mennos-server', 'homeserver-pc', 'mennos-vm']
|
||||
|
38
config/ansible/tasks/global/global.yml
Normal file
38
config/ansible/tasks/global/global.yml
Normal file
@ -0,0 +1,38 @@
|
||||
- name: Include symlinks tasks
|
||||
ansible.builtin.import_tasks: tasks/global/symlinks.yml
|
||||
|
||||
- name: Gather package facts
|
||||
ansible.builtin.package_facts:
|
||||
manager: auto
|
||||
become: true
|
||||
|
||||
- name: Include Tailscale tasks
|
||||
ansible.builtin.import_tasks: tasks/global/tailscale.yml
|
||||
become: true
|
||||
|
||||
- name: Include Rust tasks
|
||||
ansible.builtin.import_tasks: tasks/global/rust.yml
|
||||
become: true
|
||||
|
||||
- name: Include Docker tasks
|
||||
ansible.builtin.import_tasks: tasks/global/docker.yml
|
||||
become: true
|
||||
|
||||
- name: Include Ollama tasks
|
||||
ansible.builtin.import_tasks: tasks/global/ollama.yml
|
||||
become: true
|
||||
|
||||
- name: Ensure common packages are installed
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- git
|
||||
- vim
|
||||
- pipx
|
||||
- trash-cli
|
||||
- curl
|
||||
- wget
|
||||
state: present
|
||||
become: true
|
||||
|
||||
- name: Include pipx tasks
|
||||
ansible.builtin.import_tasks: tasks/global/pipx.yml
|
@ -1,5 +1,5 @@
|
||||
- name: Set user home directory
|
||||
set_fact:
|
||||
ansible.builtin.set_fact:
|
||||
user_home: "{{ ansible_env.HOME if ansible_user_id == 'root' else lookup('env', 'HOME') }}"
|
||||
|
||||
- name: Create basic symlinks
|
||||
@ -7,7 +7,7 @@
|
||||
src: "{{ item.src | replace('~', user_home) }}"
|
||||
dest: "{{ item.dest | replace('~', user_home) }}"
|
||||
state: link
|
||||
force: yes
|
||||
force: true
|
||||
follow: false
|
||||
loop:
|
||||
- { src: "~/dotfiles/config/home-manager", dest: "~/.config/home-manager" }
|
||||
@ -21,7 +21,7 @@
|
||||
src: "{{ gitconfig_mapping[hostname] | replace('~', user_home) }}"
|
||||
dest: "{{ user_home }}/.gitconfig"
|
||||
state: link
|
||||
force: yes
|
||||
force: true
|
||||
follow: false
|
||||
vars:
|
||||
gitconfig_mapping:
|
||||
@ -37,7 +37,7 @@
|
||||
src: "{{ authorized_keys_mapping[hostname] | replace('~', user_home) }}"
|
||||
dest: "{{ user_home }}/.ssh/authorized_keys"
|
||||
state: link
|
||||
force: yes
|
||||
force: true
|
||||
follow: false
|
||||
vars:
|
||||
authorized_keys_mapping:
|
@ -1,2 +0,0 @@
|
||||
- name: Install Pano - Clipboard Manager
|
||||
ansible.builtin.import_tasks: tasks/gnome-extensions/pano.yml
|
6
config/ansible/tasks/servers/server.yml
Normal file
6
config/ansible/tasks/servers/server.yml
Normal file
@ -0,0 +1,6 @@
|
||||
- name: Ensure common packages are installed
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- openssh-server
|
||||
state: present
|
||||
become: true
|
2
config/ansible/tasks/workstations/gnome-extensions.yml
Normal file
2
config/ansible/tasks/workstations/gnome-extensions.yml
Normal file
@ -0,0 +1,2 @@
|
||||
- name: Install Pano - Clipboard Manager
|
||||
ansible.builtin.import_tasks: tasks/workstations/gnome-extensions/pano.yml
|
30
config/ansible/tasks/workstations/workstation.yml
Normal file
30
config/ansible/tasks/workstations/workstation.yml
Normal file
@ -0,0 +1,30 @@
|
||||
- name: Include VSCode tasks
|
||||
ansible.builtin.import_tasks: tasks/workstations/vscode.yml
|
||||
become: true
|
||||
|
||||
- name: Include Brave tasks
|
||||
ansible.builtin.import_tasks: tasks/workstations/brave.yml
|
||||
become: true
|
||||
|
||||
- name: Include 1Password tasks
|
||||
ansible.builtin.import_tasks: tasks/workstations/1password.yml
|
||||
become: true
|
||||
|
||||
- name: Include GNOME Extensions tasks
|
||||
ansible.builtin.import_tasks: tasks/workstations/gnome-extensions.yml
|
||||
|
||||
- name: Include flatpaks tasks
|
||||
ansible.builtin.import_tasks: tasks/workstations/flatpaks.yml
|
||||
|
||||
- name: Ensure common packages are installed
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
# Flatpak package manager, used for various applications
|
||||
- flatpak
|
||||
# Required by Pano - Clipboard Manager (GNOME Extension)
|
||||
- libgda
|
||||
- libgda-sqlite
|
||||
# Required by Bubblemail - Email Notifications (GNOME Extension)
|
||||
- bubblemail
|
||||
state: present
|
||||
become: true
|
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"
|
||||
|
@ -9,28 +9,49 @@
|
||||
"markdown": true,
|
||||
"scminput": false
|
||||
},
|
||||
"git.autofetch": true,
|
||||
"workbench.iconTheme": "vscode-icons",
|
||||
"[jsonc]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"[json]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
},
|
||||
"git.autofetch": false,
|
||||
"git.openRepositoryInParentFolders": "always",
|
||||
"makefile.configureOnOpen": false,
|
||||
"vsicons.dontShowNewVersionMessage": true,
|
||||
"debug.internalConsoleOptions": "openOnSessionStart",
|
||||
|
||||
"[go]": {
|
||||
"editor.tabSize": 4,
|
||||
"editor.renderWhitespace": "all"
|
||||
},
|
||||
|
||||
"[dart]": {
|
||||
// Automatically format code on save and during typing of certain characters
|
||||
// (like `;` and `}`).
|
||||
"editor.formatOnSave": true,
|
||||
"editor.formatOnType": true,
|
||||
"editor.rulers": [140],
|
||||
|
||||
// Draw a guide line at 80 characters, where Dart's formatting will wrap code.
|
||||
"editor.rulers": [80],
|
||||
|
||||
// Disables built-in highlighting of words that match your selection. Without
|
||||
// this, all instances of the selected text will be highlighted, interfering
|
||||
// with Dart's ability to highlight only exact references to the selected variable.
|
||||
"editor.selectionHighlight": false,
|
||||
"editor.suggestSelection": "first",
|
||||
|
||||
// Allows pressing <TAB> to complete snippets such as `for` even when the
|
||||
// completion list is not visible.
|
||||
"editor.tabCompletion": "onlySnippets",
|
||||
|
||||
// By default, VS Code will populate code completion with words found in the
|
||||
// matching documents when a language service does not provide its own completions.
|
||||
// This results in code completion suggesting words when editing comments and
|
||||
// strings. This setting will prevent that.
|
||||
"editor.wordBasedSuggestions": "off"
|
||||
},
|
||||
"[nix]": {
|
||||
"editor.formatOnSave": true
|
||||
"remote.SSH.remotePlatform": {
|
||||
"mennos-laptop": "linux",
|
||||
"mennos-desktop": "linux"
|
||||
},
|
||||
"editor.tabSize": 2,
|
||||
"editor.insertSpaces": true,
|
||||
@ -41,5 +62,5 @@
|
||||
"[dockercompose]": {
|
||||
"editor.defaultFormatter": "ms-azuretools.vscode-docker"
|
||||
},
|
||||
"go.toolsManagement.autoUpdate": true,
|
||||
"go.toolsManagement.autoUpdate": true
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user