dotfiles/org/config/installation.org

30 KiB
Raw Blame History

Arch Linux, Phundrak-flavored

Introduction

Here will be presented what I do to get my system up and running on a fresh Arch Linux install. These installation instructions were written in order to get an Arch Linux distribution up and running with the same configuration as my main computers and my travelling laptops configuration.

Install Arch Linux

I usually install Arch from the vanilla ISO, however I began using archfi to install easily the distro (Ive done it so many times, I know how it works now). Usually, my distros will be installed on two partitions: /home and / (root).

If the computer supports EFI bootloaders, the EFI partition will be mounted on /boot/efi. I generally use systemd-boot as my boot manager, but if you are more comfortable with another one, just install what you want. Be aware that if you format your /boot partition, you will delete all boot managers that already exist; so, if you are dual-booting, DO NOT FORMAT IT. Yes, I made the mistake of wiping the Windows boot manager when I used to dual-boot.

In order to use the suspend-then-hibernate systemd command, it is necessary to have a swap partition at least twice the size of your installed RAM. That is because when this command will be run, the system will try to save the current state of your machine, stored in your RAM, to the swap filesystem. If there is not enough space, the command will fail, and you wont be able to use this command. For instance, my current computer has 32GB of RAM, hence my SWAP partition is 16GB large.

Get the latest, fastest mirrors

When you boot into the live ISO, execute the following command:

  pacman -Sy reflector
  reflector -c FR -c DE -c BE -l 200 -p http -p https --sort rate \
            --save /etc/pacman.d/mirrorlist --verbose

This will update the packages from your live ISO, and you will get the best mirrors for your installation. Of course, change the countries accordingly to your location. In my case, I am only interested in French, German, and Belgian mirrors.

Install the system

Then you can use a custom script to ease your installation of Arch if you do not wish to do it manually. Personally, Ive done it several times already, I know how the distro works, I just want to be able to install my distro quickly now. Ill need to download the script with wget, but apparently it isnt installed by default on Arch ISOs anymore, so Ill need to install it.

  pacman -S wget

Now, lets grab the script. You can check it on Github.

  wget archfi.sf.net/archfi
  # Or from matmoul.github.io/archfi if SourceForge is down
  sh archfi

Then, follow the instructions and install Arch Linux. Take the opportunity to install as many packages as you need, mainly yay which I use as my package manager (it is just a wrapper for pacman) and AUR helper, and pacman-contrib which will help us installing some packages later.

Once your system is installed, reboot and remove your installation media from your computer.

Execute bootstrap

With the installation of Arch with archfi, I will have yay, an AUR helper, installed. This will allow me to have some basic packages installed in order to run the bootstrap described below. So, lets install fish (our shell running the script), git, and my dotfiles manager yadm.

  yay -Sy fish git yadm

yadm comes with a very handy feature: its bootstrap script. It can be executed automatically once the dotfiles are cloned with yadm:

  yadm clone https://labs.phundrak.com/phundrak/dotfiles
  # or if labs.phundrak.com is down or too slow for you
  #yadm clone https://github.com/phundrak/dotfiles

Lets take a look at what it does.

Decrypt private yadm files

Some private files are stored encrypted in the repository of my yadm dotfiles. I will need them later on during the bootstrap execution.

  if test "$USER" = 'phundrak'
      yadm decrypt
  else
      whiptail --yesno "Decrypt private files?" 8 40 && yadm decrypt
  end

Get a correct keyboard layout

I use mainly the bépo layout, a French keyboard layout inspired by Dvorak layouts, however I sometimes need to switch back to the standard French AZERTY or the American QWERTY layout, so I make it so the Menu key switches for me my layout between these three. This makes it so my xorg configuration of my keyboard looks like this:

  set keyboardconf \
  'Section "InputClass"
          Identifier "system-keyboard"
          MatchIsKeyboard "on"
          Option "XkbLayout" "fr"
          Option "XkbModel" "pc104"
          Option "XkbVariant" "bepo_afnor"
          Option "XkbOptions" "caps:ctrl_modifier"
  EndSection'

So, lets ask the user if they want to set it as their keyboard configuration.

  printf "\n# Set keyboard layout #########################################################\n\n"
  whiptail --yesno "Would you like to set your keyboard layout to the bépo layout?" 8 55
  if test $status -eq 0
      echo $keyboardconf | sudo tee /etc/X11/xorg.conf.d/00-keyboard.conf
  end

Set our locale

I use two main locales, the French and US UTF-8 locales, and I like to keep the Japanese locale activated just in case.

  set mylocales "en_US.UTF-8 UTF-8" "fr_FR.UTF-8 UTF-8" "ja_JP.UTF-8 UTF-8"

