dotfiles/Arch.org
SqrtMinusOne 2975f43344
Some checks failed
Update Site / trigger_update (push) Has been cancelled
desktop: add zotero
2025-12-02 12:23:47 +03:00

283 lines
8.8 KiB
Org Mode

#+TITLE: Arch Linux
#+PROPERTY: header-args :mkdirp yes
I've decided to switch to [[https://archlinux.org/][Arch Linux]] and configure it declaratively with [[https://github.com/ripytide/metapac][metapac]].
* System installation
** Installation
On installation, see https://wiki.archlinux.org/title/Installation_guide and/or use =archinstall=.
** After installation
Update everything:
#+begin_src bash
sudo pacman -Syyu
#+end_src
Install git, python and yadm:
#+begin_src bash
sudo pacman -Syu python git pacman-contrib yadm
#+end_src
Select top-6 fastest mirrors to work with. Generate a mirrorlist file using this service: https://archlinux.org/mirrorlist/, then use =rankmirrors= from =pacman-contrib= (see [[https://wiki.archlinux.org/title/Mirrors][Mirrors]] on Arch Wiki).
#+begin_src bash
sudo -i
cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
rankmirrors -n 6 /etc/pacman.d/mirrorlist.backup > /etc/pacman.d/mirrorlist
#+end_src
If there isn't enough RAM (e.g. running in a VM), turn off mounting =/tmp= as [[https://wiki.archlinux.org/title/Tmpfs#Disable_automatic_mount][tmpfs]]:
#+begin_src basd
sudo systemctl mask tmp.mount
#+end_src
Install [[https://github.com/Morganamilo/paru][paru]]:
#+begin_src bash
sudo pacman -S --needed base-devel
git clone https://aur.archlinux.org/paru.git
cd paru
makepkg -si
#+end_src
Install [[https://github.com/ripytide/metapac][metapac]]:
#+begin_src bash
paru -Syyu metapac
#+end_src
Then install Arch packages with =metapac=:
#+begin_src bash
mkdir ~/00-Scratch/
git clone https://github.com/SqrtMinusOne/dotfiles.git ~/00-Scratch/dotfiles/
cp -r ~/00-Scratch/dotfiles/.config/metapac ~/.config/
metapac s
#+end_src
Then, install the ssh and gpg keys (put them into the =~/.ssh= folder). To export gpg keys:
#+begin_src bash
gpg --output private.pgp --armor --export-secret-keys <keyname>
#+end_src
And to import:
#+begin_src bash
gpg --import private.pgp
gpg --edit-key <keyname>
trust
#+end_src
Also the following to =~/.ssh/config=:
#+begin_src conf-space
Host *
AddKeysToAgent yes
#+end_src
And run:
#+begin_src bash
systemctl enable --user --now ssh-agent
#+end_src
It looks like it is necessary to run at least once.
Then, clone the dotfiles repo with =yadm=:
#+begin_src bash
yadm clone git@github.com:SqrtMinusOne/dotfiles.git
#+end_src
Checkout the changed files.
Clone org-mode and passwords repos:
#+begin_src bash
git clone ssh://git@git.sqrtminusone.xyz:222/sqrtminusone/org-mode.git "/home/pavel/30-39 Life/32 org-mode"
git clone ssh://git@git.sqrtminusone.xyz:222/sqrtminusone/passwords.git "/home/pavel/.password-store"
#+end_src
And don't forget to configure git:
#+begin_src bash
git config --global user.email "thexcloud@gmail.com"
git config --global user.name "SqrtMinusOne"
#+end_src
#+begin_src bash
sudo systemctl enable --now NetworkManager
#+end_src
Install wakatime:
#+begin_src bash
cd ~/00-Scratch/
git clone https://github.com/wakatime/wakatime-cli.git
cd ./wakatime-cli
go build
mv wakatime-cli ~/bin
#+end_src
And create the =~/.wakatime.cfg= file with the following contents:
#+begin_src
[settings]
api_key = <api-key>
#+end_src
Then run =emacs= and make sure it starts. Run:
- =M-x nerd-icons-install-fonts=
- =M-x all-the-icons-install-fonts=
- =M-x treesit-install-language-grammar=
Run =rclone config=, configure the remotes. Then =M-x my/index-commands-sync=.
If everything works, login into EXWM.
Create some directories:
#+begin_src bash
mkdir -p /home/pavel/Pictures/screenshots/
mkdir -p /home/pavel/.mpd/playlists/
#+end_src
Also run:
#+begin_src bash
sudo chmod +s /usr/bin/light
#+end_src
For I've decided to use =NetworkManager=, but Arch Linux uses =iwd= by default, which causes issues. Disable it by:
#+begin_src bash
sudo systemctl disable --now iwd
sudo systemctl disable --now systemd-networkd
#+end_src
And reboot. After the reboot, =NetworkManager= should run using =wpa_supplicant= as backend for Wi-Fi.
Don't forget to sync mail and enable the sync timer.
Install [[https://github.com/retorquere/zotero-better-bibtex][zotero-better-bibtex]] manually.
* Metapac configuration
[[https://github.com/ripytide/metapac][metapac]] is a declarative wrapper around different package managers, including [[https://wiki.archlinux.org/title/Pacman][pacman]] and [[https://github.com/Morganamilo/paru][paru]]. This means the required packages can be listed in configuration files and checked into version control.
I've also tried [[https://github.com/kiviktnm/decman][decman]], but it turned out to be too unstable because it ships its own logic for building AUR packages, which doesn't always work. So wrapping =paru= seems like a saner approach. Also, sometimes AUR drops packets, and =decman= can't handle it gracefully.
In =metapac=, packages are listed in "groups", each group being a TOML file stating which package has to be installed by which package manager. I declare groups as Org tables, see the "System configuration" section in Emacs.org.
Below is the table enabling different groups on different hostnames:
#+NAME: metapac-groups
| Profile | archlinux | weiss | violet |
| browsers | + | + | + |
| console | + | + | + |
| desktop | + | + | + |
| desktop-misc | + | + | + |
| desktop-polybar | + | + | + |
| desktop-rofi | + | + | + |
| dev | + | + | + |
| emacs | + | + | + |
| latex | + | + | + |
| mail | + | + | + |
| music | + | + | + |
| nvidia | | | + |
| office | + | + | + |
| system | + | + | + |
| printer | | | + |
And the code to format it as TOML:
#+NAME: metapac-groups-format
#+begin_src emacs-lisp :var groups=metapac-groups
(let* ((hostnames (cdr (nth 0 groups)))
groups-by-hostname)
(cl-loop for row in (cdr groups)
for group = (nth 0 row)
do (cl-loop for i from 0
for sign in (cdr row)
for hostname = (nth i hostnames)
if (not (string-empty-p sign))
do (push group (alist-get hostname groups-by-hostname
nil nil #'equal))))
(cl-loop for (hostname . groups) in groups-by-hostname
concat (format "%s = [%s]\n" hostname
(mapconcat (lambda (g) (format "\"%s\"" g)) groups ","))))
#+end_src
Which is used in the config:
#+begin_src toml :tangle .config/metapac/config.toml :noweb yes
hostname_enabled_backends_enabled = false
enabled_backends = ["arch"]
hostname_groups_enabled = true
[hostname_groups]
<<metapac-groups-format()>>
[arch]
package_manager = "paru"
#+end_src
* System packages
Some necessary Arch packages:
| Arch dependency |
|---------------------|
| amneziavpn-bin |
| base |
| base-devel |
| decman |
| grub |
| iwd |
| lightdm |
| lightdm-gtk-greeter |
| linux |
| linux-firmware |
| inetutils |
| nano |
| networkmanager |
| metapac |
| openssh |
| pacman-contrib |
| paru |
| pipewire |
| pipewire-audio |
| pipewire-alsa |
| pipewire-pulse |
| pipewire-jack |
| sof-firmware |
| smartmontools |
| vim |
| xterm |
| wget |
| wireless_tools |
| wireplumber |
| yadm |
| zram-generator |
Various drivers, I'm not sure which I actually need, so...
| Arch dependency |
|--------------------|
| libva-intel-driver |
| intel-media-driver |
| vulkan-intel |
| vulkan-radeon |
| xf86-video-amdgpu |
| xf86-video-ati |
NVIDIA drivers & AI stuff for violet
| Category | Arch dependency |
|----------+--------------------------|
| nvidia | cuda |
| nvidia | nvidia-utils |
| nvidia | nvidia |
| nvidia | ollama-cuda |
| nvidia | nvidia-container-toolkit |
Printer packages.
| Category | Arch dependency |
|----------+-----------------|
| printer | cups |
| printer | usbutils |
| printer | brlaser |
| printer | naps2-bin |
| printer | brscan4 |
#+NAME: packages
#+begin_src emacs-lisp :tangle no :var category=""
(my/format-arch-dependencies category)
#+end_src
#+begin_src scheme :tangle .config/metapac/groups/nvidia.toml :noweb yes
<<packages("nvidia")>>
#+end_src
#+begin_src scheme :tangle .config/metapac/groups/printer.toml :noweb yes
<<packages("printer")>>
#+end_src
#+begin_src scheme :tangle .config/metapac/groups/system.toml :noweb yes
<<packages()>>
#+end_src