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