Ill let the user accept them one by one.

  printf "\n# Set locale ##################################################################\n\n"

  for item in $mylocales
      whiptail --yesno "Set the \"$item\" locale?" 8 40
      if test $status -eq 0 -a (grep -e "#$item" /etc/locale.gen)
          sudo sed -i "/$item/s/^#//g" /etc/locale.gen
      end
  end

This is my configuration I usually use when it comes to my locale.

  set localeconf "LANG=en_US.UTF-8
  LC_COLLATE=C
  LC_NAME=fr_FR.UTF-8
  LC_NUMERIC=fr_FR.UTF-8
  LC_IDENTIFICATION=fr_FR.UTF-8
  LC_TELEPHONE=fr_FR.UTF-8
  LC_MONETARY=fr_FR.UTF-8
  LC_PAPER=fr_FR.UTF-8
  LC_ADDRESS=fr_FR.UTF-8
  LC_TIME=fr_FR.UTF-8
  LC_MEASUREMENT=fr_FR.UTF-8"

Lets set it as our systems locale if the user whishes to.

  whiptail --yesno "Do you agree to have the following locale set?\n\n     $localeconf"  20 43
  if test $status -eq 0
      echo $localeconf | sudo tee /etc/locale.conf
  end

Now we can generate our locale!

  printf "\n# Generate locale #############################################################\n\n"
  sudo locale-gen

Create some folders

Lets create some folders we might need for mounting our drives, Android devices and CDs.

  printf "\n# Create directories for mounting #############################################\n\n"
  sudo mkdir -p /mnt/{USB,CD,Android}
  sudo chown $USER:(id -g $USER) /mnt/{USB,CD,Android}

Set users shell to fish

First of all, the bootstrap shell will set the users shell to fish.

  printf "\n# Set fish as the default shell ###############################################\n\n"
  whiptail --yesno "Set the current users default shell to fish?" 8 50
  if test $status -eq 0 -a ! "$SHELL" = '/usr/bin/fish'
      chsh -s /usr/bin/fish
  end

Install basic packages

Lets set in a custom varible what packages well be needing.

  set PACKAGES \
  acpi acpilight adobe-source-han-sans-jp-fonts arc-gtk-theme asar ascii \
  aspell-en aspell-fr awesome awesome-terminal-fonts awesome-freedesktop-git \
  base-devel bashtop bat biber bitwarden-bin bluez-firmware bluez-utils bzip2 \
  chicken chromium clisp corrupter-git cppcheck cppreference \
  cppreference-devhelp cpupower discord-canary discount docker docker-compose \
  dockerfile-language-server-bin doxygen emacs emacs-org-mode exa exfat-utils \
  farbfeld fd ffmpegthumbnailer findutils firefox flake8 flat-remix-gtk freeglut \
  fzf gcc-libs gdb gimp gnome-disk-utility gnome-epub-thumbnailer gnu-free-fonts \
  gnuplot go go-tools golangci-lint-bin graphviz htop hugo i3lock-color \
  inetutils isync inter-font javascript-typescript-langserver js-beautify \
  jfsutils jmtpfs lain-git libxft-bgra linux-headers lldb logrotate ly meson \
  minted man-db man-pages mpc mpd mpd-rich-presence-discord-git mpv mupdf-tools \
  nano ncdu ncmpcpp nemo-fileroller nemo-preview neofetch netctl \
  network-manager-applet networkmanager networkmanager-openvpn nitrogen \
  nm-connection-editor nodejs-vmd nomacs nordic-theme-git nordvpn-bin \
  noto-fonts-emoji npm ntfs-3g numlockx obs-studio openssh otf-fandol \
  otf-ipafont p7zip pacman-contrib pandoc-bin pass pavucontrol pdfpc \
  picom-ibhagwan-git powerline-fonts prettier pulseaudio-bluetooth \
  python-autoflake python-epc python-importmagic python-language-server \
  python-nose python-pip python-poetry python-ptvsd python-pytest \
  qt5-imageformats qemu r raw-thumbnailer reflector ripgrep rofi rsync rtv \
  ruby-rb-fsevent ruby-sass rustup samba scrot sent shadow siji-git \
  simplescreenrecorder sshfs st-luke-git sxiv texlive-bin texlive-langchinese \
  texlive-langcyrillic texlive-langgreek texlive-langjapanese texlive-langkorean \
  texlive-latexextra texlive-localmanager-git texlive-most tmux tree \
  ttf-arphic-uming ttf-baekmuk ttf-charis-sil ttf-dejavu \
  ttf-google-fonts-opinionated-git ttf-hanazono ttf-joypixels ttf-koruri \
  ttf-liberation ttf-monapo ttf-sazanami ttf-tibetan-machine typescript \
  typescript-language-server-bin unicode-emoji unrar usbutils valgrind \
  vscode-css-languageserver-bin vscode-html-languageserver-bin w3m wget \
  x11-ssh-askpass xclip xdg-user-dirs-gtk xfce-polkit xidlehook xfsprogs \
  xorg-drivers xorg-server xorg-xinit xss-lock xvkbd yaml-language-server-bin \
  zeal

