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
@ -3,4 +3,5 @@ mennos-laptop ansible_connection=local
|
|||||||
mennos-desktop ansible_connection=local
|
mennos-desktop ansible_connection=local
|
||||||
|
|
||||||
[servers]
|
[servers]
|
||||||
mennos-server ansible_connection=local
|
mennos-server ansible_connection=local
|
||||||
|
homeserver-pc ansible_connection=local
|
||||||
|
@ -3,69 +3,13 @@
|
|||||||
gather_facts: true
|
gather_facts: true
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: Include symlinks tasks
|
- name: Include global tasks
|
||||||
ansible.builtin.import_tasks: tasks/symlinks.yml
|
ansible.builtin.import_tasks: tasks/global/global.yml
|
||||||
|
|
||||||
- name: Gather package facts
|
- name: Include workstation tasks
|
||||||
ansible.builtin.package_facts:
|
ansible.builtin.import_tasks: tasks/workstations/workstation.yml
|
||||||
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
|
|
||||||
when: hostname in ['mennos-laptop', 'mennos-desktop']
|
when: hostname in ['mennos-laptop', 'mennos-desktop']
|
||||||
|
|
||||||
- name: Include pipx tasks
|
- name: Include server tasks
|
||||||
ansible.builtin.import_tasks: tasks/pipx.yml
|
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
|
- 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') }}"
|
user_home: "{{ ansible_env.HOME if ansible_user_id == 'root' else lookup('env', 'HOME') }}"
|
||||||
|
|
||||||
- name: Create basic symlinks
|
- name: Create basic symlinks
|
||||||
@ -7,7 +7,7 @@
|
|||||||
src: "{{ item.src | replace('~', user_home) }}"
|
src: "{{ item.src | replace('~', user_home) }}"
|
||||||
dest: "{{ item.dest | replace('~', user_home) }}"
|
dest: "{{ item.dest | replace('~', user_home) }}"
|
||||||
state: link
|
state: link
|
||||||
force: yes
|
force: true
|
||||||
follow: false
|
follow: false
|
||||||
loop:
|
loop:
|
||||||
- { src: "~/dotfiles/config/home-manager", dest: "~/.config/home-manager" }
|
- { src: "~/dotfiles/config/home-manager", dest: "~/.config/home-manager" }
|
||||||
@ -21,7 +21,7 @@
|
|||||||
src: "{{ gitconfig_mapping[hostname] | replace('~', user_home) }}"
|
src: "{{ gitconfig_mapping[hostname] | replace('~', user_home) }}"
|
||||||
dest: "{{ user_home }}/.gitconfig"
|
dest: "{{ user_home }}/.gitconfig"
|
||||||
state: link
|
state: link
|
||||||
force: yes
|
force: true
|
||||||
follow: false
|
follow: false
|
||||||
vars:
|
vars:
|
||||||
gitconfig_mapping:
|
gitconfig_mapping:
|
||||||
@ -37,7 +37,7 @@
|
|||||||
src: "{{ authorized_keys_mapping[hostname] | replace('~', user_home) }}"
|
src: "{{ authorized_keys_mapping[hostname] | replace('~', user_home) }}"
|
||||||
dest: "{{ user_home }}/.ssh/authorized_keys"
|
dest: "{{ user_home }}/.ssh/authorized_keys"
|
||||||
state: link
|
state: link
|
||||||
force: yes
|
force: true
|
||||||
follow: false
|
follow: false
|
||||||
vars:
|
vars:
|
||||||
authorized_keys_mapping:
|
authorized_keys_mapping:
|
||||||
@ -46,4 +46,4 @@
|
|||||||
mennos-gamingpc: "~/dotfiles/config/ssh/authorized_keys/mennos-gamingpc"
|
mennos-gamingpc: "~/dotfiles/config/ssh/authorized_keys/mennos-gamingpc"
|
||||||
mennos-laptop: "~/dotfiles/config/ssh/authorized_keys/mennos-laptop"
|
mennos-laptop: "~/dotfiles/config/ssh/authorized_keys/mennos-laptop"
|
||||||
homeserver-pc: "~/dotfiles/config/ssh/authorized_keys/homeserver-pc"
|
homeserver-pc: "~/dotfiles/config/ssh/authorized_keys/homeserver-pc"
|
||||||
wsl: "~/dotfiles/config/ssh/authorized_keys/wsl"
|
wsl: "~/dotfiles/config/ssh/authorized_keys/wsl"
|
@ -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'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
readonly NIXOS_RELEASE="24.11"
|
readonly NIXOS_RELEASE="24.11" # Home Manager release version (Must match NixOS version)
|
||||||
readonly GIT_REPO="https://git.mvl.sh/vleeuwenmenno/dotfiles.git"
|
readonly GIT_REPO="https://git.mvl.sh/vleeuwenmenno/dotfiles.git" # Dotfiles repository URL
|
||||||
readonly DOTFILES_DIR="${HOME}/dotfiles"
|
readonly DOTFILES_DIR="${HOME}/dotfiles" # Dotfiles directory
|
||||||
readonly SETUP_MARKER="${HOME}/.dotfiles-setup"
|
readonly SETUP_MARKER="${HOME}/.dotfiles-setup" # Setup marker file indicates setup has been run
|
||||||
|
|
||||||
# Color constants
|
# Color constants
|
||||||
readonly RED='\033[0;31m'
|
readonly RED='\033[0;31m'
|
||||||
@ -81,107 +81,6 @@ validate_hostname() {
|
|||||||
return 0
|
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() {
|
update_nixos_flake() {
|
||||||
local hostname="$1"
|
local hostname="$1"
|
||||||
local isServer="$2"
|
local isServer="$2"
|
||||||
|
@ -9,28 +9,49 @@
|
|||||||
"markdown": true,
|
"markdown": true,
|
||||||
"scminput": false
|
"scminput": false
|
||||||
},
|
},
|
||||||
|
"git.autofetch": true,
|
||||||
"workbench.iconTheme": "vscode-icons",
|
"workbench.iconTheme": "vscode-icons",
|
||||||
"[jsonc]": {
|
"[jsonc]": {
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
},
|
},
|
||||||
"[json]": {
|
"[json]": {
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
"editor.formatOnSave": true
|
|
||||||
},
|
},
|
||||||
"git.autofetch": false,
|
"vsicons.dontShowNewVersionMessage": true,
|
||||||
"git.openRepositoryInParentFolders": "always",
|
"debug.internalConsoleOptions": "openOnSessionStart",
|
||||||
"makefile.configureOnOpen": false,
|
|
||||||
|
"[go]": {
|
||||||
|
"editor.tabSize": 4,
|
||||||
|
"editor.renderWhitespace": "all"
|
||||||
|
},
|
||||||
|
|
||||||
"[dart]": {
|
"[dart]": {
|
||||||
|
// Automatically format code on save and during typing of certain characters
|
||||||
|
// (like `;` and `}`).
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"editor.formatOnType": 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.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",
|
"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"
|
"editor.wordBasedSuggestions": "off"
|
||||||
},
|
},
|
||||||
"[nix]": {
|
"remote.SSH.remotePlatform": {
|
||||||
"editor.formatOnSave": true
|
"mennos-laptop": "linux",
|
||||||
|
"mennos-desktop": "linux"
|
||||||
},
|
},
|
||||||
"editor.tabSize": 2,
|
"editor.tabSize": 2,
|
||||||
"editor.insertSpaces": true,
|
"editor.insertSpaces": true,
|
||||||
@ -41,5 +62,5 @@
|
|||||||
"[dockercompose]": {
|
"[dockercompose]": {
|
||||||
"editor.defaultFormatter": "ms-azuretools.vscode-docker"
|
"editor.defaultFormatter": "ms-azuretools.vscode-docker"
|
||||||
},
|
},
|
||||||
"go.toolsManagement.autoUpdate": true,
|
"go.toolsManagement.autoUpdate": true
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user