chore(rootfs): remove Doom Emacs layer

Add the ForgeOS home ownership repair unit to the normal rootfs assembly.
This commit is contained in:
blazblue547-afk committed 2026-06-17 11:18:14 -04:00
1 parent 7e7ca149c7
commit eb8038ef4c
10 files changed
+36 -334

No files matched your search

+2 -9
View File
@@ -10,12 +10,10 @@ export NIX_VERSION ?= 2.34.0
export NIX_SYSTEM ?= x86_64-linux
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))
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)),6144,4096))
export IMAGE_SIZE_MIB ?= $(if $(filter gnome,$(DESKTOP)),12288,$(if $(desktop_enabled),6144,4096))
export ESP_SIZE_MIB ?= 256
export JOBS ?= $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
export SECURE_BOOT ?= 0
@@ -24,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 doom-emacs 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 gnome-rootfs image gnome-image secure-boot-keys run run-image run-desktop run-gnome list-disks install clean distclean
help:
@printf '%s\n' \
@@ -40,8 +38,6 @@ help:
' make rootfs - assemble the systemd rootfs and initramfs' \
' make rootfs includes Nix as the core package manager' \
' 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' \
@@ -82,9 +78,6 @@ 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:
+1 -14
View File
@@ -2,7 +2,7 @@
ForgeOS is a custom `x86_64` operating system project that defaults to a CLI-only source-built userspace instead of an existing Linux distribution tree. It uses the Linux kernel as the kernel layer, systemd as PID 1, BusyBox as a compact shell/rescue utility set, a custom root filesystem overlay, and direct UEFI boot through the kernel EFI stub. An optional GNOME desktop image flavor is available through a Debian package bootstrap.
As of `2026-06-16`, the project defaults to:
As of `2026-06-17`, the project defaults to:
- Linux kernel `7.1`
- systemd `260`
@@ -14,7 +14,6 @@ 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
@@ -72,16 +71,6 @@ 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
@@ -121,7 +110,6 @@ 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.
@@ -161,7 +149,6 @@ Linux-PAM, systemd, and D-Bus are built with Meson/Ninja and staged dynamically.
- Nix is the package manager for the normal ForgeOS rootfs, but ForgeOS does not yet have a declarative NixOS-style system rebuild/update flow.
- 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.
-6
View File
@@ -10,15 +10,12 @@ ForgeOS defaults to a CLI-only operating system for `x86_64` desktops and laptop
- Linux-PAM for local login authentication and session hooks
- BusyBox for `/bin/sh`, early switch-root support, and compact rescue tools
- Nix for core package management
- 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.
@@ -54,8 +51,6 @@ 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:
@@ -96,7 +91,6 @@ 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
- declarative NixOS-style system rebuilds and rollback 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
@@ -0,0 +1,12 @@
[Unit]
Description=Repair ForgeOS user home ownership
Documentation=man:systemd.service(5)
After=local-fs.target
Before=systemd-user-sessions.service getty.target forgeos-login@tty1.service forgeos-login@ttyS0.service
[Service]
Type=oneshot
ExecStart=/bin/sh -c 'if [ -d /home/forge ]; then chown -R 1000:1000 /home/forge && chmod 700 /home/forge; fi'
[Install]
WantedBy=multi-user.target
-7
View File
@@ -16,10 +16,6 @@ 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
@@ -277,9 +273,6 @@ 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/"
+16 -4
View File
@@ -7,14 +7,26 @@ source "$(dirname "$0")/common.sh"
require_cmd qemu-img parted mkfs.vfat mkfs.ext4 mcopy mmd dd awk truncate
ensure_dirs
normal_rootfs_matches() {
[[ -d "$ROOTFS_STAGING_DIR" ]] || return 1
[[ -f "$ROOTFS_STAGING_DIR/etc/forgeos-nix" ]] || return 1
if truthy "$ENABLE_DESKTOP"; then
[[ -f "$ROOTFS_STAGING_DIR/etc/forgeos-desktop" ]] || return 1
else
[[ ! -f "$ROOTFS_STAGING_DIR/etc/forgeos-desktop" ]] || return 1
fi
[[ ! -f "$ROOTFS_STAGING_DIR/etc/forgeos-doom-emacs" ]] || return 1
}
[[ -f "$OUT_DIR/bzImage" ]] || "$ROOT_DIR/scripts/build-kernel.sh"
if [[ "$DESKTOP" == "gnome" ]]; then
[[ -d "$ROOTFS_STAGING_DIR" && -f "$ROOTFS_STAGING_DIR/etc/gdm3/daemon.conf" ]] || "$ROOT_DIR/scripts/build-gnome-rootfs.sh"
else
if truthy "$ENABLE_DESKTOP"; then
[[ -d "$ROOTFS_STAGING_DIR" && -f "$ROOTFS_STAGING_DIR/etc/forgeos-desktop" && -f "$ROOTFS_STAGING_DIR/etc/forgeos-nix" ]] || "$ROOT_DIR/scripts/build-rootfs.sh"
else
[[ -d "$ROOTFS_STAGING_DIR" && -f "$ROOTFS_STAGING_DIR/etc/forgeos-nix" ]] || "$ROOT_DIR/scripts/build-rootfs.sh"
normal_rootfs_matches || "$ROOT_DIR/scripts/build-rootfs.sh"
if ! truthy "$ENABLE_DESKTOP"; then
[[ -f "$OUT_DIR/rootfs.cpio.gz" ]] || "$ROOT_DIR/scripts/build-rootfs.sh"
fi
fi
+2 -4
View File
@@ -110,6 +110,8 @@ ln -sfn /etc/systemd/system/forgeos-bootdiag.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants/forgeos-bootdiag.service"
ln -sfn /etc/systemd/system/forgeos-console-banner.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants/forgeos-console-banner.service"
ln -sfn /etc/systemd/system/forgeos-home-ownership.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants/forgeos-home-ownership.service"
ln -sfn /usr/lib/systemd/system/dbus.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants/dbus.service"
ln -sfn /usr/lib/systemd/system/dbus.socket \
@@ -156,10 +158,6 @@ 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" \
+1 -9
View File
@@ -20,7 +20,6 @@ NIX_VERSION=${NIX_VERSION:-2.34.0}
NIX_SYSTEM=${NIX_SYSTEM:-x86_64-linux}
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
@@ -33,7 +32,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)$ || "$ENABLE_DOOM_EMACS" =~ ^(1|true|TRUE|yes|YES|on|ON)$ ]]; then
elif [[ "$ENABLE_DESKTOP" =~ ^(1|true|TRUE|yes|YES|on|ON)$ ]]; then
IMAGE_SIZE_MIB=6144
else
IMAGE_SIZE_MIB=4096
@@ -65,12 +64,8 @@ NIX_TARBALL="nix-${NIX_VERSION}-${NIX_SYSTEM}.tar.xz"
NIX_URL="https://releases.nixos.org/nix/nix-${NIX_VERSION}/${NIX_TARBALL}"
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}"
@@ -83,7 +78,6 @@ 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"
@@ -91,8 +85,6 @@ 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' "$*"
+2 -2
View File
@@ -86,8 +86,8 @@ Options:
--help Show this help.
This does not install desktop, GNOME, disk-image, installer, or Secure Boot
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.
extras. It includes the host tools needed to enable optional rootfs layers, but
it does not install those target packages on the host.
EOF
}
-279
View File
@@ -1,279 +0,0 @@
#!/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"