These are the minimum I would have in my own installation. You can edit it however you want. Lets install those.

  printf "\n# Installing needed packages ##################################################\n\n"
  sudo pacman -Syu
  for pkg in $PACKAGES
      yay -S --needed $pkg
  end

Tangle configuration files from Org files

Before tangling our configuration files, we need to create some directories first so our files can be properly tangled. Heres the list of directories we need to create:

$HOME/.config/awesome
$HOME/.config/awesome/theme
$HOME/.config/emacs/private
$HOME/.config/fish
$HOME/.config/gtk-2.0
$HOME/.config/gtk-3.0
$HOME/.config/ncmpcpp
$HOME/.config/neofetch
$HOME/.config/picom
$HOME/.config/yadm
$HOME/.local/bin
$HOME/org/capture
  (mapconcat (lambda (x) (format "mkdir -p %s" (car x)))
             dirs
             "\n")
mkdir -p $HOME/.config/awesome
mkdir -p $HOME/.config/awesome/theme
mkdir -p $HOME/.config/emacs/private
mkdir -p $HOME/.config/fish
mkdir -p $HOME/.config/gtk-2.0
mkdir -p $HOME/.config/gtk-3.0
mkdir -p $HOME/.config/ncmpcpp
mkdir -p $HOME/.config/neofetch
mkdir -p $HOME/.config/picom
mkdir -p $HOME/.config/yadm
mkdir -p $HOME/.local/bin
mkdir -p $HOME/org/capture

Our code to generate such directories looks like this:

  <<gen-dirs-tangle()>>

The next step is to tangle all the Org files. Here is the list of files that are to be tangled:

filename
awesome.org
bin.org
emacs.org
fish.org
index.org
picom.org
rustfmt.org
tmux.org
  (mapconcat (lambda (x) (concat
                          (format "printf '\\n\\n==== Tangling %s\\n\\n' && \\\n" x)
                          (concat "emacs -q --batch --eval '(require \\'ob-tangle)' \\\n"
                                  "--eval '(setq org-confirm-babel-evaluate nil)' \\\n"
                                  (format "--eval '(org-babel-tangle-file \"~/org/config/%s\")'\n" x))))
             files
             "\n")
printf '\n\n==== Tangling awesome.org\n\n' && \
emacs -q --batch --eval '(require \'ob-tangle)' \
--eval '(setq org-confirm-babel-evaluate nil)' \
--eval '(org-babel-tangle-file "~/org/config/awesome.org")'

printf '\n\n==== Tangling bin.org\n\n' && \
emacs -q --batch --eval '(require \'ob-tangle)' \
--eval '(setq org-confirm-babel-evaluate nil)' \
--eval '(org-babel-tangle-file "~/org/config/bin.org")'

printf '\n\n==== Tangling emacs.org\n\n' && \
emacs -q --batch --eval '(require \'ob-tangle)' \
--eval '(setq org-confirm-babel-evaluate nil)' \
--eval '(org-babel-tangle-file "~/org/config/emacs.org")'

printf '\n\n==== Tangling fish.org\n\n' && \
emacs -q --batch --eval '(require \'ob-tangle)' \
--eval '(setq org-confirm-babel-evaluate nil)' \
--eval '(org-babel-tangle-file "~/org/config/fish.org")'

printf '\n\n==== Tangling index.org\n\n' && \
emacs -q --batch --eval '(require \'ob-tangle)' \
--eval '(setq org-confirm-babel-evaluate nil)' \
--eval '(org-babel-tangle-file "~/org/config/index.org")'

printf '\n\n==== Tangling picom.org\n\n' && \
emacs -q --batch --eval '(require \'ob-tangle)' \
--eval '(setq org-confirm-babel-evaluate nil)' \
--eval '(org-babel-tangle-file "~/org/config/picom.org")'

