aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-08-16 20:35:54 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-08-16 20:35:54 +0200
commitafec8caa5b74e81e7427cdf1240711429e2d9ed8 (patch)
treedbf2c9f991b27caa09e3019bd40f874a7c2cbcd9
parentde57a12e9a5daadedf649aba4b5c498983ff4347 (diff)
downloadsebastiano.tronto.net-afec8caa5b74e81e7427cdf1240711429e2d9ed8.tar.gz
sebastiano.tronto.net-afec8caa5b74e81e7427cdf1240711429e2d9ed8.zip
New blog post
-rw-r--r--src/blog/2025-08-16-alpine-declarative/alpine-declarative.md106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/blog/2025-08-16-alpine-declarative/alpine-declarative.md b/src/blog/2025-08-16-alpine-declarative/alpine-declarative.md
new file mode 100644
index 0000000..f186ea2
--- /dev/null
+++ b/src/blog/2025-08-16-alpine-declarative/alpine-declarative.md
@@ -0,0 +1,106 @@
1# Declarative package management with Alpine Linux
2
3It has been almost two months since my last update, and it feels a
4bit weird because I have done plenty of tinkering that would be a
5good fit for this blog! But for one reason or another, I did not
6feel like writing about any of this in the usual level of detail.
7
8However, one of the last things I did is quite simple to explain, so here
9is a short post about it.
10
11## Alpine linux
12
13A couple of days ago I decided to try out
14[Alpine Linux](https://www.alpinelinux.org), a lightweight distro that
15uses [musl libc](https://www.musl-libc.org/) instead of GNU libc and
16[busybox](https://busybox.net) instead of GNU coreutils.
17
18Alpine's package manager is called Alpine Package Keeper (APK, not to
19be confused with Android Package, which also goes by APK). It is very
20fast and simple to use, and it has an especially cool feature: the
21list of all manually installed packages is kept in the plain text file
22`/etc/apk/world`. This file can be edited by hand, and running `apk fix`
23will then add or remove packages to satisfy the list in the file. Neat!
24
25## Declarative package management
26
27Unfortunately, APK will also overwrite `/etc/apk/world` by removing
28empty lines and sorting the packages in alphabetical order, one per
29line. Moreover, there is no option to write comments in this file.
30So one cannot really use it as a (commented) list of the packages they
31want to keep installed.
32
33At first I thought I could keep such a list in a separate file, and write
34a script to parse this file, remove the comments, write the result to
35`/etc/apk/world` and then run `apk fix`.
36
37But then I thought it would be even better to merge the two, and here
38is the result:
39
40```
41#!/bin/sh
42
43# Make a backup copy of the previous /etc/apk/world
44cp /etc/apk/world /etc/apk/world.backup
45
46echo "
47
48# Base system packages (installed by default)
49alpine-base busybox-mdev-openrc doas grub-efi openssh openssl
50
51# Firmware (installed by default, system-dependent)
52linux-firmware-i915 linux-firmware-intel linux-firmware-mediatek linux-firmware-other
53linux-firmware-rtl_bt linux-firmware-rtl_nic linux-firmware-xe linux-lts
54
55# Documentation
56docs mandoc-apropos
57
58# Wifi and other hardware control
59iwd openresolv pciutils bluez
60
61# Audio
62pulseaudio pulseaudio-bluez pulseaudio-alsa alsa-plugins-pulse pulseaudio-utils pulsemixer
63
64# Core tools (non-X)
65coreutils-fmt curl imagemagick ffmpeg tmux ghostscript ncurses shellcheck
66kbd # For console keyboard configuration
67syncthing fzf sfeed yt-dlp mblaze msmtp oath-toolkit
68
69# Development tools
70build-base git gdb valgrind clang20 python3 rust cargo hare
71lowdown darkhttpd # Both used for updating my website
72libx11-dev libxft-dev libxinerama-dev
73
74# Xorg xorg-server
75xinit eudev mesa-dri-gallium xf86-video-intel xf86-input-libinput xf86-input-synaptics
76setxkbmap xsel xbanish xsetroot xwallpaper xev slock
77
78# X applications
79firefox libreoffice telegram-desktop vlc imv-x11
80zathura-djvu zathura-pdf-mupdf zathura-ps
81arandr
82
83# Fonts, but like a gazillion of them
84font-terminus font-noto font-noto-extra font-arabic-misc
85font-misc-cyrillic font-mutt-misc font-screen-cyrillic
86font-winitzki-cyrillic font-cronyx-cyrillic font-noto-arabic
87font-noto-armenian font-noto-cherokee font-noto-devanagari
88font-noto-ethiopic font-noto-georgian font-noto-hebrew font-noto-lao
89font-noto-malayalam font-noto-tamil font-noto-thaana font-noto-thai
90
91" | sed 's/#.*//' | grep -v '^[:space:]*$' > /etc/apk/world
92apk fix
93```
94
95The bulk of the file is a
96[here document](https://en.wikipedia.org/wiki/Here_document) with a long
97list of all the packages I want installed - Alpine is really minimal! The
98few lines of code above and below this list are there to make a backup a
99copy of the old `/etc/apk/world`, filter out the comment from the new list
100using [sed](../2023-12-03-sed) and [grep](../2023-08-20-grep),
101copy the new list to `/etc/apk/world` and finally run `apk fix`.
102
103Now when I want to add a new piece of software to my system
104I edit this file and then run it as root. A dead simple
105way to do declarative package management - take that,
106[Nix](https://en.wikipedia.org/wiki/Nix_(package_manager))!

Generated with cgit - Back to sebastiano.tronto.net