cmc/cleberg.net

My personal web garden & blog.

clone: git clone https://gitbay.org/cmc/cleberg.net.git

main: content/blog/2022-12-23-alpine-desktop.org · raw

  1#+date:        [2022-12-23 Fri 00:00:00]
  2#+title:       Alpine Desktop with Sway
  3#+description: Setting up Alpine Linux as a desktop with Sway as the window manager.
  4#+slug:        alpine-desktop
  5#+filetags:    :linux:
  6
  7* Isn't Alpine Linux for Servers?
  8
  9This is a question I see a lot when people are presented with an example of
 10Alpine Linux running as a desktop operating system (OS).
 11
 12While Alpine is small, fast, and minimal, that doesn't stop it from functioning
 13at a productive level for desktop users.
 14
 15This post is documentation of how I installed and modified Alpine Linux to
 16become my daily desktop OS.
 17
 18* Installation
 19
 20Note that I cover the installation of Alpine Linux in my other post, so I won't
 21repeat it here: [[https://cleberg.net/blog/alpine-linux.html][Alpine Linux Essentials: Installing and Setting Up a Secure
 22Minimal Server]].
 23
 24Basically, get a bootable USB (Universal Serial Bus) device or whatever you
 25prefer with Alpine on it, boot the optical disc image (ISO), and run the setup
 26script.
 27
 28#+begin_src sh
 29setup-alpine
 30#+end_src
 31
 32Once you have gone through all the options and installer finishes without
 33errors, reboot.
 34
 35#+begin_src sh
 36reboot
 37#+end_src
 38
 39* Initial Setup
 40
 41Once Alpine is installed and the machine has rebooted, login is as root
 42initially or =su= to root once you log in as your user. From here, you should
 43start by updating and upgrading the system in case the ISO was not fully
 44up-to-date.
 45
 46#+begin_src sh
 47# Update and upgrade system
 48apk -U update && apk -U upgrade
 49
 50# Add an editor so we can enable the community repository
 51apk add nano
 52#+end_src
 53
 54You need to uncomment the =community= repository for your version of Alpine
 55Linux.
 56
 57For v3.17, the =repositories= file should look like this:
 58
 59#+begin_src sh
 60nano /etc/apk/repositories
 61#+end_src
 62
 63#+begin_src conf
 64#/media/sda/apks
 65http://mirrors.gigenet.com/alpinelinux/v3.17/main
 66http://mirrors.gigenet.com/alpinelinux/v3.17/community
 67#http://mirrors.gigenet.com/alpinelinux/edge/main
 68#http://mirrors.gigenet.com/alpinelinux/edge/community
 69#http://mirrors.gigenet.com/alpinelinux/edge/testing
 70#+end_src
 71
 72#+begin_src sh
 73# Add the rest of your packages
 74apk add linux-firmware iwd doas git curl wget
 75
 76# Add yourself to the wheel group so you can use the doas command
 77adduser $USER wheel
 78#+end_src
 79
 80* Window Manager (Desktop)
 81
 82The [[https://wiki.alpinelinux.org/wiki/Sway][Sway installation guide]] has everything you need to get Sway working on
 83Alpine.
 84
 85However, I'll include a brief list of the commands I ran and their purpose for
 86posterity here.
 87
 88#+begin_src sh
 89# Add eudev and set it up
 90apk add eudev
 91setup-devd udev
 92
 93# Since I have Radeon graphics, I need the following packages
 94apk add mesa-dri-gallium mesa-va-gallium
 95
 96# Add user to applicable groups
 97adduser $USER input
 98adduser $USER video
 99
100# Add a font package
101apk add ttf-dejavu
102
103# Add the seatd daemon
104apk add seatd
105rc-update add seatd
106rc-service seatd start
107
108# Add user to seat group
109adduser $USER seat
110
111# Add elogind
112apk add elogind polkit-elogind
113rc-update add elogind
114rc-service elogind start
115
116# Finally, add sway and dependencies
117apk add sway sway-doc
118apk add                \ # Install optional dependencies:
119    xwayland             \ # recommended for compatibility reasons
120    foot                 \ # default terminal emulator
121    bemenu               \ # wayland menu
122    swaylock swaylockd   \ # lockscreen tool
123    swaybg               \ # wallpaper daemon
124    swayidle               # idle management (DPMS) daemon
125#+end_src
126
127Once you have the packages installed and set-up, you need to export the
128=XDG_RUNTIME_DIR= upon login. To do this, edit your =.profile= file.
129
130If you use another shell, such as =zsh=, you need to edit that shell's profile
131(e.g., =~/.zprofile=)!
132
133#+begin_src sh
134nano ~/.profile
135#+end_src
136
137Within the file, paste this:
138
139#+begin_src sh
140if test -z "${XDG_RUNTIME_DIR}"; then
141  export XDG_RUNTIME_DIR=/tmp/$(id -u)-runtime-dir
142  if ! test -d "${XDG_RUNTIME_DIR}"; then
143    mkdir "${XDG_RUNTIME_DIR}"
144    chmod 0700 "${XDG_RUNTIME_DIR}"
145  fi
146fi
147#+end_src
148
149Once that's complete, you can launch Sway manually.
150
151#+begin_src sh
152dbus-run-session -- sway
153#+end_src
154
155** Personal Touches
156
157I also added the following packages, per my personal preferences and situation.
158
159#+begin_src sh
160doas apk add brightnessctl   \ # Brightness controller
161             zsh             \ # Shell
162             firefox         \ # Browser
163             syncthing       \ # File sync service
164             wireguard-tools \ # Wireguard VPN
165             gomuks          \ # CLI Matrix client
166             neomutt         \ # CLI email client
167             thunderbird     \ # GUI email client
168             gnupg             # GPG key manager
169#+end_src
170
171From here, I use my Syncthing storage to pull all the configuration files I
172stored from prior desktops, such as my [[https://github.com/ccleberg/dotfiles][dotfiles]].
173
174* Resolving Issues
175
176** WiFi Issues
177
178I initially tried to set up my Wi-Fi the standard way with =iwd=, but it didn't
179work.
180
181Here is what I initially tried (I did all of this as =root=):
182
183#+begin_src sh
184apk add iwd
185rc-service iwd start
186iwctl station wlan0 connect <SSID> # This will prompt for the password
187rc-update add iwd boot && rc-update add dbus boot
188#+end_src
189
190Then, I added the Wi-Fi entry to the bottom of the networking interface file:
191
192#+begin_src sh
193nano /etc/network/interfaces
194#+end_src
195
196#+begin_src conf
197auto wlan0
198iface wlan0 inet dhcp
199#+end_src
200
201Finally, restart the networking service:
202
203#+begin_src sh
204rc-service networking restart
205#+end_src
206
207My Wi-Fi interface would receive an internet protocol (IP) address from the
208router, but it could not ping anything in the network. To solve the Wi-Fi
209issues, I originally upgraded to Alpine's =edge= repositories, which was
210unnecessary.
211
212Really, the solution was to enable the =NameResolvingService=resolvconf= in
213=/etc/iwd/main.conf=.
214
215#+begin_src sh
216doas nano /etc/iwd/main.conf
217#+end_src
218
219#+begin_src conf
220[Network]
221
222NameResolvingService=resolvconf
223#+end_src
224
225Once I finished this process, my Wi-Fi is working flawlessly.
226
227** Sound Issues
228
229Same as with the Wi-Fi, I had no sound and could not control the mute/unmute or
230volume buttons on my laptop.
231
232To resolve this, I installed [[https://wiki.alpinelinux.org/wiki/PipeWire][pipewire]].
233
234#+begin_src sh
235# Add your user to the following groups
236addgroup $USER audio
237addgroup $USER video
238
239# Install pipewire and other useful packages
240apk add pipewire wireplumber pipewire-pulse pipewire-jack pipewire-alsa
241#+end_src
242
243Finally, I needed to add =/usr/libexec/pipewire-launcher= to my
244=.config/sway/config= file so that Pipewire would run every time I launched
245sway.
246
247#+begin_src sh
248nano ~/.config/sway/config
249#+end_src
250
251#+begin_src conf
252# Run pipewire audio server
253exec /usr/libexec/pipewire-launcher
254
255# Example audio button controls
256bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ +5%
257bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume @DEFAULT_SINK@ -5%
258bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute @DEFAULT_SINK@ toggle
259bindsym XF86AudioMicMute exec --no-startup-id pactl set-source-mute @DEFAULT_SOURCE@ toggle
260#+end_src
261
262Note that I do not use bluetooth or screen sharing, so I won't cover those
263options in this post.
264
265Other than these issues, I have a working Alpine desktop. No other complaints
266thus far!