printf '\n\n==== Tangling rustfmt.org\n\n' && \
emacs -q --batch --eval '(require \'ob-tangle)' \
--eval '(setq org-confirm-babel-evaluate nil)' \
--eval '(org-babel-tangle-file "~/org/config/rustfmt.org")'

printf '\n\n==== Tangling tmux.org\n\n' && \
emacs -q --batch --eval '(require \'ob-tangle)' \
--eval '(setq org-confirm-babel-evaluate nil)' \
--eval '(org-babel-tangle-file "~/org/config/tmux.org")'
  printf "\n# Tangling org files ##########################################################\n\n"
  <<generate-tangle()>>

Setting up Emacs: Installing Spacemacs

Now, the first thing we want to do with Emacs is install its Spacemacs distribution. Well clone its develop branch into ~/.config/emacs. We need to do this prior to our dotfiles cloning because of some submodules that are cloned within our ~/.config/emacs directory, and git wont let us clone Spacemacs in an already existing and non-empty directory. To make sure it isnt one, lets delete any potentially existing ~/.config/emacs directory:

  printf "\n# Installing Spacemacs ########################################################\n\n"
  rm -rf $HOME/.config/emacs $HOME/.emacs* .spacemacs

Now we can clone Spacemacs:

  git clone --branch develop https://github.com/syl20bnr/spacemacs ~/.config/emacs

And we can restore what might have been deleted in our ~/.emacs.d/private directory:

  yadm checkout -- ~/.config/emacs/private/

Set up dotfiles git repository

Update our dotfiles remotes

This line in the bootstrap script will test if the current user is using my username. If yes, its probably me.

  if test "$USER" = 'phundrak'

If it is me installing and using these dotfiles, I want the remotes of my dotfiles to be set to ssh remotes using my ssh keys.

  printf "\n# Update yadms remotes #######################################################\n\n"
  yadm remote set-url origin git@labs.phundrak.com:phundrak/dotfiles.git
  yadm remote add github git@github.com:phundrak/dotfiles.git

I will also want to decrypt my encrypted files, such as said ssh keys.

  printf "\n# Decrypt encrypted dotfiles ##################################################\n\n"
  yadm decrypt

Finally, lets close this if statement.

  end

Update our submodules

Now we can download the various dependencies of our dotfiles. To do so, lets run the following command:

  printf "\n# Getting yadm susbmodules ####################################################\n\n"
  yadm submodule update --init --recursive

Enable some services

We have installed some packages which require some services to run. Lets enable them.

Systemd-timesyncd

This service enables time syncing with the NTP protocol, so I can be sure my computers time is correct. The service first needs to be enabled:

  printf "\n# Enabling timesync ###########################################################\n\n"
  sudo systemctl enable --now systemd-timesyncd

Now, let systemd know I want to use the NTP protocol to keep my computers time synced.

  sudo timedatectl set-ntp true

Docker

First, lets activate Docker on startup.

  printf "\n# Enabling and starting Docker ################################################\n\n"
  sudo systemctl enable --now docker

Now, if we wish it, we can be added to the docker group so we wont have to type sudo each time we call Docker or Docker Compose.

  read --prompt "echo 'Do you wish to be added to the `docker` group? (Y/n): ' " -l adddockergroup
  if test $adddockergroup = 'y' || test $adddockergroup = "Y" || test $adddockergroup = ''
      sudo usermod -aG docker $USER
  end

Emacs

Emacs will run as a user service, which means it wont be launched until we log in. However, the service wont be started immediately, I personally prefer to start a standalone instance in which installing and compiling the Emacs packages will happen, and then once that is done I will start the service.

  printf "\n# Enabling Emacs as user service ##############################################\n\n"
  systemctl --user enable emacs

Mpd

Mpd will also use as a user service in order to get rid of some lines of code in my configuration.

  printf "\n# Enabling Mpd as a user service ##############################################\n\n"
  mkdir -p ~/.config/mpd/playlists
  systemctl --user enable --now mpd

SSH server

Maybe we want to activate an SSH server on our machine. If so, we can enable it. Lets ask the question.

  whiptail --yesno 'Do you want to activate the ssh server?' 8 50
  if test $status -eq 0
      printf "\n# Enabling ssh server #########################################################\n\n"
      sudo systemctl enable --now sshd
  end

Ly

Ly is a display manager based on ncurses which I find nice enough for me to use (I generally dont like using display managers). Lets enable it, and lets disable tty2 while were at it (Ly uses it to run X).

  sudo systemctl disable getty@tty2
  sudo systemctl enable --now ly

Acpilight

acpilight is our utility managing the brightness of our screen. There is actually no service to enable here, but we must ensure the user is part of the video group so we can modify the brightness of our screen without using sudo.

  sudo usermod -aG video $USER

