Skip to content

Commit

Permalink
Install packages with home-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
staticdev committed Jan 21, 2024
1 parent ae0073b commit 27bc029
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 68 deletions.
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Expand Down
41 changes: 9 additions & 32 deletions default.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
30 changes: 29 additions & 1 deletion tasks/home-manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -27,5 +32,28 @@
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') }}"
USER: "{{ lookup('env', 'USER') }}"
changed_when: true

# REMOVE DEBUGS
- name: Display home.nix contents

Check failure on line 39 in tasks/home-manager.yml

View workflow job for this annotation

GitHub Actions / Lint

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 39 in tasks/home-manager.yml

View workflow job for this annotation

GitHub Actions / Lint

no-changed-when

Commands should not change things if nothing needs doing.
command: cat home.nix chdir=~/.config/home-manager/
register: command_output

- name: Print to console

Check failure on line 43 in tasks/home-manager.yml

View workflow job for this annotation

GitHub Actions / Lint

fqcn[action-core]

Use FQCN for builtin module actions (debug).
debug:
msg: "{{command_output.stdout}}"

Check warning on line 45 in tasks/home-manager.yml

View workflow job for this annotation

GitHub Actions / Lint

jinja[spacing]

Jinja2 spacing could be improved: {{command_output.stdout}} -> {{ command_output.stdout }}

- name: Print the value of USER
ansible.builtin.debug:
var: "{{ lookup('env', 'USER') }}"

- 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('env', 'USER') }}"
changed_when: true
21 changes: 0 additions & 21 deletions tasks/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 27bc029

Please sign in to comment.