APGv2 packages support install/remove lifecycle scripts stored in the scripts/ directory within each .apg archive.
pre-install— executed before package installationpost-install— executed after package installationpre-remove— executed before package removalpost-remove— executed after package removal
Add a [scripts] section to your recipe.toml:
[scripts]
postinstall = ["init", "ldconfig"]
preremove = ["init"]
postremove = []
add_to_path = false# Enable and start neoinit service
if [ -f /etc/neoinit/services/package.yaml ]; then
servctl start package || true
fi# Register alternatives with switch (NurOS alternatives manager)
if command -v switch >/dev/null 2>&1; then
switch --install /usr/bin/package package /usr/bin/package 50 || true
fiNote: NurOS uses switch (similar to Gentoo's eselect or Debian's update-alternatives)
Set add_to_path = true to generate /etc/profile.d/<package>.sh:
#!/usr/bin/env sh
# Add package to PATH
export PATH="/usr/lib/package/bin:$PATH"# Reload neoinit services
if command -v servctl >/dev/null 2>&1; then
servctl reload || true
fi# Update library cache
if command -v ldconfig >/dev/null 2>&1; then
ldconfig || true
fi[scripts]
postinstall = ["init", "reload"]
preremove = []
postremove = ["reload"]
[service]
exec = "/usr/bin/nginx -g 'daemon off;'"
description = "Nginx web server"
working_dir = "/var/www"
restart = true
type = "simple"
[service.env]
NGINX_PORT = "80"Generated /etc/neoinit/services/nginx.yaml:
name: nginx
description: Nginx web server
exec: /usr/bin/nginx -g 'daemon off;'
working_dir: /var/www
restart: true
type: simple
env:
- NGINX_PORT=80[scripts]
postinstall = ["update-alternatives", "ldconfig"]
preremove = []
postremove = ["ldconfig"][scripts]
postinstall = []
add_to_path = true # Generates /etc/profile.d/tool.sh[service]
exec = "/usr/bin/mydaemon --config /etc/mydaemon.conf"
description = "My system daemon"
working_dir = "/var/lib/mydaemon"
restart = true
type = "simple"
user = "mydaemon"
group = "mydaemon"
[service.env]
LOG_LEVEL = "info"If no templates are specified, apger generates empty placeholder scripts:
#!/usr/bin/env sh
# APGv2 post-install script (empty)
exit 0This ensures the scripts/ directory is never empty (APGv2 requirement).
Scripts are executed by the package manager during:
- Installation:
pre-install→ extract files →post-install - Removal:
pre-remove→ remove files →post-remove
All scripts run with:
- Shebang:
#!/usr/bin/env sh(portable) - Error handling:
set -e(exit on error) - Permissions:
chmod +x(executable)
NurOS uses neoinit — a microkernel-style init system. Service files should be placed in:
/etc/neoinit/services/<package>.yaml
If your recipe includes a [service] section, apger automatically generates the neoinit YAML configuration:
[service]
exec = "/usr/bin/nginx -g 'daemon off;'"
description = "Nginx web server"
working_dir = "/var/www"
restart = true
type = "simple" # simple | forking | oneshot
user = "nginx" # Optional: run as specific user
group = "nginx" # Optional: run as specific group
[service.env]
NGINX_PORT = "80"
NGINX_WORKERS = "4"Generated /etc/neoinit/services/nginx.yaml:
name: nginx
description: Nginx web server
exec: /usr/bin/nginx -g 'daemon off;'
working_dir: /var/www
restart: true
type: simple
user: nginx
group: nginx
env:
- NGINX_PORT=80
- NGINX_WORKERS=4- simple — process runs in foreground (default)
- forking — process forks to background
- oneshot — runs once and exits
name: nginx
description: Nginx web server
exec: /usr/bin/nginx -g "daemon off;"
working_dir: /var/www
restart: true
type: simple
env:
- NGINX_PORT=80# Start service
servctl start nginx
# Stop service
servctl stop nginx
# Check status
servctl status
# List all services
servctl listNote: neoinit communicates via /run/neoinit.sock
NurOS uses switch for managing alternatives (similar to Gentoo's eselect):
# Install alternative
switch --install /usr/bin/editor editor /usr/bin/vim 50
# List alternatives
switch --list editor
# Select alternative
switch --set editor vimapger generates scripts and passes them to apgbuild:
- apger reads
[scripts]section fromrecipe.toml - Generates shell scripts using templates
- Creates
scripts/directory in each split package - apgbuild includes
scripts/in the.apgarchive
package-1.0.0.apg (tar.zst)
├── usr/
│ ├── bin/
│ └── lib/
├── scripts/
│ ├── pre-install
│ ├── post-install
│ ├── pre-remove
│ └── post-remove
├── metadata.json
└── crc32sums
- Keep scripts minimal — use templates when possible
- Handle failures gracefully — use
|| truefor non-critical commands - Check command availability — use
command -vbefore calling - Use neoinit for services — place YAML definitions in
/etc/neoinit/services/ - Test scripts — verify they work on clean system
View generated scripts:
# Extract package
tar -xf package-1.0.0.apg
# Check scripts
cat scripts/post-install- APGv2 Specification
- neoinit (NurOS init system) — microkernel-style init
- switch (NurOS alternatives manager)
- servctl Documentation