Add Nix core package manager

This commit is contained in:
blazblue547-afk committed 2026-06-16 18:26:55 -04:00
1 parent fb2112c141
commit 382db41a55
14 files changed
+323 -8

No files matched your search

+4 -1
View File
@@ -6,6 +6,8 @@ export BUSYBOX_VERSION ?= 1.38.0
export SYSTEMD_VERSION ?= 260 export SYSTEMD_VERSION ?= 260
export DBUS_VERSION ?= 1.16.2 export DBUS_VERSION ?= 1.16.2
export PAM_VERSION ?= 1.7.2 export PAM_VERSION ?= 1.7.2
export NIX_VERSION ?= 2.34.0
export NIX_SYSTEM ?= x86_64-linux
export DESKTOP ?= console export DESKTOP ?= console
export ENABLE_DESKTOP ?= 0 export ENABLE_DESKTOP ?= 0
export ENABLE_DOOM_EMACS ?= 0 export ENABLE_DOOM_EMACS ?= 0
@@ -13,7 +15,7 @@ export ROOT_LABEL ?= FORGE_ROOT
export EFI_LABEL ?= FORGE_EFI export EFI_LABEL ?= FORGE_EFI
desktop_enabled := $(filter 1 true TRUE yes YES on ON,$(ENABLE_DESKTOP)) 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)) 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 IMAGE_SIZE_MIB ?= $(if $(filter gnome,$(DESKTOP)),12288,$(if $(or $(desktop_enabled),$(doom_emacs_enabled)),6144,4096))
export ESP_SIZE_MIB ?= 256 export ESP_SIZE_MIB ?= 256
export JOBS ?= $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1) export JOBS ?= $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
export SECURE_BOOT ?= 0 export SECURE_BOOT ?= 0
@@ -36,6 +38,7 @@ help:
' make systemd - build systemd PID 1' \ ' make systemd - build systemd PID 1' \
' make dbus - build the D-Bus system bus daemon' \ ' make dbus - build the D-Bus system bus daemon' \
' make rootfs - assemble the systemd rootfs and initramfs' \ ' 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_DESKTOP=1 make rootfs - add Openbox/tint2/PCManFM desktop' \
' ENABLE_DOOM_EMACS=1 make rootfs - add Emacs + Doom Emacs tooling' \ ' ENABLE_DOOM_EMACS=1 make rootfs - add Emacs + Doom Emacs tooling' \
' make doom-emacs - rebuild rootfs with the Doom Emacs layer enabled' \ ' make doom-emacs - rebuild rootfs with the Doom Emacs layer enabled' \
+10 -1
View File
@@ -9,6 +9,7 @@ As of `2026-06-16`, the project defaults to:
- D-Bus `1.16.2` - D-Bus `1.16.2`
- BusyBox `1.38.0` - BusyBox `1.38.0`
- Linux-PAM `1.7.2` - Linux-PAM `1.7.2`
- Nix `2.34.0` as the core package manager
- `amd64` / `x86_64` only - `amd64` / `x86_64` only
- 64-bit only - 64-bit only
- UEFI boot - UEFI boot
@@ -45,6 +46,13 @@ That dependency script is for Debian/Ubuntu hosts and installs only the packages
The default console accounts are `forge` and `root`; both use the password `forge`. Console logins go through BusyBox `login`, Linux-PAM, and `pam_systemd.so`, so `systemd-logind` tracks real per-user sessions. The default console accounts are `forge` and `root`; both use the password `forge`. Console logins go through BusyBox `login`, Linux-PAM, and `pam_systemd.so`, so `systemd-logind` tracks real per-user sessions.
Nix is staged into the normal ForgeOS rootfs as the core package manager. On first boot, `forgeos-nix-bootstrap.service` registers the initial `/nix/store` closure, creates the default Nix profile, and starts `nix-daemon`. Log in as `forge` and install packages with the modern profile command:
```bash
nix profile install nixpkgs#hello
hello
```
To build a UEFI disk image: To build a UEFI disk image:
```bash ```bash
@@ -106,6 +114,7 @@ sudo make install DISK=/dev/nvme0n1
- For default direct QEMU testing, `scripts/run-qemu.sh direct` uses the generated `rootfs.cpio.gz`. - For default direct QEMU testing, `scripts/run-qemu.sh direct` uses the generated `rootfs.cpio.gz`.
- The host-side installer expands the root partition to fill larger target disks. - The host-side installer expands the root partition to fill larger target disks.
- systemd is installed as `/sbin/init`. BusyBox remains available for `/bin/sh`, PAM-backed `/bin/login`, early switch-root support, and emergency command-line tools. - systemd is installed as `/sbin/init`. BusyBox remains available for `/bin/sh`, PAM-backed `/bin/login`, early switch-root support, and emergency command-line tools.
- Nix `2.34.0` is staged from the official `x86_64-linux` binary tarball and configured in multi-user daemon mode with `/nix`, `nixbld` build users, `cache.nixos.org`, and `nix-command`/`flakes` enabled. Override `NIX_VERSION` or `NIX_SYSTEM` if you intentionally want a different upstream tarball.
- A ForgeOS-native `neofetch` command is included in the overlay with a custom ForgeOS ASCII logo at `/usr/share/neofetch/ascii/distro/forgeos`. - A ForgeOS-native `neofetch` command is included in the overlay with a custom ForgeOS ASCII logo at `/usr/share/neofetch/ascii/distro/forgeos`.
- The console starts PAM-backed login prompts on `tty1` and `ttyS0` through native systemd units instead of BusyBox `inittab`. - The console starts PAM-backed login prompts on `tty1` and `ttyS0` through native systemd units instead of BusyBox `inittab`.
- The system bus is provided by source-built `dbus-daemon` and socket-activated at `/run/dbus/system_bus_socket`. - The system bus is provided by source-built `dbus-daemon` and socket-activated at `/run/dbus/system_bus_socket`.
@@ -149,7 +158,7 @@ Linux-PAM, systemd, and D-Bus are built with Meson/Ninja and staged dynamically.
- UEFI only for now; BIOS boot is not implemented. - UEFI only for now; BIOS boot is not implemented.
- The kernel config includes common desktop, laptop, and QEMU storage/input paths, but not every vendor driver. - The kernel config includes common desktop, laptop, and QEMU storage/input paths, but not every vendor driver.
- Wireless firmware, GPU acceleration, stock Microsoft-trusted Secure Boot/shim integration, audio, and power-management polish are not bundled yet. - Wireless firmware, GPU acceleration, stock Microsoft-trusted Secure Boot/shim integration, audio, and power-management polish are not bundled yet.
- There is no package manager yet. - 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. - 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 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. - 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.
+6 -2
View File
@@ -9,6 +9,7 @@ ForgeOS defaults to a CLI-only operating system for `x86_64` desktops and laptop
- D-Bus for the system message bus - D-Bus for the system message bus
- Linux-PAM for local login authentication and session hooks - Linux-PAM for local login authentication and session hooks
- BusyBox for `/bin/sh`, early switch-root support, and compact rescue tools - 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 - optional Doom Emacs tooling for an editor-focused user environment
- custom units and configuration files from this repository - custom units and configuration files from this repository
@@ -39,11 +40,14 @@ The root filesystem is assembled in `staging/rootfs` from:
- Linux-PAM install output from `staging/pam` - Linux-PAM install output from `staging/pam`
- runtime library dependencies copied from the native build host for systemd, D-Bus, PAM, and BusyBox binaries - runtime library dependencies copied from the native build host for systemd, D-Bus, PAM, and BusyBox binaries
- BusyBox install output for shell and rescue utilities - BusyBox install output for shell and rescue utilities
- the official Nix `x86_64-linux` binary tarball staged into `/nix/store`
- kernel modules from the kernel build - kernel modules from the kernel build
- the repository overlay in `overlay/rootfs` - the repository overlay in `overlay/rootfs`
The default network path uses DHCP through `systemd-networkd`. DNS servers learned from DHCP are exposed through `systemd-resolved`, and `/etc/resolv.conf` is a symlink to the resolved-managed compatibility file at `/run/systemd/resolve/resolv.conf`. Tools that query systemd over D-Bus use the system bus at `/run/dbus/system_bus_socket`. The source-built systemd layer also includes `systemd-logind`, `loginctl`, `pam_systemd.so`, the `org.freedesktop.login1` system-bus policy, and the logind varlink socket. Console login uses BusyBox `getty` and `login`; `/etc/pam.d/login` authenticates against `/etc/shadow` with `pam_unix.so` and registers sessions with `pam_systemd.so`. The default network path uses DHCP through `systemd-networkd`. DNS servers learned from DHCP are exposed through `systemd-resolved`, and `/etc/resolv.conf` is a symlink to the resolved-managed compatibility file at `/run/systemd/resolve/resolv.conf`. Tools that query systemd over D-Bus use the system bus at `/run/dbus/system_bus_socket`. The source-built systemd layer also includes `systemd-logind`, `loginctl`, `pam_systemd.so`, the `org.freedesktop.login1` system-bus policy, and the logind varlink socket. Console login uses BusyBox `getty` and `login`; `/etc/pam.d/login` authenticates against `/etc/shadow` with `pam_unix.so` and registers sessions with `pam_systemd.so`.
Nix is integrated as a multi-user daemon package manager in the normal ForgeOS rootfs. `scripts/stage-nix.sh` copies the official Nix store closure into `/nix/store`, stages `nix.conf`, adds `nixbld` build accounts, enables `forgeos-nix-bootstrap.service`, and exposes `nix-daemon.service` plus `nix-daemon.socket`. On first boot, the bootstrap service fixes `/nix` ownership, loads the bundled `.reginfo` into the Nix database, and creates the default profile with Nix, Nix manual pages, and the bundled CA certificate package. ForgeOS enables `nix-command` and `flakes`, uses `cache.nixos.org`, and leaves Nix build sandboxing disabled until the OS has a verified sandbox policy.
The default console build also generates `out/rootfs.cpio.gz` for quick QEMU smoke tests. Desktop-enabled rootfs builds skip the initramfs artifact and boot through the ext4 root partition image. The default console build also generates `out/rootfs.cpio.gz` for quick QEMU smoke tests. Desktop-enabled rootfs builds skip the initramfs artifact and boot through the ext4 root partition image.
For `DESKTOP=gnome`, `scripts/build-gnome-rootfs.sh` uses `mmdebstrap` or root-run `debootstrap` to assemble a Debian GNOME root filesystem in `staging/rootfs`, adds ForgeOS identity defaults, creates the initial desktop user, enables GDM and NetworkManager, and copies ForgeOS kernel modules. The GNOME image path deliberately does not copy `rootfs.cpio.gz` into the EFI System Partition because a desktop rootfs is too large for the initramfs-based smoke-test flow. For `DESKTOP=gnome`, `scripts/build-gnome-rootfs.sh` uses `mmdebstrap` or root-run `debootstrap` to assemble a Debian GNOME root filesystem in `staging/rootfs`, adds ForgeOS identity defaults, creates the initial desktop user, enables GDM and NetworkManager, and copies ForgeOS kernel modules. The GNOME image path deliberately does not copy `rootfs.cpio.gz` into the EFI System Partition because a desktop rootfs is too large for the initramfs-based smoke-test flow.
@@ -91,7 +95,7 @@ This is enough for a first CLI OS image and a development boot path, but not yet
- Microsoft/shim-signed Secure Boot chain - Microsoft/shim-signed Secure Boot chain
- measured boot and full verified boot - measured boot and full verified boot
- full laptop Wi-Fi and firmware coverage - full laptop Wi-Fi and firmware coverage
- package management - declarative NixOS-style system rebuilds and rollback management
- pre-synced per-user Doom Emacs package caches - pre-synced per-user Doom Emacs package caches
- source-built GNOME and graphical desktop dependency closure - source-built GNOME and graphical desktop dependency closure
- source-built Openbox/Xorg/GTK graphical dependency closure - source-built Openbox/Xorg/GTK graphical dependency closure
@@ -104,5 +108,5 @@ This is enough for a first CLI OS image and a development boot path, but not yet
1. Add a source-built libc and dependency sysroot so systemd no longer needs copied host libraries. 1. Add a source-built libc and dependency sysroot so systemd no longer needs copied host libraries.
2. Teach the installer to support target-specific kernel command lines so multiple ForgeOS disks can coexist more safely. 2. Teach the installer to support target-specific kernel command lines so multiple ForgeOS disks can coexist more safely.
3. Add network profiles, SSH, and a package/update mechanism. 3. Add network profiles, SSH, and a ForgeOS system update mechanism on top of Nix.
4. Expand kernel coverage for Wi-Fi, Bluetooth, audio, suspend, and vendor input devices. 4. Expand kernel coverage for Wi-Fi, Bluetooth, audio, suspend, and vendor input devices.
+1
View File
@@ -10,5 +10,6 @@ input:x:104:forge
systemd-journal:x:190: systemd-journal:x:190:
systemd-network:x:192: systemd-network:x:192:
systemd-resolve:x:193: systemd-resolve:x:193:
nixbld:x:30000:nixbld1,nixbld2,nixbld3,nixbld4,nixbld5,nixbld6,nixbld7,nixbld8,nixbld9,nixbld10,nixbld11,nixbld12,nixbld13,nixbld14,nixbld15,nixbld16,nixbld17,nixbld18,nixbld19,nixbld20,nixbld21,nixbld22,nixbld23,nixbld24,nixbld25,nixbld26,nixbld27,nixbld28,nixbld29,nixbld30,nixbld31,nixbld32
forge:x:1000: forge:x:1000:
nobody:x:65534: nobody:x:65534:
+1
View File
@@ -10,5 +10,6 @@ input:*::forge
systemd-journal:*:: systemd-journal:*::
systemd-network:*:: systemd-network:*::
systemd-resolve:*:: systemd-resolve:*::
nixbld:*::nixbld1,nixbld2,nixbld3,nixbld4,nixbld5,nixbld6,nixbld7,nixbld8,nixbld9,nixbld10,nixbld11,nixbld12,nixbld13,nixbld14,nixbld15,nixbld16,nixbld17,nixbld18,nixbld19,nixbld20,nixbld21,nixbld22,nixbld23,nixbld24,nixbld25,nixbld26,nixbld27,nixbld28,nixbld29,nixbld30,nixbld31,nixbld32
forge:!:: forge:!::
nobody:*:: nobody:*::
+32
View File
@@ -3,4 +3,36 @@ forge:x:1000:1000:ForgeOS User:/home/forge:/bin/sh
systemd-network:x:192:192:systemd Network Management:/:/bin/sh systemd-network:x:192:192:systemd Network Management:/:/bin/sh
systemd-resolve:x:193:193:systemd Resolver:/:/bin/sh systemd-resolve:x:193:193:systemd Resolver:/:/bin/sh
messagebus:x:81:81:System Message Bus:/:/bin/sh messagebus:x:81:81:System Message Bus:/:/bin/sh
nixbld1:x:30001:30000:Nix build user 1:/var/empty:/sbin/nologin
nixbld2:x:30002:30000:Nix build user 2:/var/empty:/sbin/nologin
nixbld3:x:30003:30000:Nix build user 3:/var/empty:/sbin/nologin
nixbld4:x:30004:30000:Nix build user 4:/var/empty:/sbin/nologin
nixbld5:x:30005:30000:Nix build user 5:/var/empty:/sbin/nologin
nixbld6:x:30006:30000:Nix build user 6:/var/empty:/sbin/nologin
nixbld7:x:30007:30000:Nix build user 7:/var/empty:/sbin/nologin
nixbld8:x:30008:30000:Nix build user 8:/var/empty:/sbin/nologin
nixbld9:x:30009:30000:Nix build user 9:/var/empty:/sbin/nologin
nixbld10:x:30010:30000:Nix build user 10:/var/empty:/sbin/nologin
nixbld11:x:30011:30000:Nix build user 11:/var/empty:/sbin/nologin
nixbld12:x:30012:30000:Nix build user 12:/var/empty:/sbin/nologin
nixbld13:x:30013:30000:Nix build user 13:/var/empty:/sbin/nologin
nixbld14:x:30014:30000:Nix build user 14:/var/empty:/sbin/nologin
nixbld15:x:30015:30000:Nix build user 15:/var/empty:/sbin/nologin
nixbld16:x:30016:30000:Nix build user 16:/var/empty:/sbin/nologin
nixbld17:x:30017:30000:Nix build user 17:/var/empty:/sbin/nologin
nixbld18:x:30018:30000:Nix build user 18:/var/empty:/sbin/nologin
nixbld19:x:30019:30000:Nix build user 19:/var/empty:/sbin/nologin
nixbld20:x:30020:30000:Nix build user 20:/var/empty:/sbin/nologin
nixbld21:x:30021:30000:Nix build user 21:/var/empty:/sbin/nologin
nixbld22:x:30022:30000:Nix build user 22:/var/empty:/sbin/nologin
nixbld23:x:30023:30000:Nix build user 23:/var/empty:/sbin/nologin
nixbld24:x:30024:30000:Nix build user 24:/var/empty:/sbin/nologin
nixbld25:x:30025:30000:Nix build user 25:/var/empty:/sbin/nologin
nixbld26:x:30026:30000:Nix build user 26:/var/empty:/sbin/nologin
nixbld27:x:30027:30000:Nix build user 27:/var/empty:/sbin/nologin
nixbld28:x:30028:30000:Nix build user 28:/var/empty:/sbin/nologin
nixbld29:x:30029:30000:Nix build user 29:/var/empty:/sbin/nologin
nixbld30:x:30030:30000:Nix build user 30:/var/empty:/sbin/nologin
nixbld31:x:30031:30000:Nix build user 31:/var/empty:/sbin/nologin
nixbld32:x:30032:30000:Nix build user 32:/var/empty:/sbin/nologin
nobody:x:65534:65534:nobody:/:/bin/sh nobody:x:65534:65534:nobody:/:/bin/sh
+32
View File
@@ -3,4 +3,36 @@ forge:$6$forgeos$gPbch8oHqLnms/ljQGrpqE5btu4FY8J9ryX.9/CfzBY6CyakPaoEkHapeKRjkZb
systemd-network:*:20620:0:99999:7::: systemd-network:*:20620:0:99999:7:::
systemd-resolve:*:20620:0:99999:7::: systemd-resolve:*:20620:0:99999:7:::
messagebus:*:20620:0:99999:7::: messagebus:*:20620:0:99999:7:::
nixbld1:!:20620:0:99999:7:::
nixbld2:!:20620:0:99999:7:::
nixbld3:!:20620:0:99999:7:::
nixbld4:!:20620:0:99999:7:::
nixbld5:!:20620:0:99999:7:::
nixbld6:!:20620:0:99999:7:::
nixbld7:!:20620:0:99999:7:::
nixbld8:!:20620:0:99999:7:::
nixbld9:!:20620:0:99999:7:::
nixbld10:!:20620:0:99999:7:::
nixbld11:!:20620:0:99999:7:::
nixbld12:!:20620:0:99999:7:::
nixbld13:!:20620:0:99999:7:::
nixbld14:!:20620:0:99999:7:::
nixbld15:!:20620:0:99999:7:::
nixbld16:!:20620:0:99999:7:::
nixbld17:!:20620:0:99999:7:::
nixbld18:!:20620:0:99999:7:::
nixbld19:!:20620:0:99999:7:::
nixbld20:!:20620:0:99999:7:::
nixbld21:!:20620:0:99999:7:::
nixbld22:!:20620:0:99999:7:::
nixbld23:!:20620:0:99999:7:::
nixbld24:!:20620:0:99999:7:::
nixbld25:!:20620:0:99999:7:::
nixbld26:!:20620:0:99999:7:::
nixbld27:!:20620:0:99999:7:::
nixbld28:!:20620:0:99999:7:::
nixbld29:!:20620:0:99999:7:::
nixbld30:!:20620:0:99999:7:::
nixbld31:!:20620:0:99999:7:::
nixbld32:!:20620:0:99999:7:::
nobody:*:20620:0:99999:7::: nobody:*:20620:0:99999:7:::
@@ -15,3 +15,6 @@ enable systemd-resolved-varlink.socket
enable systemd-udevd.service enable systemd-udevd.service
enable systemd-udevd-control.socket enable systemd-udevd-control.socket
enable systemd-udevd-kernel.socket enable systemd-udevd-kernel.socket
enable forgeos-nix-bootstrap.service
enable nix-daemon.service
enable nix-daemon.socket
+2 -2
View File
@@ -12,9 +12,9 @@ if [[ "$DESKTOP" == "gnome" ]]; then
[[ -d "$ROOTFS_STAGING_DIR" && -f "$ROOTFS_STAGING_DIR/etc/gdm3/daemon.conf" ]] || "$ROOT_DIR/scripts/build-gnome-rootfs.sh" [[ -d "$ROOTFS_STAGING_DIR" && -f "$ROOTFS_STAGING_DIR/etc/gdm3/daemon.conf" ]] || "$ROOT_DIR/scripts/build-gnome-rootfs.sh"
else else
if truthy "$ENABLE_DESKTOP"; then if truthy "$ENABLE_DESKTOP"; then
[[ -d "$ROOTFS_STAGING_DIR" && -f "$ROOTFS_STAGING_DIR/etc/forgeos-desktop" ]] || "$ROOT_DIR/scripts/build-rootfs.sh" [[ -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 else
[[ -d "$ROOTFS_STAGING_DIR" ]] || "$ROOT_DIR/scripts/build-rootfs.sh" [[ -d "$ROOTFS_STAGING_DIR" && -f "$ROOTFS_STAGING_DIR/etc/forgeos-nix" ]] || "$ROOT_DIR/scripts/build-rootfs.sh"
[[ -f "$OUT_DIR/rootfs.cpio.gz" ]] || "$ROOT_DIR/scripts/build-rootfs.sh" [[ -f "$OUT_DIR/rootfs.cpio.gz" ]] || "$ROOT_DIR/scripts/build-rootfs.sh"
fi fi
fi fi
+11
View File
@@ -68,6 +68,9 @@ grep -qx 'CONFIG_LOGIN_SESSION_AS_CHILD=y' "$OUT_DIR/busybox.config" || "$ROOT_D
[[ -f "$OUT_DIR/bzImage" ]] || "$ROOT_DIR/scripts/build-kernel.sh" [[ -f "$OUT_DIR/bzImage" ]] || "$ROOT_DIR/scripts/build-kernel.sh"
msg "assembling root filesystem" msg "assembling root filesystem"
if [[ -d "$ROOTFS_STAGING_DIR" ]]; then
chmod -R u+w "$ROOTFS_STAGING_DIR" 2>/dev/null || true
fi
rm -rf "$ROOTFS_STAGING_DIR" rm -rf "$ROOTFS_STAGING_DIR"
mkdir -p "$ROOTFS_STAGING_DIR" mkdir -p "$ROOTFS_STAGING_DIR"
@@ -83,6 +86,7 @@ copy_busybox_deps
mkdir -p "$ROOTFS_STAGING_DIR"/{proc,sys,dev,run/dbus,tmp,var/lib/dbus,var/log,root,home/forge,boot,mnt,etc/systemd/system} mkdir -p "$ROOTFS_STAGING_DIR"/{proc,sys,dev,run/dbus,tmp,var/lib/dbus,var/log,root,home/forge,boot,mnt,etc/systemd/system}
rsync -a "$OVERLAY_DIR"/ "$ROOTFS_STAGING_DIR"/ rsync -a "$OVERLAY_DIR"/ "$ROOTFS_STAGING_DIR"/
"$ROOT_DIR/scripts/stage-nix.sh"
rm -f "$ROOTFS_STAGING_DIR/sbin/init" rm -f "$ROOTFS_STAGING_DIR/sbin/init"
ln -s ../usr/lib/systemd/systemd "$ROOTFS_STAGING_DIR/sbin/init" ln -s ../usr/lib/systemd/systemd "$ROOTFS_STAGING_DIR/sbin/init"
@@ -132,6 +136,12 @@ ln -sfn /usr/lib/systemd/system/systemd-udevd-control.socket \
"$ROOTFS_STAGING_DIR/etc/systemd/system/sockets.target.wants/systemd-udevd-control.socket" "$ROOTFS_STAGING_DIR/etc/systemd/system/sockets.target.wants/systemd-udevd-control.socket"
ln -sfn /usr/lib/systemd/system/systemd-udevd-kernel.socket \ ln -sfn /usr/lib/systemd/system/systemd-udevd-kernel.socket \
"$ROOTFS_STAGING_DIR/etc/systemd/system/sockets.target.wants/systemd-udevd-kernel.socket" "$ROOTFS_STAGING_DIR/etc/systemd/system/sockets.target.wants/systemd-udevd-kernel.socket"
ln -sfn /etc/systemd/system/forgeos-nix-bootstrap.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/sysinit.target.wants/forgeos-nix-bootstrap.service"
ln -sfn /etc/systemd/system/nix-daemon.service \
"$ROOTFS_STAGING_DIR/etc/systemd/system/multi-user.target.wants/nix-daemon.service"
ln -sfn /etc/systemd/system/nix-daemon.socket \
"$ROOTFS_STAGING_DIR/etc/systemd/system/sockets.target.wants/nix-daemon.socket"
ln -sfn /dev/null "$ROOTFS_STAGING_DIR/etc/systemd/system/autovt@.service" ln -sfn /dev/null "$ROOTFS_STAGING_DIR/etc/systemd/system/autovt@.service"
ln -sfn /dev/null "$ROOTFS_STAGING_DIR/etc/systemd/system/getty@tty1.service" ln -sfn /dev/null "$ROOTFS_STAGING_DIR/etc/systemd/system/getty@tty1.service"
@@ -155,6 +165,7 @@ chmod 755 \
"$ROOTFS_STAGING_DIR/sbin/forgeos-bootdiag" \ "$ROOTFS_STAGING_DIR/sbin/forgeos-bootdiag" \
"$ROOTFS_STAGING_DIR/sbin/forgeos-console-banner" \ "$ROOTFS_STAGING_DIR/sbin/forgeos-console-banner" \
"$ROOTFS_STAGING_DIR/sbin/forgeos-switch-root" \ "$ROOTFS_STAGING_DIR/sbin/forgeos-switch-root" \
"$ROOTFS_STAGING_DIR/usr/lib/forgeos/nix-bootstrap" \
"$ROOTFS_STAGING_DIR/usr/bin/neofetch" \ "$ROOTFS_STAGING_DIR/usr/bin/neofetch" \
"$ROOTFS_STAGING_DIR/usr/share/udhcpc/default.script" "$ROOTFS_STAGING_DIR/usr/share/udhcpc/default.script"
chmod 700 "$ROOTFS_STAGING_DIR/root" "$ROOTFS_STAGING_DIR/home/forge" chmod 700 "$ROOTFS_STAGING_DIR/root" "$ROOTFS_STAGING_DIR/home/forge"
+3
View File
@@ -4,5 +4,8 @@ set -euo pipefail
source "$(dirname "$0")/common.sh" source "$(dirname "$0")/common.sh"
for path in "$BUILD_DIR" "$STAGING_DIR" "$OUT_DIR"; do
[[ -d "$path" ]] && chmod -R u+w "$path" 2>/dev/null || true
done
rm -rf "$BUILD_DIR" "$STAGING_DIR" "$OUT_DIR" rm -rf "$BUILD_DIR" "$STAGING_DIR" "$OUT_DIR"
msg "removed build, staging, and output directories" msg "removed build, staging, and output directories"
+7 -2
View File
@@ -16,6 +16,8 @@ BUSYBOX_VERSION=${BUSYBOX_VERSION:-1.38.0}
SYSTEMD_VERSION=${SYSTEMD_VERSION:-260} SYSTEMD_VERSION=${SYSTEMD_VERSION:-260}
DBUS_VERSION=${DBUS_VERSION:-1.16.2} DBUS_VERSION=${DBUS_VERSION:-1.16.2}
PAM_VERSION=${PAM_VERSION:-1.7.2} PAM_VERSION=${PAM_VERSION:-1.7.2}
NIX_VERSION=${NIX_VERSION:-2.34.0}
NIX_SYSTEM=${NIX_SYSTEM:-x86_64-linux}
DESKTOP=${DESKTOP:-console} DESKTOP=${DESKTOP:-console}
ENABLE_DESKTOP=${ENABLE_DESKTOP:-0} ENABLE_DESKTOP=${ENABLE_DESKTOP:-0}
ENABLE_DOOM_EMACS=${ENABLE_DOOM_EMACS:-0} ENABLE_DOOM_EMACS=${ENABLE_DOOM_EMACS:-0}
@@ -32,9 +34,9 @@ if [[ -z "${IMAGE_SIZE_MIB:-}" ]]; then
if [[ "$DESKTOP" == "gnome" ]]; then if [[ "$DESKTOP" == "gnome" ]]; then
IMAGE_SIZE_MIB=12288 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)$ || "$ENABLE_DOOM_EMACS" =~ ^(1|true|TRUE|yes|YES|on|ON)$ ]]; then
IMAGE_SIZE_MIB=4096 IMAGE_SIZE_MIB=6144
else else
IMAGE_SIZE_MIB=2048 IMAGE_SIZE_MIB=4096
fi fi
fi fi
ESP_SIZE_MIB=${ESP_SIZE_MIB:-256} ESP_SIZE_MIB=${ESP_SIZE_MIB:-256}
@@ -59,6 +61,8 @@ DBUS_TARBALL="dbus-${DBUS_VERSION}.tar.xz"
DBUS_URL="https://dbus.freedesktop.org/releases/dbus/${DBUS_TARBALL}" DBUS_URL="https://dbus.freedesktop.org/releases/dbus/${DBUS_TARBALL}"
PAM_TARBALL="linux-pam-${PAM_VERSION}.tar.gz" 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" PAM_URL="https://github.com/linux-pam/linux-pam/archive/refs/tags/v${PAM_VERSION}.tar.gz"
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_SUITE=${GNOME_SUITE:-trixie}
GNOME_MIRROR=${GNOME_MIRROR:-http://deb.debian.org/debian} 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_GIT_URL=${DOOM_EMACS_GIT_URL:-https://github.com/doomemacs/doomemacs.git}
@@ -73,6 +77,7 @@ BUSYBOX_SRC_DIR="$SOURCE_DIR/busybox-${BUSYBOX_VERSION}"
SYSTEMD_SRC_DIR="$SOURCE_DIR/systemd-${SYSTEMD_VERSION}" SYSTEMD_SRC_DIR="$SOURCE_DIR/systemd-${SYSTEMD_VERSION}"
DBUS_SRC_DIR="$SOURCE_DIR/dbus-${DBUS_VERSION}" DBUS_SRC_DIR="$SOURCE_DIR/dbus-${DBUS_VERSION}"
PAM_SRC_DIR="$SOURCE_DIR/linux-pam-${PAM_VERSION}" PAM_SRC_DIR="$SOURCE_DIR/linux-pam-${PAM_VERSION}"
NIX_SRC_DIR="$SOURCE_DIR/nix-${NIX_VERSION}-${NIX_SYSTEM}"
KERNEL_BUILD_DIR="$BUILD_DIR/linux-${KERNEL_VERSION}" KERNEL_BUILD_DIR="$BUILD_DIR/linux-${KERNEL_VERSION}"
BUSYBOX_BUILD_DIR="$BUILD_DIR/busybox-${BUSYBOX_VERSION}" BUSYBOX_BUILD_DIR="$BUILD_DIR/busybox-${BUSYBOX_VERSION}"
SYSTEMD_BUILD_DIR="$BUILD_DIR/systemd-${SYSTEMD_VERSION}" SYSTEMD_BUILD_DIR="$BUILD_DIR/systemd-${SYSTEMD_VERSION}"
+2
View File
@@ -12,11 +12,13 @@ download "$BUSYBOX_URL" "$DOWNLOAD_DIR/$BUSYBOX_TARBALL"
download "$SYSTEMD_URL" "$DOWNLOAD_DIR/$SYSTEMD_TARBALL" download "$SYSTEMD_URL" "$DOWNLOAD_DIR/$SYSTEMD_TARBALL"
download "$DBUS_URL" "$DOWNLOAD_DIR/$DBUS_TARBALL" download "$DBUS_URL" "$DOWNLOAD_DIR/$DBUS_TARBALL"
download "$PAM_URL" "$DOWNLOAD_DIR/$PAM_TARBALL" download "$PAM_URL" "$DOWNLOAD_DIR/$PAM_TARBALL"
download "$NIX_URL" "$DOWNLOAD_DIR/$NIX_TARBALL"
extract_tarball "$DOWNLOAD_DIR/$KERNEL_TARBALL" "$KERNEL_SRC_DIR" extract_tarball "$DOWNLOAD_DIR/$KERNEL_TARBALL" "$KERNEL_SRC_DIR"
extract_tarball "$DOWNLOAD_DIR/$BUSYBOX_TARBALL" "$BUSYBOX_SRC_DIR" extract_tarball "$DOWNLOAD_DIR/$BUSYBOX_TARBALL" "$BUSYBOX_SRC_DIR"
extract_tarball_into "$DOWNLOAD_DIR/$SYSTEMD_TARBALL" "$SYSTEMD_SRC_DIR" extract_tarball_into "$DOWNLOAD_DIR/$SYSTEMD_TARBALL" "$SYSTEMD_SRC_DIR"
extract_tarball "$DOWNLOAD_DIR/$DBUS_TARBALL" "$DBUS_SRC_DIR" extract_tarball "$DOWNLOAD_DIR/$DBUS_TARBALL" "$DBUS_SRC_DIR"
extract_tarball_into "$DOWNLOAD_DIR/$PAM_TARBALL" "$PAM_SRC_DIR" extract_tarball_into "$DOWNLOAD_DIR/$PAM_TARBALL" "$PAM_SRC_DIR"
extract_tarball_into "$DOWNLOAD_DIR/$NIX_TARBALL" "$NIX_SRC_DIR"
msg "sources are ready" msg "sources are ready"
+209
View File
@@ -0,0 +1,209 @@
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/common.sh"
require_cmd chmod find head install ln mkdir rsync sort tar
ensure_dirs
[[ "$ARCH" == "x86_64" ]] || die "Nix rootfs staging currently supports ARCH=x86_64 only"
[[ "$NIX_SYSTEM" == "x86_64-linux" ]] || die "Nix rootfs staging currently supports NIX_SYSTEM=x86_64-linux only"
[[ -d "$ROOTFS_STAGING_DIR" ]] || die "missing rootfs staging tree: $ROOTFS_STAGING_DIR"
if [[ ! -d "$NIX_SRC_DIR/store" || ! -f "$NIX_SRC_DIR/.reginfo" ]]; then
"$ROOT_DIR/scripts/fetch-sources.sh"
fi
[[ -d "$NIX_SRC_DIR/store" ]] || die "missing Nix store payload: $NIX_SRC_DIR/store"
[[ -f "$NIX_SRC_DIR/.reginfo" ]] || die "missing Nix registration info: $NIX_SRC_DIR/.reginfo"
nix_store_name=$(find "$NIX_SRC_DIR/store" -mindepth 1 -maxdepth 1 -type d -name "*-nix-${NIX_VERSION}" -printf '%f\n' | LC_ALL=C sort | head -n 1)
nix_manual_name=$(find "$NIX_SRC_DIR/store" -mindepth 1 -maxdepth 1 -type d -name "*-nix-manual-${NIX_VERSION}-man" -printf '%f\n' | LC_ALL=C sort | head -n 1)
nix_cacert_name=$(find "$NIX_SRC_DIR/store" -mindepth 1 -maxdepth 1 -type d -name "*-nss-cacert-*" -printf '%f\n' | LC_ALL=C sort | head -n 1)
[[ -n "$nix_store_name" ]] || die "could not locate nix-${NIX_VERSION} store path in $NIX_SRC_DIR/store"
[[ -n "$nix_manual_name" ]] || die "could not locate nix manual store path in $NIX_SRC_DIR/store"
[[ -n "$nix_cacert_name" ]] || die "could not locate nss-cacert store path in $NIX_SRC_DIR/store"
nix_store_path="/nix/store/$nix_store_name"
nix_manual_path="/nix/store/$nix_manual_name"
nix_cacert_path="/nix/store/$nix_cacert_name"
msg "staging Nix $NIX_VERSION as the core package manager"
mkdir -p \
"$ROOTFS_STAGING_DIR/nix/store" \
"$ROOTFS_STAGING_DIR/nix/var/log/nix/drvs" \
"$ROOTFS_STAGING_DIR/nix/var/nix/bootstrap" \
"$ROOTFS_STAGING_DIR/nix/var/nix/db" \
"$ROOTFS_STAGING_DIR/nix/var/nix/gcroots/per-user" \
"$ROOTFS_STAGING_DIR/nix/var/nix/profiles/per-user" \
"$ROOTFS_STAGING_DIR/nix/var/nix/temproots" \
"$ROOTFS_STAGING_DIR/nix/var/nix/userpool" \
"$ROOTFS_STAGING_DIR/nix/var/nix/daemon-socket" \
"$ROOTFS_STAGING_DIR/etc/nix" \
"$ROOTFS_STAGING_DIR/etc/profile.d" \
"$ROOTFS_STAGING_DIR/etc/systemd/system" \
"$ROOTFS_STAGING_DIR/usr/bin" \
"$ROOTFS_STAGING_DIR/usr/lib/forgeos" \
"$ROOTFS_STAGING_DIR/usr/lib/tmpfiles.d"
rsync -a "$NIX_SRC_DIR/store/" "$ROOTFS_STAGING_DIR/nix/store/"
install -m 0644 "$NIX_SRC_DIR/.reginfo" "$ROOTFS_STAGING_DIR/nix/var/nix/bootstrap/reginfo"
chmod 1775 "$ROOTFS_STAGING_DIR/nix/store"
chmod -R ugo-w "$ROOTFS_STAGING_DIR/nix/store"/* 2>/dev/null || true
chmod 0755 \
"$ROOTFS_STAGING_DIR/nix" \
"$ROOTFS_STAGING_DIR/nix/var" \
"$ROOTFS_STAGING_DIR/nix/var/nix" \
"$ROOTFS_STAGING_DIR/nix/var/nix/bootstrap" \
"$ROOTFS_STAGING_DIR/nix/var/nix/daemon-socket"
for tool in nix nix-build nix-channel nix-collect-garbage nix-copy-closure nix-daemon nix-env nix-instantiate nix-shell nix-store; do
if [[ -x "$ROOTFS_STAGING_DIR$nix_store_path/bin/$tool" ]]; then
ln -sfn "$nix_store_path/bin/$tool" "$ROOTFS_STAGING_DIR/usr/bin/$tool"
fi
done
if [[ -e "$ROOTFS_STAGING_DIR/usr/sbin/nologin" ]]; then
ln -sfn ../usr/sbin/nologin "$ROOTFS_STAGING_DIR/sbin/nologin"
fi
cat > "$ROOTFS_STAGING_DIR/etc/nix/nix.conf" <<'EOF'
build-users-group = nixbld
allowed-users = *
trusted-users = root
substituters = https://cache.nixos.org/
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
experimental-features = nix-command flakes
ssl-cert-file = /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt
max-jobs = auto
sandbox = false
EOF
cat > "$ROOTFS_STAGING_DIR/etc/profile.d/nix.sh" <<EOF
# ForgeOS provides Nix as the core package manager through nix-daemon.
export NIX_REMOTE=\${NIX_REMOTE:-daemon}
if [ -e /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]; then
. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
elif [ -e "$nix_store_path/etc/profile.d/nix-daemon.sh" ]; then
. "$nix_store_path/etc/profile.d/nix-daemon.sh"
fi
EOF
cat > "$ROOTFS_STAGING_DIR/usr/lib/forgeos/nix-bootstrap" <<EOF
#!/bin/sh
set -eu
PATH=/usr/bin:/usr/sbin:/bin:/sbin
export PATH
NIX_STORE_PATH="$nix_store_path"
NIX_MANUAL_PATH="$nix_manual_path"
NIX_CACERT_PATH="$nix_cacert_path"
NIX_STATE=/nix/var/nix
REGINFO="\$NIX_STATE/bootstrap/reginfo"
MARKER="\$NIX_STATE/forgeos-bootstrap-complete"
mkdir -p \\
/nix/store \\
/nix/var/log/nix/drvs \\
"\$NIX_STATE/bootstrap" \\
"\$NIX_STATE/db" \\
"\$NIX_STATE/gcroots/per-user" \\
"\$NIX_STATE/profiles/per-user" \\
"\$NIX_STATE/temproots" \\
"\$NIX_STATE/userpool" \\
"\$NIX_STATE/daemon-socket" \\
/root
chown root:root /nix /nix/var /nix/var/nix /nix/var/log /nix/var/log/nix /nix/var/log/nix/drvs 2>/dev/null || true
chown -R root:nixbld /nix/store 2>/dev/null || true
chmod 1775 /nix/store
chmod -R ugo-w /nix/store/* 2>/dev/null || true
chmod 0755 "\$NIX_STATE" "\$NIX_STATE/bootstrap" "\$NIX_STATE/daemon-socket"
if [ -e "\$MARKER" ]; then
exit 0
fi
if [ ! -s "\$REGINFO" ]; then
echo "missing Nix registration info at \$REGINFO" >&2
exit 1
fi
export HOME=/root
export USER=root
export NIX_CONF_DIR=/etc/nix
"\$NIX_STORE_PATH/bin/nix-store" --load-db < "\$REGINFO"
"\$NIX_STORE_PATH/bin/nix-env" -p /nix/var/nix/profiles/default -i "\$NIX_STORE_PATH" "\$NIX_MANUAL_PATH" "\$NIX_CACERT_PATH"
printf '%s\n' 'https://channels.nixos.org/nixpkgs-unstable nixpkgs' > /root/.nix-channels
touch "\$MARKER"
EOF
chmod 0755 "$ROOTFS_STAGING_DIR/usr/lib/forgeos/nix-bootstrap"
cat > "$ROOTFS_STAGING_DIR/etc/systemd/system/forgeos-nix-bootstrap.service" <<'EOF'
[Unit]
Description=Bootstrap ForgeOS Nix store
DefaultDependencies=no
After=local-fs.target
Before=sockets.target multi-user.target
ConditionPathExists=/nix/var/nix/bootstrap/reginfo
ConditionPathExists=!/nix/var/nix/forgeos-bootstrap-complete
[Service]
Type=oneshot
ExecStart=/usr/lib/forgeos/nix-bootstrap
RemainAfterExit=yes
[Install]
WantedBy=sysinit.target
EOF
cat > "$ROOTFS_STAGING_DIR/etc/systemd/system/nix-daemon.service" <<EOF
[Unit]
Description=Nix package manager daemon
Documentation=man:nix-daemon https://nixos.org/manual
After=forgeos-nix-bootstrap.service
RequiresMountsFor=/nix/store
RequiresMountsFor=/nix/var
RequiresMountsFor=/nix/var/nix/db
ConditionPathIsReadWrite=/nix/var/nix/daemon-socket
[Service]
ExecStart=$nix_store_path/bin/nix-daemon --daemon
KillMode=process
LimitNOFILE=1048576
TasksMax=1048576
Delegate=yes
[Install]
WantedBy=multi-user.target
EOF
cat > "$ROOTFS_STAGING_DIR/etc/systemd/system/nix-daemon.socket" <<'EOF'
[Unit]
Description=Nix package manager daemon socket
Before=multi-user.target
RequiresMountsFor=/nix/store
ConditionPathIsReadWrite=/nix/var/nix/daemon-socket
[Socket]
ListenStream=/nix/var/nix/daemon-socket/socket
[Install]
WantedBy=sockets.target
EOF
cat > "$ROOTFS_STAGING_DIR/usr/lib/tmpfiles.d/nix-daemon.conf" <<'EOF'
d /nix/var/nix/daemon-socket 0755 root root - -
d /nix/var/nix/builds 0755 root root 7d -
EOF
printf 'Nix %s (%s)\n' "$NIX_VERSION" "$NIX_SYSTEM" > "$ROOTFS_STAGING_DIR/etc/forgeos-nix"
msg "Nix staged from $nix_store_path"