Skip to content
Carlos Hernandez edited this page Oct 15, 2026 · 4 revisions

pkg (macOS .pkg)

The pkg format builds a flat product-archive .pkg that installs a file tree onto a Mac. embala authors the archive directly — the same shape Apple's productbuild emits — so you can build a .pkg on any OS, no macOS host or Xcode tooling required.

The honest scope up front: a .pkg here is a file-drop installer. It lays your files down under an install location, optionally runs a preinstall and postinstall script you supply, and records a receipt so the system knows the files are there. macOS ships no uninstaller for it, and embala adds none either. If you need a double-click uninstall, this format is the wrong tool; see Limitations.

What you get

A single artifact named <name>-<version>.pkg (from [package].name and [package].version). Installing it copies the payload tree under your install-location — which must be an absolute path — and writes a receipt under your [package].identifier so pkgutil can report and later forget it.

Two ways to install:

How Command
Double-click Opens the standard macOS Installer.app GUI.
Scripted sudo installer -pkg hello-1.0.0.pkg -target /

-target / installs into the local system domain (the default), which is why it needs sudo.

The standard Installer wizard, opened on macOS 26:

Installer.app showing the package

Payload facts

Every file in the archive is normalized the same way, regardless of the machine that built it:

Fact Behavior
Ownership Fixed root:wheel (uid 0, gid 0) on every file and directory.
File mode The entry's mode if set (e.g. 0o600); otherwise derived from the source file's exec bit: executable source → 0755, otherwise 0644.
Directory mode 0755, unless declared in directories with a mode.
Apple Silicon Installs without Rosetta. The archive declares both x86_64 and arm64 host architectures, so Installer never assumes an Intel-only payload.
Relocatable No — the payload always lands at install-location.

Because ownership, timestamps, and ordering are all pinned, the build is deterministic: the same inputs produce a byte-identical .pkg.

Installing into the user's home (enable-user-home)

By default a .pkg installs into the system domain and needs sudo. Set enable-user-home = true and the package also becomes installable into the user's home domain — no sudo required:

installer -pkg hello-1.0.0.pkg -target CurrentUserHomeDirectory

This adds the CurrentUserHome domain to the package; the system-domain (-target /) install still works as before. Its primary use is user-scope and test installs — installing without elevation, e.g. in CI or a throwaway account, then tearing it back down.

Install scripts (scripts)

scripts names a directory, relative to the config file, that embala packs the way pkgbuild --scripts does:

[pkg]
install-location = "/usr/local"
scripts = "scripts"
files = [{ src = "dist/hello", dest = "bin/hello" }]
  • A top-level preinstall runs before the payload is laid down, and a top-level postinstall runs after. Either or both may be present. Installer gives each one pkgbuild's default 600-second timeout.
  • Everything else in the directory ships alongside them (helper scripts, subdirectories, data files), so a hook can call or source files next to it.
  • Each script keeps its exec bit: an executable source installs 0755, anything else 0644. Symlinks are followed.
  • A preinstall or postinstall that isn't executable fails the build. pkgbuild would package it anyway, and installer would then fail on the target machine.
  • On a Windows build host there is no exec bit to read, so embala treats a file as executable if it starts with #! or is a Mach-O binary. Give hook scripts a shebang line.

Installer runs the hooks with the usual arguments: $1 is the package path, $2 the install location (under your home directory for a home install), and $3 the target volume. They run as root for a system-domain install, and as you for a CurrentUserHomeDirectory install.

Config

The [pkg] section of embala.toml:

Field Required Meaning
files yes Payload entries. Each is { src, dest, mode }: src is relative to the config file's directory; dest is the /-separated path relative to install-location; mode is optional permission bits such as 0o600.
directories no Directories to ship with a mode, each { dest, mode }. A declared directory ships even if nothing is under it. mode defaults to 0755.
install-location yes Absolute path the payload installs under (e.g. /usr/local). Must start with /, or the build fails.
enable-user-home no false by default. When true, allows the sudo-free CurrentUserHomeDirectory install described above.
scripts no Directory of install scripts, relative to the config file. See Install scripts.
[package]
name = "hello"
version = "1.0.0"
identifier = "com.example.hello"
display-name = "Hello"
# ...

[pkg]
install-location = "/usr/local"
enable-user-home = true
files = [
  { src = "dist/hello", dest = "bin/hello" },
  { src = "dist/README", dest = "share/hello/README" },
]

With the config above, dist/hello (executable) installs to /usr/local/bin/hello mode 0755, owned root:wheel; README to /usr/local/share/hello/README mode 0644. Intermediate directories (bin, share, share/hello) are created for you.

Private files and directories (mode, directories)

A file that must not be world-readable, or a directory only root may enter, gets an explicit mode:

[pkg]
install-location = "/Library/Example"
files = [{ src = "credentials", dest = "app/credentials", mode = 0o600 }]
directories = [{ dest = "keys", mode = 0o700 }]

app/credentials installs 0600 and keys/ installs 0700, empty; app/ is implied and stays 0755. Modes come from the config, not the source file on disk: git keeps only the exec bit, and Windows hosts have none, so this keeps the result the same on every build host. Only permission bits (0o000-0o777) are allowed.

Upgrades: Installer applies a file's mode even when the file already exists, but it leaves an existing directory's mode alone. If keys/ is already there at 0755, installing this package keeps it 0755 (a pkgbuild-built package does the same). A fresh install gets 0700. If existing machines need the tighter mode, chmod it in a postinstall script.

Payload rules enforced at build time:

  • dest must be a relative path with no empty or .. segments.
  • No two entries (files or directories) may share a dest, and a file dest can't also be a declared directory or the parent of another dest.
  • mode must be 0o000-0o777: setuid, setgid and sticky bits are rejected.
  • At least one file is required.

The Installer window title comes from [package].display-name.

Signing

A finished .pkg can be signed by adding a [sign.macos] command — embala signs the archive after building it. See Code-Signing for the command, tool notes, and what Gatekeeper actually does with the result.

Limitations

These are deliberate scope decisions, not defects:

  • Single component, non-relocatable. One payload, one fixed install location. No multi-component choices, no user-relocatable install path.

  • No uninstaller. macOS has no native uninstall for a .pkg, and embala adds nothing on top. Uninstalling is manual: remove the installed files, then forget the receipt so pkgutil no longer reports the package.

    System-domain install (-target /):

    sudo rm -rf /usr/local/bin/hello /usr/local/share/hello
    sudo pkgutil --forget com.example.hello

    Home-domain install (-target CurrentUserHomeDirectory) — no sudo. The install prefixes install-location with your home directory (so the example above lands under ~/usr/local), and the receipt lives on the user volume:

    rm -rf ~/usr/local/bin/hello ~/usr/local/share/hello
    pkgutil --volume ~ --forget com.example.hello

    Adapt the rm paths to your own install-location and dest entries. pkgutil --pkg-info <identifier> (add --volume ~ for a home install) lists what a receipt covers if you need to check before removing.

See also

Clone this wiki locally