# Provision a Hetzner box with ArchLinux
## Basics
- [x] https://docs.hetzner.com/robot/dedicated-server/operating-systems/installimage/ [completion:: 2024-06-07]
- [x] Setup a new user https://wiki.archlinux.org/title/Users_and_groups [completion:: 2024-06-07]
```shell
pacman -Syu
pacman -S sudo
pacman -S zsh
useradd -m -G root -s /usr/bin/zsh kakkoyun
echo 'kakkoyun ALL=(ALL) ALL' >> /etc/sudoers
passwd kakkoyun
```
- [x] Copy ssh public key for the user [completion:: 2024-06-07]
```shell
brew info ssh-copy-id
ssh-copy-id SERVER
vim .ssh/config
# Name the server
```
- [x] Setup yay [completion:: 2024-06-07]
```shell
# sudo might be required
pacman -Syu
pacman -S --needed base-devel git
git clone https://aur.archlinux.org/yay.git
cd yay && makepkg -si
```
- [x] Install and setup Tailscale https://tailscale.com/kb/1077/secure-server-ubuntu-18-04 [completion:: 2024-06-07]
```shell
yay -S tailscale
sudo systemctl enable tailscaled.service --now
sudo tailscale login
yay -S ufw
sudo ufw enable
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow in on tailscale from any
sudo ufw reload
sudo systemctl restart sshd
```
https://www.digitalocean.com/community/tutorials/ufw-essentials-common-firewall-rules-and-commands
## Devsetup
- [x] Install and connect vscode, github [completion:: 2024-06-07]
```shell
yay -S code
yay -S github-cli # This helps you to generate necessary SSH keys
```
- [x] Install and setup terminal (zsh, starship and oh-my-zsh) [completion:: 2024-06-07]
```shell
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
sh install.sh
yay -S getnf
yay -S autojump
# Install some fonts https://github.com/getnf/getnf
curl -sS https://starship.rs/install.sh | sh
echo 'eval "$(starship init zsh)"' >> .zshrc
```
- [x] Install nix https://devenv.sh/ [completion:: 2024-06-07]
```shell
sh <(curl -L https://nixos.org/nix/install) --daemon
echo 'experimental-features = nix-command flakes' > /etc/nix/nix.conf
nix profile install --accept-flake-config nixpkgs#devenv
yay -S direnv # https://direnv.net/docs/hook.html
echo 'eval "$(direnv hook zsh)"' >> .zshrc
```
- [x] Install pyenv [completion:: 2024-06-07]
```shell
yay -S pyenv
pyenv install 3.11
pyenv global 3.11
```
- [x] Authenticate GCP https://cloud.google.com/sdk/docs/install#linux [completion:: 2024-06-07]
```shell
# https://cloud.google.com/sdk/docs/install#linux
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-479.0.0-linux-x86_64.tar.gz
tar -xf google-cloud-cli-479.0.0-linux-x86_64.tar.gz
./google-cloud-sdk/install.sh
./google-cloud-sdk/bin/gcloud init
```
- [x] Install Wakatime [completion:: 2024-06-07]
```shell
yay -S wakatime
cd ~/.oh-my-zsh/custom/plugins && git clone https://github.com/sobolevn/wakatime-zsh-plugin.git wakatime
```
## Other utilities to install
```shell
```
----
# Ansible playbook
This is auto-generated
```yaml
---
- name: Provision Arch Linux machine
hosts: all
become: true
vars:
user_name: kakkoyun
user_password: "{{ 'your_password' | password_hash('sha512') }}" # Replace 'your_password' with the actual password
tasks:
- name: Ensure system is up to date
pacman:
update_cache: yes
upgrade: yes
- name: Install necessary packages
pacman:
name:
- sudo
- zsh
- base-devel
- git
- ufw
state: present
- name: Add new user
user:
name: "{{ user_name }}"
groups: root
shell: /usr/bin/zsh
password: "{{ user_password }}"
state: present
create_home: yes
- name: Allow user to use sudo
lineinfile:
path: /etc/sudoers
state: present
line: "{{ user_name }} ALL=(ALL) ALL"
validate: 'visudo -cf %s'
- name: Copy SSH public key for the user
authorized_key:
user: "{{ user_name }}"
state: present
key: "{{ lookup('file', '/path/to/your/public/key.pub') }}" # Replace with the path to your public key
- name: Clone yay from AUR
git:
repo: https://aur.archlinux.org/yay.git
dest: /home/{{ user_name }}/yay
clone: yes
update: yes
become_user: "{{ user_name }}"
- name: Build and install yay
command: makepkg -si
args:
chdir: /home/{{ user_name }}/yay
become: true
become_user: "{{ user_name }}"
- name: Install Tailscale and configure UFW
become: true
block:
- name: Install Tailscale
pacman:
name: tailscale
state: present
- name: Enable and start Tailscale service
systemd:
name: tailscaled
enabled: yes
state: started
- name: Login to Tailscale
command: sudo tailscale login
- name: Install UFW
pacman:
name: ufw
state: present
- name: Enable UFW
ufw:
state: enabled
default:
incoming: deny
outgoing: allow
- name: Allow incoming on Tailscale
ufw:
rule: allow
name: "Allow Tailscale"
interface: tailscale0
- name: Reload UFW rules
command: sudo ufw reload
- name: Restart SSHD
systemd:
name: sshd
state: restarted
- name: Install and setup development environment
become: true
block:
- name: Install VSCode and GitHub CLI
yay:
name:
- code
- github-cli
state: present
- name: Install and configure zsh, starship, oh-my-zsh
become_user: "{{ user_name }}"
block:
- name: Install oh-my-zsh
shell: sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
- name: Install starship
shell: curl -sS https://starship.rs/install.sh | sh
- name: Update .zshrc for starship
lineinfile:
path: /home/{{ user_name }}/.zshrc
state: present
line: 'eval "$(starship init zsh)"'
- name: Install Nix and configure
shell: sh <(curl -L https://nixos.org/nix/install) --daemon
args:
creates: /nix
become_user: "{{ user_name }}"
- name: Configure Nix
lineinfile:
path: /etc/nix/nix.conf
line: 'experimental-features = nix-command flakes'
create: yes
- name: Install devenv and direnv
become_user: "{{ user_name }}"
block:
- name: Install devenv
shell: nix profile install --accept-flake-config nixpkgs#devenv
- name: Install direnv
yay:
name: direnv
state: present
- name: Update .zshrc for direnv
lineinfile:
path: /home/{{ user_name }}/.zshrc
state: present
line: 'eval "$(direnv hook zsh)"'
- name: Install pyenv
become_user: "{{ user_name }}"
yay:
name: pyenv
state: present
- name: Install Python 3.11 using pyenv
become_user: "{{ user_name }}"
shell: pyenv install 3.11 && pyenv global 3.11
- name: Install Google Cloud CLI
yay:
name: google-cloud-cli
state: present
- name: Install Wakatime
yay:
name: wakatime
state: present
```