Skip to content

Commit 6eee8d5

Browse files
committed
feat: add dotfiles to Pi
1 parent 4f6b85f commit 6eee8d5

18 files changed

+280
-120
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ _This [Ansible](https://www.ansible.com) configuration automates the setup of a
3434
- **NextCloud** with **OnlyOffice** for file synchronization and sharing
3535
- **Immich** for media synchronization with fast-upload speeds
3636
- **Home Assistant** for home automation and IoT management
37+
- **Dotfiles** for a standardized environment
3738

3839
## ⚙️ Requirements
3940

playbook.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@
2020
ansible.builtin.import_tasks: pre_tasks/mount_nvme_ssds.yml
2121
- name: Suppress login message
2222
ansible.builtin.import_tasks: pre_tasks/suppress_login_message.yml
23+
post_tasks:
24+
- name: Display new public key for manual GitHub setup
25+
ansible.builtin.debug:
26+
msg: "Copy this public key into your GitHub account: {{ keypair_result.public_key }}"
27+
when: keypair_result.changed
28+
- name: Post-install instructions for Dotfiles
29+
ansible.builtin.debug:
30+
msg: "To initialize the dotfiles, run the following command: chezmoi init --source=~/.dotfiles --apply"
31+
when: not dotfiles_stat.stat.exists
2332

2433
roles:
25-
- zsh
34+
- dotfiles
2635
- docker
2736
- caddy
2837
- cloudflare-ddns-updater

roles/docker/tasks/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
- name: Add Docker repository to sources list
3737
ansible.builtin.apt_repository:
38-
repo: "deb [arch=arm64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release | lower }} stable"
38+
repo: "deb [arch=arm64 signed-by={{ gpg_key_file }}] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release | lower }} stable"
3939
filename: docker
4040

4141
- name: Install

roles/zsh/tasks/bat.yml renamed to roles/dotfiles/tasks/bat.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
- name: Install bat
2-
when: "'bat' not in ansible_facts.packages"
32
block:
43
- name: Install
54
ansible.builtin.apt:
65
name: bat
76
update_cache: true
7+
when: "'bat' not in ansible_facts.packages"
88

99
- name: Ensure .local/bin directory exists
1010
file:

roles/dotfiles/tasks/carapace.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- name: Install carapace
2+
when: "'carapace' not in ansible_facts.packages"
3+
block:
4+
- name: Add carapace repository to sources list
5+
ansible.builtin.apt_repository:
6+
repo: "deb [trusted=yes] https://apt.fury.io/rsteube/ /"
7+
filename: fury
8+
9+
- name: Install
10+
ansible.builtin.apt:
11+
name: carapace-bin
12+
update_cache: true

roles/dotfiles/tasks/chezmoi.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- name: Install chezmoi
2+
block:
3+
- name: Ensure .local/bin directory exists
4+
file:
5+
path: "/home/{{ ansible_user }}/.local/bin"
6+
state: directory
7+
become_user: "{{ ansible_user }}"
8+
9+
- name: Install
10+
ansible.builtin.shell: sh -c "$(curl -fsLS get.chezmoi.io/lb)"
11+
args:
12+
creates: "/home/{{ ansible_user }}/.local/bin/chezmoi"
13+
become_user: "{{ ansible_user }}"

roles/dotfiles/tasks/delta.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
- name: Install delta
2+
block:
3+
- name: Check if already installed
4+
ansible.builtin.command: dpkg-query -W delta
5+
register: delta_res
6+
failed_when: delta_res.rc > 1
7+
changed_when: delta_res.rc == 1
8+
9+
- name: Check latest delta version
10+
ansible.builtin.uri:
11+
url: "https://api.github.com/repos/dandavison/delta/releases/latest"
12+
return_content: true
13+
body_format: json
14+
register: response
15+
when: delta_res.rc == 1
16+
17+
- name: Install
18+
ansible.builtin.apt:
19+
deb: "https://github.com/dandavison/delta/releases/latest/download/git-delta_{{ response.json.tag_name }}_arm64.deb"
20+
when: delta_res.rc == 1

roles/zsh/tasks/eza.yml renamed to roles/dotfiles/tasks/eza.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
- name: Add eza repository to sources list
3030
ansible.builtin.apt_repository:
31-
repo: "deb [arch=arm64 signed-by={{ gpg_key_file }}] http://deb.gierens.de stable main"
31+
repo: "deb [signed-by={{ gpg_key_file }}] http://deb.gierens.de stable main"
3232
filename: gierens
3333

3434
- name: Install
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
- name: Install fastfetch
2-
vars:
3-
fastfetch_config_dir: "/home/{{ ansible_user }}/.config/fastfetch"
42
block:
53
- name: Check if already installed
64
ansible.builtin.command: dpkg-query -W fastfetch
@@ -17,13 +15,3 @@
1715
ansible.builtin.apt:
1816
deb: "https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-linux-aarch64.deb"
1917
when: fastfetch_res.rc == 1
20-
21-
- name: Ensure fastfetch config directory exists
22-
ansible.builtin.file:
23-
path: "{{ fastfetch_config_dir }}"
24-
state: directory
25-
26-
- name: Copy config
27-
ansible.builtin.get_url:
28-
url: "https://raw.githubusercontent.com/Nitestack/dotfiles/refs/heads/main/config/private_dot_config/exact_fastfetch/config.jsonc"
29-
dest: "{{ fastfetch_config_dir }}/config.jsonc"

roles/dotfiles/tasks/lazygit.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
- name: Install lazygit
2+
block:
3+
- name: Ensure /usr/local/bin directory exists
4+
file:
5+
path: "/usr/local/bin"
6+
state: directory
7+
8+
- name: Check if already installed
9+
ansible.builtin.command: which lazygit
10+
register: lazygit_check
11+
failed_when: false
12+
changed_when: false
13+
14+
- name: Check latest lazygit version
15+
ansible.builtin.uri:
16+
url: "https://api.github.com/repos/jesseduffield/lazygit/releases/latest"
17+
return_content: true
18+
body_format: json
19+
register: response
20+
when: lazygit_check.rc != 0
21+
22+
- name: Install
23+
ansible.builtin.unarchive:
24+
src: "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_{{ response.json.tag_name | regex_replace('^v(?=[0-9])', '') }}_Linux_arm64.tar.gz"
25+
dest: "/usr/local/bin/"
26+
creates: "/usr/local/bin/lazygit"
27+
remote_src: true
28+
include:
29+
- lazygit
30+
when: lazygit_check.rc != 0

roles/dotfiles/tasks/main.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
- name: Set up Dotfiles
3+
vars:
4+
ssh_key_type: ed25519
5+
block:
6+
- name: Install Git
7+
ansible.builtin.apt:
8+
name: git
9+
update_cache: true
10+
when: "'git' not in ansible_facts.packages"
11+
- name: Install Nushell
12+
ansible.builtin.include_tasks: ./nushell.yml
13+
- name: Install chezmoi
14+
ansible.builtin.include_tasks: ./chezmoi.yml
15+
- name: Install bat
16+
ansible.builtin.include_tasks: ./bat.yml
17+
- name: Install carapace
18+
ansible.builtin.include_tasks: ./carapace.yml
19+
- name: Install delta
20+
ansible.builtin.include_tasks: ./delta.yml
21+
- name: Install eza
22+
ansible.builtin.include_tasks: ./eza.yml
23+
- name: Install fastfetch
24+
ansible.builtin.include_tasks: ./fastfetch.yml
25+
- name: Install lazygit
26+
ansible.builtin.include_tasks: ./lazygit.yml
27+
- name: Install Oh My Posh
28+
ansible.builtin.include_tasks: ./oh-my-posh.yml
29+
- name: Install vivid
30+
ansible.builtin.include_tasks: ./vivid.yml
31+
- name: Install zoxide
32+
ansible.builtin.include_tasks: ./zoxide.yml
33+
34+
- name: Add GitHub to ~/.ssh/known_hosts
35+
ansible.builtin.known_hosts:
36+
name: "github.com"
37+
key: "{{ lookup('pipe', 'ssh-keyscan -t rsa github.com') }}"
38+
become_user: "{{ ansible_user }}"
39+
40+
- name: Generate SSH keypair for user (if absent)
41+
community.crypto.openssh_keypair:
42+
path: "/home/{{ ansible_user }}/.ssh/id_{{ ssh_key_type }}"
43+
type: "{{ ssh_key_type }}"
44+
become_user: "{{ ansible_user }}"
45+
register: keypair_result
46+
47+
- name: Check if Dotfiles exists
48+
ansible.builtin.stat:
49+
path: "/home/{{ ansible_user }}/.dotfiles"
50+
register: dotfiles_stat
51+
52+
- name: Download Dotfiles
53+
ansible.builtin.git:
54+
dest: "/home/{{ ansible_user }}/.dotfiles"
55+
repo: "git@github.com:Nitestack/dotfiles.git"
56+
accept_hostkey: true
57+
key_file: "/home/{{ ansible_user }}/.ssh/id_{{ ssh_key_type }}"
58+
when: not dotfiles_stat.stat.exists
59+
become_user: "{{ ansible_user }}"

roles/dotfiles/tasks/nushell.yml

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
- name: Install Nushell
2+
when: "'nu' not in ansible_facts.packages"
3+
vars:
4+
gpg_key_tmp_file: /tmp/nushell.gpg.key
5+
gpg_key_file: /etc/apt/keyrings/fury-nushell.gpg
6+
block:
7+
- name: Install dependencies
8+
ansible.builtin.apt:
9+
name: gpg
10+
update_cache: true
11+
12+
- name: Download GPG key
13+
ansible.builtin.get_url:
14+
url: "https://apt.fury.io/nushell/gpg.key"
15+
dest: "{{ gpg_key_tmp_file }}"
16+
mode: "0644"
17+
18+
- name: Convert GPG key to keyring format
19+
ansible.builtin.command:
20+
cmd: "gpg --dearmor -o {{ gpg_key_file }} {{ gpg_key_tmp_file }}"
21+
args:
22+
creates: "{{ gpg_key_file }}"
23+
24+
- name: Remove temporary GPG key
25+
ansible.builtin.file:
26+
name: "{{ gpg_key_tmp_file }}"
27+
state: absent
28+
29+
- name: Add Nushell repository to sources list
30+
ansible.builtin.apt_repository:
31+
repo: "deb [signed-by={{ gpg_key_file }}] https://apt.fury.io/nushell/ /"
32+
filename: fury
33+
34+
- name: Install
35+
ansible.builtin.apt:
36+
name: nushell
37+
update_cache: true
38+
39+
- name: Check if ~/.bashrc exists
40+
ansible.builtin.stat:
41+
path: "/home/{{ ansible_user }}/.bashrc"
42+
register: bashrc_stat
43+
44+
- name: Check if ~/.profile exists
45+
ansible.builtin.stat:
46+
path: "/home/{{ ansible_user }}/.profile"
47+
register: profile_stat
48+
49+
- name: Check if ~/.bash_logout exists
50+
ansible.builtin.stat:
51+
path: "/home/{{ ansible_user }}/.bash_logout"
52+
register: bash_logout_stat
53+
54+
- name: Copy /etc/skel/.bashrc to ~/.bashrc
55+
ansible.builtin.copy:
56+
src: "/etc/skel/.bashrc"
57+
dest: "/home/{{ ansible_user }}/.bashrc"
58+
when: not bashrc_stat.stat.exists
59+
become_user: "{{ ansible_user }}"
60+
61+
- name: Copy /etc/skel/.profile to ~/.profile
62+
ansible.builtin.copy:
63+
src: "/etc/skel/.profile"
64+
dest: "/home/{{ ansible_user }}/.profile"
65+
when: not profile_stat.stat.exists
66+
become_user: "{{ ansible_user }}"
67+
68+
- name: Copy /etc/skel/.bash_logout to ~/.bash_logout
69+
ansible.builtin.copy:
70+
src: "/etc/skel/.bash_logout"
71+
dest: "/home/{{ ansible_user }}/.bash_logout"
72+
when: not bash_logout_stat.stat.exists
73+
become_user: "{{ ansible_user }}"
74+
75+
- name: Ensure Nushell startup
76+
ansible.builtin.blockinfile:
77+
path: "/home/{{ ansible_user }}/.bashrc"
78+
insertafter: EOF
79+
block: |
80+
# Start Nushell for interactive sessions
81+
if [ -n "$PS1" ]; then
82+
if command -v nu &> /dev/null; then
83+
exec nu
84+
fi
85+
fi
86+
become_user: "{{ ansible_user }}"

roles/dotfiles/tasks/oh-my-posh.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- name: Install Oh My Posh
2+
block:
3+
- name: Ensure .local/bin directory exists
4+
file:
5+
path: "/home/{{ ansible_user }}/.local/bin"
6+
state: directory
7+
become_user: "{{ ansible_user }}"
8+
9+
- name: Install
10+
ansible.builtin.shell: curl -s https://ohmyposh.dev/install.sh | bash -s -- -d ~/.local/bin
11+
args:
12+
creates: "/home/{{ ansible_user }}/.local/bin/oh-my-posh"
13+
become_user: "{{ ansible_user }}"

roles/dotfiles/tasks/vivid.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
- name: Install vivid
2+
block:
3+
- name: Check if already installed
4+
ansible.builtin.command: dpkg-query -W vivid
5+
register: vivid_res
6+
failed_when: vivid_res.rc > 1
7+
changed_when: vivid_res.rc == 1
8+
9+
- name: Check latest vivid version
10+
ansible.builtin.uri:
11+
url: "https://api.github.com/repos/sharkdp/vivid/releases/latest"
12+
return_content: true
13+
body_format: json
14+
register: response
15+
when: vivid_res.rc == 1
16+
17+
- name: Install
18+
ansible.builtin.apt:
19+
deb: "https://github.com/sharkdp/vivid/releases/latest/download/vivid_{{ response.json.tag_name | regex_replace('^v(?=[0-9])', '') }}_arm64.deb"
20+
when: vivid_res.rc == 1

roles/dotfiles/tasks/zoxide.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- name: Install zoxide
2+
block:
3+
- name: Ensure .local/bin directory exists
4+
file:
5+
path: "/home/{{ ansible_user }}/.local/bin"
6+
state: directory
7+
become_user: "{{ ansible_user }}"
8+
9+
- name: Install
10+
ansible.builtin.shell: curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
11+
args:
12+
creates: "/home/{{ ansible_user }}/.local/bin/zoxide"
13+
become_user: "{{ ansible_user }}"

roles/zsh/files/.zshrc

-43
This file was deleted.

0 commit comments

Comments
 (0)