From c651722b73127f0e8062094e20218939c5f53b7d Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Wed, 22 Jan 2025 15:11:58 +0100 Subject: [PATCH] refactor: reorganize Ansible tasks for better structure and include common package installations --- config/ansible/inventory.ini | 3 +- config/ansible/main.yml | 70 ++--------- config/ansible/tasks/{ => global}/docker.yml | 0 config/ansible/tasks/global/global.yml | 38 ++++++ config/ansible/tasks/{ => global}/ollama.yml | 0 config/ansible/tasks/{ => global}/pipx.yml | 0 config/ansible/tasks/{ => global}/rust.yml | 0 .../ansible/tasks/{ => global}/symlinks.yml | 10 +- .../ansible/tasks/{ => global}/tailscale.yml | 0 config/ansible/tasks/gnome-extensions.yml | 2 - config/ansible/tasks/servers/server.yml | 6 + .../tasks/{ => workstations}/1password.yml | 0 .../tasks/{ => workstations}/brave.yml | 0 .../tasks/{ => workstations}/flatpaks.yml | 0 .../tasks/workstations/gnome-extensions.yml | 2 + .../gnome-extensions/pano.yml | 0 .../tasks/{ => workstations}/vscode.yml | 0 .../tasks/workstations/workstation.yml | 30 +++++ setup.sh | 109 +----------------- vscode/settings.json | 41 +++++-- 20 files changed, 125 insertions(+), 186 deletions(-) rename config/ansible/tasks/{ => global}/docker.yml (100%) create mode 100644 config/ansible/tasks/global/global.yml rename config/ansible/tasks/{ => global}/ollama.yml (100%) rename config/ansible/tasks/{ => global}/pipx.yml (100%) rename config/ansible/tasks/{ => global}/rust.yml (100%) rename config/ansible/tasks/{ => global}/symlinks.yml (93%) rename config/ansible/tasks/{ => global}/tailscale.yml (100%) delete mode 100644 config/ansible/tasks/gnome-extensions.yml create mode 100644 config/ansible/tasks/servers/server.yml rename config/ansible/tasks/{ => workstations}/1password.yml (100%) rename config/ansible/tasks/{ => workstations}/brave.yml (100%) rename config/ansible/tasks/{ => workstations}/flatpaks.yml (100%) create mode 100644 config/ansible/tasks/workstations/gnome-extensions.yml rename config/ansible/tasks/{ => workstations}/gnome-extensions/pano.yml (100%) rename config/ansible/tasks/{ => workstations}/vscode.yml (100%) create mode 100644 config/ansible/tasks/workstations/workstation.yml diff --git a/config/ansible/inventory.ini b/config/ansible/inventory.ini index 6426325..7d5e8e1 100644 --- a/config/ansible/inventory.ini +++ b/config/ansible/inventory.ini @@ -3,4 +3,5 @@ mennos-laptop ansible_connection=local mennos-desktop ansible_connection=local [servers] -mennos-server ansible_connection=local \ No newline at end of file +mennos-server ansible_connection=local +homeserver-pc ansible_connection=local diff --git a/config/ansible/main.yml b/config/ansible/main.yml index c817f2f..6c2788b 100644 --- a/config/ansible/main.yml +++ b/config/ansible/main.yml @@ -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'] diff --git a/config/ansible/tasks/docker.yml b/config/ansible/tasks/global/docker.yml similarity index 100% rename from config/ansible/tasks/docker.yml rename to config/ansible/tasks/global/docker.yml diff --git a/config/ansible/tasks/global/global.yml b/config/ansible/tasks/global/global.yml new file mode 100644 index 0000000..0d9e237 --- /dev/null +++ b/config/ansible/tasks/global/global.yml @@ -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 diff --git a/config/ansible/tasks/ollama.yml b/config/ansible/tasks/global/ollama.yml similarity index 100% rename from config/ansible/tasks/ollama.yml rename to config/ansible/tasks/global/ollama.yml diff --git a/config/ansible/tasks/pipx.yml b/config/ansible/tasks/global/pipx.yml similarity index 100% rename from config/ansible/tasks/pipx.yml rename to config/ansible/tasks/global/pipx.yml diff --git a/config/ansible/tasks/rust.yml b/config/ansible/tasks/global/rust.yml similarity index 100% rename from config/ansible/tasks/rust.yml rename to config/ansible/tasks/global/rust.yml diff --git a/config/ansible/tasks/symlinks.yml b/config/ansible/tasks/global/symlinks.yml similarity index 93% rename from config/ansible/tasks/symlinks.yml rename to config/ansible/tasks/global/symlinks.yml index 4e259b9..9e7d37b 100644 --- a/config/ansible/tasks/symlinks.yml +++ b/config/ansible/tasks/global/symlinks.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: @@ -46,4 +46,4 @@ mennos-gamingpc: "~/dotfiles/config/ssh/authorized_keys/mennos-gamingpc" mennos-laptop: "~/dotfiles/config/ssh/authorized_keys/mennos-laptop" homeserver-pc: "~/dotfiles/config/ssh/authorized_keys/homeserver-pc" - wsl: "~/dotfiles/config/ssh/authorized_keys/wsl" \ No newline at end of file + wsl: "~/dotfiles/config/ssh/authorized_keys/wsl" diff --git a/config/ansible/tasks/tailscale.yml b/config/ansible/tasks/global/tailscale.yml similarity index 100% rename from config/ansible/tasks/tailscale.yml rename to config/ansible/tasks/global/tailscale.yml diff --git a/config/ansible/tasks/gnome-extensions.yml b/config/ansible/tasks/gnome-extensions.yml deleted file mode 100644 index fd103be..0000000 --- a/config/ansible/tasks/gnome-extensions.yml +++ /dev/null @@ -1,2 +0,0 @@ -- name: Install Pano - Clipboard Manager - ansible.builtin.import_tasks: tasks/gnome-extensions/pano.yml diff --git a/config/ansible/tasks/servers/server.yml b/config/ansible/tasks/servers/server.yml new file mode 100644 index 0000000..83be04c --- /dev/null +++ b/config/ansible/tasks/servers/server.yml @@ -0,0 +1,6 @@ +- name: Ensure common packages are installed + ansible.builtin.package: + name: + - openssh-server + state: present + become: true diff --git a/config/ansible/tasks/1password.yml b/config/ansible/tasks/workstations/1password.yml similarity index 100% rename from config/ansible/tasks/1password.yml rename to config/ansible/tasks/workstations/1password.yml diff --git a/config/ansible/tasks/brave.yml b/config/ansible/tasks/workstations/brave.yml similarity index 100% rename from config/ansible/tasks/brave.yml rename to config/ansible/tasks/workstations/brave.yml diff --git a/config/ansible/tasks/flatpaks.yml b/config/ansible/tasks/workstations/flatpaks.yml similarity index 100% rename from config/ansible/tasks/flatpaks.yml rename to config/ansible/tasks/workstations/flatpaks.yml diff --git a/config/ansible/tasks/workstations/gnome-extensions.yml b/config/ansible/tasks/workstations/gnome-extensions.yml new file mode 100644 index 0000000..2191cec --- /dev/null +++ b/config/ansible/tasks/workstations/gnome-extensions.yml @@ -0,0 +1,2 @@ +- name: Install Pano - Clipboard Manager + ansible.builtin.import_tasks: tasks/workstations/gnome-extensions/pano.yml diff --git a/config/ansible/tasks/gnome-extensions/pano.yml b/config/ansible/tasks/workstations/gnome-extensions/pano.yml similarity index 100% rename from config/ansible/tasks/gnome-extensions/pano.yml rename to config/ansible/tasks/workstations/gnome-extensions/pano.yml diff --git a/config/ansible/tasks/vscode.yml b/config/ansible/tasks/workstations/vscode.yml similarity index 100% rename from config/ansible/tasks/vscode.yml rename to config/ansible/tasks/workstations/vscode.yml diff --git a/config/ansible/tasks/workstations/workstation.yml b/config/ansible/tasks/workstations/workstation.yml new file mode 100644 index 0000000..d2be623 --- /dev/null +++ b/config/ansible/tasks/workstations/workstation.yml @@ -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 diff --git a/setup.sh b/setup.sh index 5f833af..51962f0 100755 --- a/setup.sh +++ b/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" diff --git a/vscode/settings.json b/vscode/settings.json index ca95a6a..36336ad 100755 --- a/vscode/settings.json +++ b/vscode/settings.json @@ -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 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 } \ No newline at end of file