Skip to content

Instantly share code, notes, and snippets.

@Alistair1231
Last active February 7, 2025 22:31
Show Gist options
  • Save Alistair1231/ab0c7ab9107eaca1c772d61982f92130 to your computer and use it in GitHub Desktop.
Save Alistair1231/ab0c7ab9107eaca1c772d61982f92130 to your computer and use it in GitHub Desktop.
arch linux distrobox with systemd
# URL=git@gist.github.com:ab0c7ab9107eaca1c772d61982f92130.git \
URL=https://gist.github.com/ab0c7ab9107eaca1c772d61982f92130.git \
git clone $URL ~/arch-distrobox
cd ~/arch-distrobox
docker build --build-arg USERNAME=$(whoami) -t arch .
distrobox create --verbose --image arch --name arch --init
distrobox enter arch
FROM archlinux:latest
ARG USER
# make sure pacman works, also install basic packages: sudo, dbus, systemd
RUN curl -s "https://archlinux.org/mirrorlist/?country=DE&country=AT&country=CH&protocol=https&use_mirror_status=on&sort=rate" | sed -e 's/^#Server/Server/' -e '/^#/d' | tee /etc/pacman.d/mirrorlist && \
curl -L https://pkgbuild.com/~morganamilo/pacman-static/x86_64/bin/pacman-static -o /tmp/pacman-static && chmod +x /tmp/pacman-static && pacman-key --init && pacman-key --populate archlinux && \
/tmp/pacman-static -Sy archlinux-keyring pacman-contrib sudo dbus systemd --noconfirm && \
curl -s "https://archlinux.org/mirrorlist/?country=DE&country=AT&country=CH&protocol=https&use_mirror_status=on" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 5 - | tee /etc/pacman.d/mirrorlist && \
pacman -Syu --noconfirm
# set up a fallback user with sudo rights (using ids 10000 instead of 1000 to not interfere with distrobox which adds the current user as 1000)
RUN groupadd -g 10000 user && \
useradd -u 10000 -g 10000 -m -G wheel -s /bin/bash user && \
echo "$USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers && \
echo "user ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
USER user
#! add chaotic-aur so you don't usually need to build stuff from the AUR yourself
# get current guide from github to ensure we have the right keys
RUN curl -L 'https://github.com/chaotic-aur/.github/raw/refs/heads/main/profile/README.md' -o /tmp/chaotic_README.md && \
# keys and mirrorlist
cat /tmp/chaotic_README.md | grep -Po '(?<= - `# )pacm.*(?=`)' | tee /tmp/chaotic.sh && \
# run pacman stuff as sudo and add noconfirm
sed -i -E \
-e 's/^(pacman-key --recv-key )/sudo \1/' \
-e 's/^(pacman-key --lsign-key )/sudo \1/' \
-e 's/^(pacman -U )/sudo \1/' \
-e 's/^(sudo pacman -U )/& --noconfirm /' \
/tmp/chaotic.sh && \
sudo bash /tmp/chaotic.sh && \
# Append to repo to pacman.conf
cat /tmp/chaotic_README.md | grep -Pzo '(?<= - `)[\[I].*(?=`)' | tr '\0' '\n' | sudo tee -a /etc/pacman.conf && \
# install yay and paru from chaotic-aur directly
sudo pacman -Syu --noconfirm paru yay
# fix `tls: failed to verify certificate: x509: certificate signed by unknown authority` in curl and yay (required as of 2024-02-07)
RUN sudo mkdir -p /usr/lib/ssl && \
sudo ln -s /etc/ssl/certs/ca-certificates.crt /usr/lib/ssl/cert.pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment