Skip to content

Commit

Permalink
mkosi: Initial files for dev-arch
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
  • Loading branch information
nathanchance committed Dec 20, 2024
1 parent e52adb5 commit 3f64e10
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 0 deletions.
149 changes: 149 additions & 0 deletions mkosi/dev-arch/mkosi.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
[Build]
WithNetwork=true

[Content]
Bootable=false
Packages=
# base/misc packages
base-devel
systemd-sysvcompat
tzdata

# Nicer versions of certain GNU utilities
bat
bat-extras
diskus
eza
fd
ripgrep

# b4
b4
git-filter-repo
patatt
python-dkim

# compression/decompression/extraction
bzip2
gzip
lzop
lz4
pbzip2
pigz
unzip
zip
zstd

# development
ccache
diffutils
hyperfine
lib32-glibc
python
python-setuptools
python-yaml
ruff
shfmt
yapf

# email
lei
mutt

# env
curl
fastfetch
fish
fzf
jq
less
moreutils
openssh
stow
tmuxp
vim
vim-spell-en
wget
zoxide

# frame-larger-than.py
python-pyelftools

# git
git
git-delta
github-cli
perl-authen-sasl
perl-mime-tools
perl-net-smtp-ssl
repo

# kernel / tuxmake
aarch64-linux-gnu-binutils
bc
bison
cpio
flex
libelf
inetutils
mkinitcpio
ncurses
openssl
pahole
riscv64-linux-gnu-binutils
rsync
socat
sparse
time
uboot-tools

# kup
perl-config-simple

# LLVM/clang + build-llvm.py
clang
cmake
lld
llvm
ninja
perf

# man pages
man-db

# package building
devtools
dpkg
pacman-contrib
rpm-tools

# spdxcheck.py
python-gitpython
python-ply

# system administration
ipmitool
reflector

# QEMU
edk2-aarch64
edk2-ovmf
libevent
libutempter
lsof
qemu-emulators-full
qemu-guest-agent
qemu-img
virtiofsd

# website management
hugo
iproute2

[Distribution]
Distribution=arch

[Output]
Format=directory
ImageId=dev-arch
OutputDirectory=/var/lib/machines
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env fish

for char in e f
echo '#!/bin/sh
exec grep -'(string upper $char)' "$@"' >/usr/local/bin/"$char"grep
end

chmod 755 /usr/local/bin/*grep
43 changes: 43 additions & 0 deletions mkosi/dev-arch/mkosi.postinst.d/00-conf.fish.chroot
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env fish

for conf in makepkg pacman
set old /etc/$conf.conf
set pacnew /etc/$conf.conf.pacnew
set new /etc/$conf.conf.new

if test -f $pacnew
mv -v $pacnew $new
else
cp -v $old $new
end

switch $conf
case makepkg
sed -i 's/^#MAKEFLAGS="-j2"/MAKEFLAGS="-j$(nproc)"/g' $new
sed -i 's/^!ccache/ccache/g' $new

case pacman
sed -i 's/^CheckSpace/#CheckSpace/g' $new
sed -i 's/^#VerbosePkgLists/VerbosePkgLists/g' $new
sed -i 's/^#Color/Color/g' $new
sed -i 's/^NoProgressBar/#NoProgressBar/g' $new
sed -i 's/^#ParallelDownloads = 5/ParallelDownloads = 7/g' $new
sed -i "/\[core-testing\]/,/Include/"'s/^#//' $new
sed -i "/\[extra-testing\]/,/Include/"'s/^#//' $new

echo '
[nathan]
SigLevel = Optional TrustAll
Server = https://raw.githubusercontent.com/nathanchance/arch-repo/main/$arch' >>$new
end

if command -q git
git diff --no-index $old $new
else
diff -Naur $old $new
end

mv -v $new $old
end

echo 'permit nopass nathan as root' >/etc/doas.conf
4 changes: 4 additions & 0 deletions mkosi/dev-arch/mkosi.postinst.d/00-locale-gen.fish.chroot
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env fish

sed -i 's/^#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
locale-gen
54 changes: 54 additions & 0 deletions mkosi/dev-arch/mkosi.postinst.d/01-install-packages.fish.chroot
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env fish

function downgrade_pkg
set pkg $argv[1]
set ver $argv[2]

set tarball /tmp/$pkg-$ver-x86_64.pkg.tar.zst
set url https://archive.archlinux.org/packages/(string split -f 1 '' $pkg)/$pkg/(basename $tarball)

curl -LSso $tarball $url
and pacman -U --noconfirm $tarball
and rm -fr $tarball
end


reflector \
--country "United States" \
--latest 15 \
--protocol https \
--save /etc/pacman.d/mirrorlist \
--sort rate

and cat /etc/pacman.d/mirrorlist

and pacman-key --init
and pacman-key --populate

# This should not be necessary but testing is broken right now
# Uninstall it before updating then install it after
and pacman -R --noconfirm qemu-emulators-full (pactree -u qemu-emulators-full | string match -gr '(qemu-(?:system|user)-?.*)=')

# Temporarily disable the pacman sandbox
and sed -i 's/^DownloadUser/#DownloadUser/g' /etc/pacman.conf

and pacman -Syyuu --noconfirm

and pacman -S --noconfirm qemu-emulators-full

# Switch to doas from sudo non-interatively
and pacman -S --ask 4 --noconfirm opendoas-sudo

and pacman -S --noconfirm \
arm-linux-gnueabi-binutils \
cvise \
debhelper \
mips-linux-gnu-binutils \
powerpc64-linux-gnu-binutils \
s390x-linux-gnu-binutils \
shellcheck-bin \
tio \
tuxmake

# Turn the pacman sandbox back on
and sed -i 's/^#DownloadUser/DownloadUser/g' /etc/pacman.conf
26 changes: 26 additions & 0 deletions mkosi/dev-arch/mkosi.postinst.d/02-add-hetzner-mirror.py.chroot
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3

from os import environ as env
from pathlib import Path
import sys

EXPECTED_MOUNTS = (
((PYTHON_FOLDER := Path(env['SRCDIR'], 'python')), 'PYTHON_FOLDER'),
((ETC := Path(env['SRCDIR'], 'etc')), '/etc'),
)
for expected_path, host_value in EXPECTED_MOUNTS:
if not expected_path.exists():
raise RuntimeError(f"{host_value} not passed into build environment?")

sys.path.append(str(PYTHON_FOLDER))
from setup.arch import HETZNER_MIRROR, add_hetzner_mirror_to_repos # noqa: E402

if not (host_pacman_conf := Path(ETC, 'pacman.conf')).exists():
sys.exit(0) # host is not Arch, cannot be Hetzner

if HETZNER_MIRROR not in host_pacman_conf.read_text(encoding='utf-8'):
sys.exit(0) # host is Arch but still not Hetzner

guest_pacman_conf = Path('/etc/pacman.conf')
guest_pacman_conf_txt = add_hetzner_mirror_to_repos(guest_pacman_conf.read_text(encoding='utf-8'))
guest_pacman_conf.write_text(guest_pacman_conf_txt, encoding='utf-8')

0 comments on commit 3f64e10

Please sign in to comment.