NordVPN

Thanks to the AUR package nordvpn-bin, I no longer have to manually maintain my VPN connections with OpenVPN. However, it requires a service that we should activate:

  sudo systemctl enable --now nordvpnd

Lets also set its default protocol to UDP. This will allow me to use any port while connected to any WiFi as long as the 443 port is available. Because yes, I do connect to a WiFi that blocks some important ports, such as the IMAP and SMTP ports. Thanks University of Paris 8 for being SO paranoid.

  nordvpn s protocol tcp

Install packages from git

Now, lets install some packages from git directly.

  mkdir -p ~/fromGIT

Reveal.JS

I sometimes use Reveal.JS to make presentations, and I set its location in my dotspacemacs file to be in ~/fromGIT, so lets clone it there.

  printf "\n# Install Reveal.JS ###########################################################\n\n"
  cd ~/fromGIT
  git clone https://github.com/hakimel/reveal.js.git

Install Rust

Install the toolchains

When using Rust, I bounce between two toolchains, the stable toolchain and the nightly toolchain, although I try to stick with Rust Stable. To install them, I will use rustup which has already been installed previously.

  printf "\n# Install the rust toolchains, nightly is the default one #####################\n\n"
  rustup default stable

This will both download the stable toolchain and set it as the default one. Now to install the nightly toolchain, lets run this:

  rustup toolchain install nightly

Install some utilities

Well need some utilities when developing Rust from Emacs, namely rustfmt and racer. Lets install them with cargo.

  printf "\n# Add rust utilities ##########################################################\n\n"
  cargo install rustfmt racer

We will also need some components for development purposes.

Component Why
rust-src Rust documentation in Emacs
rls LSP backend for Emacs
clippy A better version of cargos check command
  (mapconcat (lambda (x) (format "rustup component add %s" x))
             components
             "\n")
rustup component add rust-src
rustup component add rls
rustup component add clippy

Here is the code to do so:

  <<rust-components-gen()>>

Install some python packages

Some packages will be needed from pip in order to get our Emacs setup correctly working.

Package Why
python-language-server[all] Python LSP packages
pyls-isort Import sortings for LSP
pyls-mypy Mypy linter for LSP
pyls-black Black plugin for pyls
  (format "pip install --user %s"
          (s-join " " packages))
pip install --user python-language-server[all] pyls-isort pyls-mypy pyls-black

Lets install them locally for our user.

  printf "\n# Installing Python packages ##################################################\n\n"
  <<python-packages-gen()>>

Set up Chicken (Scheme interpreter/compiler)

Chicken needs to be set up before being used. First, we need to install its documentation.

  printf "\n# Setting up Chicken ##########################################################\n\n"
  chicken-install -s apropos chicken-doc

Then, well complete the documentation like so:

  cd (chicken-csi -b -e "(import (chicken platform))" -p "(chicken-home)")
  curl https://3e8.org/pub/chicken-doc/chicken-doc-repo.tgz | sudo tar zx

Set up our fish shell

The last thing we want to do is to set up our fish shell with some extensions in order to improve the user experience.

Install fisher

We will be using fisher as our extensions manager for Fish. Lets install it.

  printf "\n# Installing fisher ###########################################################\n\n"
  curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish

Install our extensions

I generally use the following extensions in my Fish shell.

Package name Description
decors/fish-colored-man Color man pages to make them more readable
franciscolourenco/done Automatically receive notifications when a long process finishes
jethrokuan/fzf Improved key bindings for junegunn/fzf
jethrokuan/z Pure-fish rupa/z-like directory jumping
jorgebucaran/fish-bax Run bash scripts, replaying environment changes in fish
jorgebucaran/fish-getopts CLI options parser; alternative to the argparse fish builtin
laughedelic/pisces Autoclose parentheses, braces, quotes and other paired symbols
oh-my-fish/theme-bobthefish A Powerline-style, Git-aware fish theme optimized for awesome.
Fish extensions managed by Fisher
  (mapconcat (lambda (x) (format "fisher add %s" x))
             extensions
             "\n")
fisher add decors/fish-colored-man
fisher add franciscolourenco/done
fisher add jethrokuan/fzf
fisher add jethrokuan/z
fisher add jorgebucaran/fish-bax
fisher add jorgebucaran/fish-getopts
fisher add laughedelic/pisces
fisher add oh-my-fish/theme-bobthefish
  printf "\n# Installing Fisher Extensions ################################################\n\n"
  <<fish-extensions-gen()>>