From d83d2648639f8e748ec1a58950506a0960a86686 Mon Sep 17 00:00:00 2001 From: staticdev Date: Sun, 21 Jan 2024 15:11:48 +0100 Subject: [PATCH] Install packages with home-manager --- README.md | 12 ++---------- default.config.yml | 41 +++++++++-------------------------------- main.yml | 8 ++++---- tasks/home-manager.yml | 28 ++++++++++++++++++++++++++++ tasks/packages.yml | 21 --------------------- 5 files changed, 43 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index bee96f0..7d5dfe1 100644 --- a/README.md +++ b/README.md @@ -129,15 +129,9 @@ installed_packages: - go ``` -For [Nix] packages, it is necessary to specify a command that will verify if it is already installed, most binaries support `--version` or just `version`, eg: +To have you own dotfiles, just fork the [dotfiles eg. repo] and change the url of `dotfiles_repo` or just change `configure_dotfiles` to false if you do not want it. -```yaml -nix_packages: - - name: git - check_cmd: git --version - - name: kubectl - check_cmd: kubectl version --client -``` +For [Nix] packages, update your [Home Manager] config on your dotfiles repo. Other package managers: @@ -152,8 +146,6 @@ npm_packages: - name: webpack ``` -To have you own dotfiles, just fork the [dotfiles eg. repo] and change the url of `dotfiles_repo` or just change `configure_dotfiles` to false if you do not want it. - Any variable can be overridden in **config.yml**; see the supporting roles' documentation for a complete list of available variables. ### Use with a remote machine diff --git a/default.config.yml b/default.config.yml index 8fb5ce7..6c17396 100644 --- a/default.config.yml +++ b/default.config.yml @@ -14,30 +14,16 @@ installed_packages: - podman # see https://github.com/NixOS/nixpkgs/issues/138423 - poedit +# Dotfiles (requires git on installed_packages or extra_packages) +configure_dotfiles: true +dotfiles_repo: "https://github.com/staticdev/dotfiles-eg.git" +dotfiles_repo_version: main +dotfiles_files: + - .tmux.conf + - .vimrc + - .zshrc + install_home_manager: true -nix_packages: - - name: kubectl - check_cmd: kubectl version --client - - name: helm - check_cmd: helm --version - - name: k9s - check_cmd: k9s version - - name: htop - check_cmd: htop --version - - name: nmap - check_cmd: nmap --version - - name: thefuck - check_cmd: thefuck --version - - name: tmux - check_cmd: tmux -V - - name: vagrant - check_cmd: vagrant --version - - name: vim - check_cmd: vim --version - - name: wget - check_cmd: wget --version - - name: xclip - check_cmd: xclip -version # Install packages from other package managers install_extra_packages: true @@ -58,15 +44,6 @@ npm_packages: [] # Default is false in favor to podman installation in installed_packages install_docker: false -# Dotfiles (requires git on installed_packages or extra_packages) -configure_dotfiles: true -dotfiles_repo: "https://github.com/staticdev/dotfiles-eg.git" -dotfiles_repo_version: main -dotfiles_files: - - .tmux.conf - - .vimrc - - .zshrc - # Development ## Go settings golang_developer: true diff --git a/main.yml b/main.yml index 067b1b6..2d7372c 100644 --- a/main.yml +++ b/main.yml @@ -21,10 +21,6 @@ ansible.builtin.include_tasks: tasks/packages.yml when: install_packages - - name: Install Home Manager - ansible.builtin.include_tasks: tasks/home-manager.yml - when: install_home_manager - - name: Install zsh ansible.builtin.include_tasks: tasks/zsh.yml when: install_zsh @@ -81,6 +77,10 @@ when: install_rclone tasks: + - name: Install Home Manager + ansible.builtin.include_tasks: tasks/home-manager.yml + when: install_home_manager + - name: Install Pycharm ansible.builtin.include_tasks: tasks/pycharm.yml when: install_pycharm diff --git a/tasks/home-manager.yml b/tasks/home-manager.yml index e277aa0..92d97e4 100644 --- a/tasks/home-manager.yml +++ b/tasks/home-manager.yml @@ -7,6 +7,11 @@ changed_when: false ignore_errors: true +- name: Copy Home Manager config from dotifles + ansible.builtin.command: + cmd: "mv ~/Documents/dotfiles/home-manager ~/.config/" + creates: "~/.config/home-manager" + - name: Add Home Manager channel when: home_manager_cmd is failed ansible.builtin.command: "nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager" @@ -29,3 +34,26 @@ # workaround of https://github.com/nix-community/home-manager/issues/3944 USER: "{{ lookup('ansible.builtin.pipe', 'id -un') }}" changed_when: true + +# REMOVE DEBUGS +- name: Display home.nix contents + command: cat home.nix chdir=~/.config/home-manager/ + register: command_output + +- name: Print to console + debug: + msg: "{{command_output.stdout}}" + +- name: Print the value of USER + ansible.builtin.debug: + var: "{{ lookup('ansible.builtin.pipe', 'id -un') }}" + +- name: Activate config + when: home_manager_cmd is failed + ansible.builtin.command: + cmd: "home-manager switch" + environment: + PATH: "{{ ansible_env.HOME + '/.nix-profile/bin:$PATH' }}" + # workaround of https://github.com/nix-community/home-manager/issues/3944 + USER: "{{ lookup('ansible.builtin.pipe', 'id -un') }}" + changed_when: true diff --git a/tasks/packages.yml b/tasks/packages.yml index 645926f..7ea375a 100644 --- a/tasks/packages.yml +++ b/tasks/packages.yml @@ -31,24 +31,3 @@ line: 'export PATH="{{ ansible_env.HOME }}/.nix-profile/bin:$PATH"' insertafter: EOF state: present - -- name: "Check installation of Nix packages" - ansible.builtin.command: "{{ item.check_cmd }}" - environment: - PATH: "{{ ansible_env.HOME + '/.nix-profile/bin:$PATH' }}" - register: package_check_cmd - changed_when: false - ignore_errors: true - loop: "{{ nix_packages }}" - loop_control: - index_var: package_index - -- name: "Install Nix packages" - ansible.builtin.command: "nix profile install nixpkgs#{{ item.name }}" - environment: - PATH: "{{ ansible_env.HOME + '/.nix-profile/bin:$PATH' }}" - when: package_check_cmd.results[package_index].failed - changed_when: true - loop: "{{ nix_packages }}" - loop_control: - index_var: package_index