Add optional Doom Emacs layer

This commit is contained in:
joe committed 2026-06-16 17:46:43 -04:00
1 parent 42bc94d831
commit fb2112c141
10 files changed
+342 -8

No files matched your search

+9 -2
View File
@@ -8,10 +8,12 @@ export DBUS_VERSION ?= 1.16.2
export PAM_VERSION ?= 1.7.2
export DESKTOP ?= console
export ENABLE_DESKTOP ?= 0
export ENABLE_DOOM_EMACS ?= 0
export ROOT_LABEL ?= FORGE_ROOT
export EFI_LABEL ?= FORGE_EFI
desktop_enabled := $(filter 1 true TRUE yes YES on ON,$(ENABLE_DESKTOP))
export IMAGE_SIZE_MIB ?= $(if $(filter gnome,$(DESKTOP)),12288,$(if $(desktop_enabled),4096,2048))
doom_emacs_enabled := $(filter 1 true TRUE yes YES on ON,$(ENABLE_DOOM_EMACS))
export IMAGE_SIZE_MIB ?= $(if $(filter gnome,$(DESKTOP)),12288,$(if $(or $(desktop_enabled),$(doom_emacs_enabled)),4096,2048))
export ESP_SIZE_MIB ?= 256
export JOBS ?= $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
export SECURE_BOOT ?= 0
@@ -20,7 +22,7 @@ export SECURE_BOOT_CERT ?=
export GNOME_SUITE ?= trixie
export GNOME_MIRROR ?= http://deb.debian.org/debian
.PHONY: help deps image-deps fetch kernel busybox pam systemd dbus rootfs gnome-rootfs image gnome-image secure-boot-keys run run-image run-desktop run-gnome list-disks install clean distclean
.PHONY: help deps image-deps fetch kernel busybox pam systemd dbus rootfs doom-emacs gnome-rootfs image gnome-image secure-boot-keys run run-image run-desktop run-gnome list-disks install clean distclean
help:
@printf '%s\n' \
@@ -35,6 +37,8 @@ help:
' make dbus - build the D-Bus system bus daemon' \
' make rootfs - assemble the systemd rootfs and initramfs' \
' ENABLE_DESKTOP=1 make rootfs - add Openbox/tint2/PCManFM desktop' \
' ENABLE_DOOM_EMACS=1 make rootfs - add Emacs + Doom Emacs tooling' \
' make doom-emacs - rebuild rootfs with the Doom Emacs layer enabled' \
' make gnome-rootfs - assemble a Debian GNOME desktop rootfs' \
' make image - build a bootable GPT/UEFI disk image' \
' make gnome-image - build a bootable GPT/UEFI GNOME disk image' \
@@ -75,6 +79,9 @@ dbus: fetch
rootfs:
@./scripts/build-rootfs.sh
doom-emacs: ENABLE_DOOM_EMACS = 1
doom-emacs: rootfs
gnome-rootfs: DESKTOP = gnome
gnome-rootfs: IMAGE_SIZE_MIB = 12288
gnome-rootfs:
+13
View File
@@ -13,6 +13,7 @@ As of `2026-06-16`, the project defaults to:
- 64-bit only
- UEFI boot
- text console only
- optional Doom Emacs tool layer for the normal rootfs
- optional GNOME desktop image using Debian `trixie` packages
## What This Repository Produces
@@ -63,6 +64,16 @@ ENABLE_DESKTOP=1 make run-desktop
This keeps the regular ForgeOS rootfs path and stages Openbox, tint2, PCManFM, Xorg, fonts, icons, and a terminal into it. The serial login prompt remains on `ttyS0`; `tty1` starts the desktop session.
To add Doom Emacs without switching OS flavors:
```bash
cd /home/joe/forgeos
ENABLE_DOOM_EMACS=1 make image
ENABLE_DOOM_EMACS=1 make run-image
```
This keeps the normal ForgeOS rootfs path and stages Emacs, Git, ripgrep, GNU find, fd, CA certificates, and the Doom Emacs Git checkout. On first shell login, ForgeOS seeds the user's `~/.config/emacs` and `~/.config/doom` from the staged Doom checkout and adds the Doom `bin` directory to `PATH`. Log in as `forge`, then run `doom sync` to fetch and compile the per-user Doom package set, followed by `doom doctor` if you want a dependency check.
To build a GNOME desktop image, install `mmdebstrap` on the host and use the GNOME targets:
```bash
@@ -101,6 +112,7 @@ sudo make install DISK=/dev/nvme0n1
- `systemd-logind` is included in the source-built systemd layer, owns `org.freedesktop.login1` on the system bus, and provides `loginctl` plus the logind varlink socket. `pam_systemd.so` registers console logins as logind sessions.
- DHCP networking is handled by `systemd-networkd`; DNS is handled by `systemd-resolved`, with `/etc/resolv.conf` linked to `/run/systemd/resolve/resolv.conf`.
- `ENABLE_DESKTOP=1` adds an Openbox/tint2/PCManFM desktop layer to the normal ForgeOS rootfs by extracting a minimal Debian package payload while preserving the source-built systemd and D-Bus daemons.
- `ENABLE_DOOM_EMACS=1` adds a Doom Emacs layer to the normal ForgeOS rootfs by extracting the needed Debian runtime packages and staging the upstream Doom Emacs Git checkout under `/usr/share/doom-emacs`.
- `DESKTOP=gnome` switches rootfs assembly to a Debian package bootstrap because GNOME depends on a large desktop stack that ForgeOS does not source-build yet.
Set `BOOTLOADER=stub` when building an image to use the direct kernel EFI-stub fallback path instead of GRUB.
@@ -140,6 +152,7 @@ Linux-PAM, systemd, and D-Bus are built with Meson/Ninja and staged dynamically.
- There is no package manager yet.
- Account management is limited to the built-in `forge` and `root` accounts.
- The Openbox desktop layer is a staged runtime payload, not an in-OS package manager.
- The Doom Emacs layer stages the framework and runtime tools, but the per-user Doom package cache is initialized with `doom sync` after first login.
- GNOME support is currently a package-bootstrapped desktop flavor, not a source-built ForgeOS desktop stack.
- The installer is host-side only; there is no in-OS guided installer yet.
+2 -2
View File
@@ -1,8 +1,8 @@
# CONFIG_STATIC is not set
CONFIG_PAM=y
CONFIG_FEATURE_INSTALLER=y
CONFIG_FEATURE_SH_STANDALONE=y
CONFIG_FEATURE_PREFER_APPLETS=y
# CONFIG_FEATURE_SH_STANDALONE is not set
# CONFIG_FEATURE_PREFER_APPLETS is not set
CONFIG_SH_IS_ASH=y
CONFIG_ASH=y
CONFIG_ASH_OPTIMIZE_FOR_SIZE=y
+6
View File
@@ -9,12 +9,15 @@ ForgeOS defaults to a CLI-only operating system for `x86_64` desktops and laptop
- D-Bus for the system message bus
- Linux-PAM for local login authentication and session hooks
- BusyBox for `/bin/sh`, early switch-root support, and compact rescue tools
- optional Doom Emacs tooling for an editor-focused user environment
- custom units and configuration files from this repository
There is also an optional `DESKTOP=gnome` image flavor. That flavor keeps the ForgeOS kernel, GRUB/EFI boot flow, image builder, and kernel modules, but uses a Debian `trixie` GNOME userspace because GNOME's dependency closure is much larger than the current source-built ForgeOS userspace.
The normal ForgeOS rootfs can also be built with `ENABLE_DESKTOP=1`. That does not switch to a new OS flavor: it keeps the source-built ForgeOS userspace and stages an Openbox/tint2/PCManFM desktop layer into the same rootfs.
The normal rootfs can also be built with `ENABLE_DOOM_EMACS=1`. That keeps the same ForgeOS userspace and stages a Doom Emacs tool layer into it rather than switching to a distro flavor.
## Boot Model
ForgeOS currently targets UEFI systems.
@@ -47,6 +50,8 @@ For `DESKTOP=gnome`, `scripts/build-gnome-rootfs.sh` uses `mmdebstrap` or root-r
For `ENABLE_DESKTOP=1`, `scripts/stage-openbox-desktop.sh` asks apt to download the Openbox desktop package closure, extracts only the runtime payloads into `staging/rootfs`, skips base daemon packages that would replace source-built systemd or D-Bus, and enables `forgeos-desktop.service` on `tty1`.
For `ENABLE_DOOM_EMACS=1`, `scripts/stage-doom-emacs.sh` stages Emacs, Git, ripgrep, GNU find, fd, CA certificates, and the upstream Doom Emacs Git checkout. The Doom checkout is stored globally at `/usr/share/doom-emacs`; `/etc/profile.d/doom-emacs.sh` seeds `~/.config/emacs` and `~/.config/doom` for each writable user home on first shell login. The per-user Doom package cache is intentionally not baked into the image; users initialize it with `doom sync` inside the running OS.
## Why EFI Stub Boot
The project can still boot the kernel EFI stub directly with `BOOTLOADER=stub`, which keeps the implementation smaller and more direct:
@@ -87,6 +92,7 @@ This is enough for a first CLI OS image and a development boot path, but not yet
- measured boot and full verified boot
- full laptop Wi-Fi and firmware coverage
- package management
- pre-synced per-user Doom Emacs package caches
- source-built GNOME and graphical desktop dependency closure
- source-built Openbox/Xorg/GTK graphical dependency closure
- source-built dependency closure for systemd and D-Bus runtime libraries
+8 -1
View File
@@ -1,4 +1,4 @@
PATH=/bin:/sbin:/usr/bin:/usr/sbin
PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin
export PATH
PS1='[forgeos \w]# '
@@ -7,3 +7,10 @@ export PS1
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
if [ -d /etc/profile.d ]; then
for profile_script in /etc/profile.d/*.sh; do
[ -r "$profile_script" ] && . "$profile_script"
done
unset profile_script
fi
+7
View File
@@ -16,6 +16,10 @@ GNOME_USER_PASSWORD=${GNOME_USER_PASSWORD:-forge}
GNOME_AUTOLOGIN=${GNOME_AUTOLOGIN:-1}
GNOME_PACKAGES=${GNOME_PACKAGES:-systemd-sysv dbus dbus-user-session gnome-core gdm3 network-manager sudo locales xserver-xorg xserver-xorg-video-all xserver-xorg-input-libinput mesa-utils fonts-dejavu firmware-linux-free}
if truthy "$ENABLE_DOOM_EMACS"; then
GNOME_PACKAGES="$GNOME_PACKAGES $DOOM_EMACS_PACKAGES"
fi
normalize_packages_csv() {
local package_csv
@@ -273,6 +277,9 @@ msg "configuring ForgeOS GNOME defaults"
configure_identity
configure_user
configure_desktop_services
if truthy "$ENABLE_DOOM_EMACS"; then
"$ROOT_DIR/scripts/stage-doom-emacs.sh"
fi
mkdir -p "$ROOTFS_STAGING_DIR/lib" "$ROOTFS_STAGING_DIR/boot"
rsync -a "$MODULES_STAGING_DIR/lib/" "$ROOTFS_STAGING_DIR/lib/"
+4
View File
@@ -146,6 +146,10 @@ if truthy "$ENABLE_DESKTOP"; then
"$ROOT_DIR/scripts/stage-openbox-desktop.sh"
fi
if truthy "$ENABLE_DOOM_EMACS"; then
"$ROOT_DIR/scripts/stage-doom-emacs.sh"
fi
chmod 755 \
"$ROOTFS_STAGING_DIR/init" \
"$ROOTFS_STAGING_DIR/sbin/forgeos-bootdiag" \
+9 -1
View File
@@ -18,6 +18,7 @@ DBUS_VERSION=${DBUS_VERSION:-1.16.2}
PAM_VERSION=${PAM_VERSION:-1.7.2}
DESKTOP=${DESKTOP:-console}
ENABLE_DESKTOP=${ENABLE_DESKTOP:-0}
ENABLE_DOOM_EMACS=${ENABLE_DOOM_EMACS:-0}
ROOT_LABEL=${ROOT_LABEL:-FORGE_ROOT}
EFI_LABEL=${EFI_LABEL:-FORGE_EFI}
case "$DESKTOP" in
@@ -30,7 +31,7 @@ esac
if [[ -z "${IMAGE_SIZE_MIB:-}" ]]; then
if [[ "$DESKTOP" == "gnome" ]]; then
IMAGE_SIZE_MIB=12288
elif [[ "$ENABLE_DESKTOP" =~ ^(1|true|TRUE|yes|YES|on|ON)$ ]]; then
elif [[ "$ENABLE_DESKTOP" =~ ^(1|true|TRUE|yes|YES|on|ON)$ || "$ENABLE_DOOM_EMACS" =~ ^(1|true|TRUE|yes|YES|on|ON)$ ]]; then
IMAGE_SIZE_MIB=4096
else
IMAGE_SIZE_MIB=2048
@@ -60,8 +61,12 @@ PAM_TARBALL="linux-pam-${PAM_VERSION}.tar.gz"
PAM_URL="https://github.com/linux-pam/linux-pam/archive/refs/tags/v${PAM_VERSION}.tar.gz"
GNOME_SUITE=${GNOME_SUITE:-trixie}
GNOME_MIRROR=${GNOME_MIRROR:-http://deb.debian.org/debian}
DOOM_EMACS_GIT_URL=${DOOM_EMACS_GIT_URL:-https://github.com/doomemacs/doomemacs.git}
DOOM_EMACS_REF=${DOOM_EMACS_REF:-master}
DOOM_EMACS_PACKAGES=${DOOM_EMACS_PACKAGES:-emacs-nox git ripgrep fd-find findutils ca-certificates}
OPENBOX_DESKTOP_PACKAGES=${OPENBOX_DESKTOP_PACKAGES:-openbox tint2 pcmanfm xinit xserver-xorg-core xserver-xorg-input-libinput xserver-xorg-video-fbdev xserver-xorg-video-vesa xserver-xorg-video-vmware lxterminal fonts-dejavu adwaita-icon-theme hicolor-icon-theme shared-mime-info}
OPENBOX_DESKTOP_SKIP_PACKAGES=${OPENBOX_DESKTOP_SKIP_PACKAGES:-base-files dbus dbus-bin dbus-daemon dbus-session-bus-common dbus-system-bus-common dbus-user-session debconf dpkg init-system-helpers keyboard-configuration libpam-systemd mount procps systemd systemd-sysv sysvinit-utils tar tzdata udev}
DOOM_EMACS_SKIP_PACKAGES=${DOOM_EMACS_SKIP_PACKAGES:-$OPENBOX_DESKTOP_SKIP_PACKAGES}
KERNEL_SRC_DIR="$SOURCE_DIR/linux-${KERNEL_VERSION}"
BUSYBOX_SRC_DIR="$SOURCE_DIR/busybox-${BUSYBOX_VERSION}"
@@ -73,6 +78,7 @@ BUSYBOX_BUILD_DIR="$BUILD_DIR/busybox-${BUSYBOX_VERSION}"
SYSTEMD_BUILD_DIR="$BUILD_DIR/systemd-${SYSTEMD_VERSION}"
DBUS_BUILD_DIR="$BUILD_DIR/dbus-${DBUS_VERSION}"
PAM_BUILD_DIR="$BUILD_DIR/linux-pam-${PAM_VERSION}"
DOOM_EMACS_SRC_DIR="$SOURCE_DIR/doomemacs"
MODULES_STAGING_DIR="$STAGING_DIR/modules"
SYSTEMD_STAGING_DIR="$STAGING_DIR/systemd"
DBUS_STAGING_DIR="$STAGING_DIR/dbus"
@@ -80,6 +86,8 @@ PAM_STAGING_DIR="$STAGING_DIR/pam"
ROOTFS_STAGING_DIR="$STAGING_DIR/rootfs"
OPENBOX_DESKTOP_DEB_DIR=${OPENBOX_DESKTOP_DEB_DIR:-"$DOWNLOAD_DIR/openbox-desktop-debs"}
OPENBOX_DESKTOP_APT_STATE_DIR=${OPENBOX_DESKTOP_APT_STATE_DIR:-"$BUILD_DIR/openbox-desktop-apt-state"}
DOOM_EMACS_DEB_DIR=${DOOM_EMACS_DEB_DIR:-"$DOWNLOAD_DIR/doom-emacs-debs"}
DOOM_EMACS_APT_STATE_DIR=${DOOM_EMACS_APT_STATE_DIR:-"$BUILD_DIR/doom-emacs-apt-state"}
msg() {
printf '==> %s\n' "$*"
+5 -2
View File
@@ -15,6 +15,7 @@ packages=(
flex
ca-certificates
curl
git
tar
xz-utils
bzip2
@@ -47,6 +48,7 @@ required_commands=(
make
gcc
curl
git
tar
xz
bzip2
@@ -65,6 +67,7 @@ required_commands=(
ldd
ldconfig
install
dpkg-deb
qemu-system-x86_64
)
@@ -83,8 +86,8 @@ Options:
--help Show this help.
This does not install desktop, GNOME, disk-image, installer, or Secure Boot
extras. It is intentionally scoped to the console rootfs and direct QEMU run
path.
extras. It includes the host tools needed to enable optional rootfs layers such
as Doom Emacs, but it does not install those target packages on the host.
EOF
}
+279
View File
@@ -0,0 +1,279 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
require_cmd chmod cp git mkdir rm rsync
ensure_dirs
[[ -d "$ROOTFS_STAGING_DIR" ]] || die "missing rootfs staging tree: $ROOTFS_STAGING_DIR"
doom_package_array() {
local package
for package in $DOOM_EMACS_PACKAGES; do
printf '%s\n' "$package"
done
}
is_skipped_package() {
local package=$1
case " $DOOM_EMACS_SKIP_PACKAGES " in
*" $package "*) return 0 ;;
*) return 1 ;;
esac
}
has_doom_runtime() {
local emacs_ok=1
if [[ -x "$ROOTFS_STAGING_DIR/usr/bin/emacs" || -x "$ROOTFS_STAGING_DIR/usr/bin/emacs-nox" || -x "$ROOTFS_STAGING_DIR/usr/bin/emacs-gtk" ]]; then
emacs_ok=0
fi
[[ "$emacs_ok" -eq 0 ]] &&
[[ -x "$ROOTFS_STAGING_DIR/usr/bin/git" ]] &&
[[ -x "$ROOTFS_STAGING_DIR/usr/bin/rg" ]] &&
[[ -x "$ROOTFS_STAGING_DIR/usr/bin/find" ]]
}
download_doom_packages() {
local -a packages=()
local package
local status_file="$DOOM_EMACS_APT_STATE_DIR/status"
local extended_states_file="$DOOM_EMACS_APT_STATE_DIR/extended_states"
require_cmd apt-get
while IFS= read -r package; do
[[ -n "$package" ]] && packages+=("$package")
done < <(doom_package_array)
[[ "${#packages[@]}" -gt 0 ]] || die "DOOM_EMACS_PACKAGES is empty"
mkdir -p \
"$DOOM_EMACS_DEB_DIR/partial" \
"$DOOM_EMACS_APT_STATE_DIR"
: > "$status_file"
: > "$extended_states_file"
msg "downloading Doom Emacs runtime package closure"
apt-get \
-o "Dir::State::status=$status_file" \
-o "Dir::State::extended_states=$extended_states_file" \
-o "Dir::Cache::archives=$DOOM_EMACS_DEB_DIR" \
-o Debug::NoLocking=1 \
--yes \
--download-only \
--no-install-recommends \
install "${packages[@]}"
}
extract_doom_packages() {
local deb
local package
local extracted_count=0
local skipped_count=0
require_cmd dpkg-deb
shopt -s nullglob
for deb in "$DOOM_EMACS_DEB_DIR"/*.deb; do
package=$(dpkg-deb -f "$deb" Package)
if is_skipped_package "$package"; then
skipped_count=$((skipped_count + 1))
continue
fi
dpkg-deb -x "$deb" "$ROOTFS_STAGING_DIR"
extracted_count=$((extracted_count + 1))
done
shopt -u nullglob
[[ "$extracted_count" -gt 0 ]] || die "no Doom Emacs runtime packages were extracted from $DOOM_EMACS_DEB_DIR"
msg "extracted $extracted_count Doom Emacs packages; skipped $skipped_count base packages"
}
sync_doom_source() {
mkdir -p "$(dirname "$DOOM_EMACS_SRC_DIR")"
if [[ -d "$DOOM_EMACS_SRC_DIR/.git" ]]; then
msg "updating Doom Emacs source"
git -C "$DOOM_EMACS_SRC_DIR" fetch --depth 1 origin "$DOOM_EMACS_REF"
git -C "$DOOM_EMACS_SRC_DIR" checkout -q FETCH_HEAD
else
msg "cloning Doom Emacs source"
rm -rf "$DOOM_EMACS_SRC_DIR"
git clone --depth 1 --branch "$DOOM_EMACS_REF" "$DOOM_EMACS_GIT_URL" "$DOOM_EMACS_SRC_DIR"
fi
}
stage_doom_source() {
local doom_share="$ROOTFS_STAGING_DIR/usr/share/doom-emacs"
mkdir -p "$doom_share"
rsync -a --delete "$DOOM_EMACS_SRC_DIR"/ "$doom_share"/
}
write_doom_integration() {
mkdir -p \
"$ROOTFS_STAGING_DIR/etc/profile.d" \
"$ROOTFS_STAGING_DIR/etc/skel/.config/doom" \
"$ROOTFS_STAGING_DIR/usr/local/bin" \
"$ROOTFS_STAGING_DIR/usr/local/libexec"
cat > "$ROOTFS_STAGING_DIR/etc/profile.d/doom-emacs.sh" <<'EOF'
doom_emacs_config_home=${XDG_CONFIG_HOME:-"$HOME/.config"}
doom_emacs_bin="$doom_emacs_config_home/emacs/bin"
case ":$PATH:" in
*":$doom_emacs_bin:"*) ;;
*) PATH="$doom_emacs_bin:$PATH" ;;
esac
export PATH
if [ -n "${HOME:-}" ] && [ -w "$HOME" ] && [ -x /usr/local/libexec/forgeos-doom-seed ]; then
/usr/local/libexec/forgeos-doom-seed >/dev/null 2>&1 || true
fi
unset doom_emacs_config_home doom_emacs_bin
EOF
cat > "$ROOTFS_STAGING_DIR/usr/local/libexec/forgeos-doom-seed" <<'EOF'
#!/bin/sh
set -eu
[ -n "${HOME:-}" ] || exit 0
[ -d /usr/share/doom-emacs ] || exit 0
config_home=${XDG_CONFIG_HOME:-"$HOME/.config"}
emacs_dir=${EMACS_DIR:-"$config_home/emacs"}
doom_dir=${DOOMDIR:-"$config_home/doom"}
tmp_dir="$emacs_dir.tmp"
mkdir -p "$config_home"
if [ ! -e "$emacs_dir" ]; then
rm -rf "$tmp_dir"
cp -a /usr/share/doom-emacs "$tmp_dir"
mv "$tmp_dir" "$emacs_dir"
fi
if [ ! -d "$doom_dir" ]; then
mkdir -p "$doom_dir"
for name in init config packages; do
template="$emacs_dir/templates/$name.example.el"
if [ -f "$template" ]; then
cp "$template" "$doom_dir/$name.el"
fi
done
if [ ! -f "$doom_dir/init.el" ]; then
printf ';;; init.el -*- lexical-binding: t; -*-\n(doom!)\n' > "$doom_dir/init.el"
fi
if [ ! -f "$doom_dir/config.el" ]; then
printf ';;; config.el -*- lexical-binding: t; -*-\n(setq user-full-name "ForgeOS User")\n' > "$doom_dir/config.el"
fi
if [ ! -f "$doom_dir/packages.el" ]; then
printf ';;; packages.el -*- lexical-binding: t; -*-\n' > "$doom_dir/packages.el"
fi
fi
EOF
cat > "$ROOTFS_STAGING_DIR/usr/local/bin/doom" <<'EOF'
#!/bin/sh
set -eu
if [ -x /usr/local/libexec/forgeos-doom-seed ]; then
/usr/local/libexec/forgeos-doom-seed >/dev/null 2>&1 || true
fi
config_home=${XDG_CONFIG_HOME:-"$HOME/.config"}
doom_bin="$config_home/emacs/bin/doom"
if [ ! -x "$doom_bin" ]; then
printf 'doom: Doom Emacs is not staged for this user\n' >&2
exit 127
fi
exec "$doom_bin" "$@"
EOF
cat > "$ROOTFS_STAGING_DIR/usr/local/bin/emacs" <<'EOF'
#!/bin/sh
set -eu
if [ -x /usr/bin/emacs ]; then
exec /usr/bin/emacs "$@"
fi
if [ -x /usr/bin/emacs-nox ]; then
exec /usr/bin/emacs-nox "$@"
fi
if [ -x /usr/bin/emacs-gtk ]; then
exec /usr/bin/emacs-gtk "$@"
fi
printf 'emacs: no Emacs binary found in /usr/bin\n' >&2
exit 127
EOF
cat > "$ROOTFS_STAGING_DIR/usr/local/bin/fd" <<'EOF'
#!/bin/sh
set -eu
if [ -x /usr/bin/fdfind ]; then
exec /usr/bin/fdfind "$@"
fi
if [ -x /usr/bin/fd ]; then
exec /usr/bin/fd "$@"
fi
printf 'fd: no fd-compatible binary found\n' >&2
exit 127
EOF
cat > "$ROOTFS_STAGING_DIR/usr/local/bin/find" <<'EOF'
#!/bin/sh
set -eu
if [ -x /usr/bin/find ]; then
exec /usr/bin/find "$@"
fi
if [ -x /bin/find ]; then
exec /bin/find "$@"
fi
printf 'find: no find binary found\n' >&2
exit 127
EOF
cat > "$ROOTFS_STAGING_DIR/etc/forgeos-doom-emacs" <<EOF
NAME=Doom Emacs
GIT_URL=$DOOM_EMACS_GIT_URL
REF=$DOOM_EMACS_REF
CONFIG_HOME=.config/emacs
DOOMDIR=.config/doom
EOF
chmod 0755 \
"$ROOTFS_STAGING_DIR/usr/local/libexec/forgeos-doom-seed" \
"$ROOTFS_STAGING_DIR/usr/local/bin/doom" \
"$ROOTFS_STAGING_DIR/usr/local/bin/emacs" \
"$ROOTFS_STAGING_DIR/usr/local/bin/fd" \
"$ROOTFS_STAGING_DIR/usr/local/bin/find"
}
if has_doom_runtime; then
msg "using existing Emacs/Git/ripgrep runtime in rootfs"
else
download_doom_packages
extract_doom_packages
fi
sync_doom_source
stage_doom_source
write_doom_integration
msg "Doom Emacs layer staged into $ROOTFS_STAGING_DIR"