Last updated:

genpack.json5 Specification Reference

Overview

genpack.json5 is a declarative definition file for system images built with genpack. It is placed in the root directory of each artifact and consolidates package configuration, Portage settings, user/service definitions, compression methods, and more into a single file.

The format is JSON5, which supports comments, trailing commas, and other conveniences. If genpack.json5 does not exist, it falls back to genpack.json, but if both exist, an error is raised.

Minimal Configuration

{
  packages: ["genpack/paravirt"]
}

If name is omitted, the directory name is used automatically (with a warning).

Field Reference

Basic Fields

name

profile

Common profiles:

ProfileUse Case
paravirtFor QEMU/KVM virtual machines (virtio, guest agent)
baremetalFor physical machines (BIOS/UEFI, device drivers)
gnome/baremetalPhysical machine + GNOME desktop
weston/paravirtVirtual machine + Wayland (Weston)

outfile

compression

Package-Related

packages

Adding a - prefix excludes the package from the list when merging with profiles or variants:

{
  packages: [
    "genpack/paravirt",
    "app-misc/screen",
    "-app-misc/unwanted-package"  // Exclude from merge source
  ]
}

buildtime_packages

{
  buildtime_packages: ["dev-lang/go", "dev-build/cmake"]
}

binpkg_excludes

Portage Settings

use

Keys are package atoms (*/* for global settings), and values are strings (space-separated) or lists:

{
  use: {
    "dev-lang/php": "+mysql +curl +gd +xml +zip",
    "media-libs/mesa": "wayland VIDEO_CARDS: virgl",
    "*/*": "python_targets_python3_12"
  }
}

USE_EXPAND variables such as CPU_FLAGS_X86:, VIDEO_CARDS:, AMDGPU_TARGETS:, and APACHE2_MODULES: are also configured through this field.

accept_keywords

When the value is null, it means no keyword restriction (the standard pattern for accepting testing versions):

{
  accept_keywords: {
    "dev-util/debootstrap": null,      // Accept ~arch
    "app-misc/package": "~amd64",      // Specific keyword
    "app-misc/other": ["~amd64", "**"] // Multiple keywords
  }
}

mask

{
  mask: [">=dev-db/mysql-8"]
}

license

{
  license: {
    "sys-kernel/linux-firmware": "linux-fw-redistributable",
    "www-client/google-chrome": "google-chrome"
  }
}

env

{
  env: {
    "sci-libs/pytorch": "torch_cuda.conf"
  }
}

Users and Groups

users

{
  users: [
    "simpleuser",
    {
      name: "advanceduser",
      uid: 1000,
      home: "/home/advanceduser",
      shell: "/bin/bash",
      initial_group: "users",
      additional_groups: ["wheel", "video", "audio"],
      create_home: true,
      empty_password: true
    }
  ]
}

Object format properties:

PropertyTypeDefaultDescription
namestring(required)Username
uidinteger(auto)User ID
commentstringGECOS field
homestringHome directory
shellstringLogin shell
initial_groupstringPrimary group
additional_groupsstring | string[]Additional groups
create_homebooleantrueWhether to create the home directory
empty_passwordbooleanfalseWhether to allow an empty password

groups

{
  groups: [
    "customgroup",
    { name: "groupwithgid", gid: 1002 }
  ]
}

Services and Setup

services

{
  services: [
    "sshd",
    "apache2",
    "fstrim.timer",
    "[email protected]"
  ]
}

setup_commands

{
  setup_commands: [
    "sed -i 's/-D SSL //' /etc/conf.d/apache2",
    "mkdir -p /var/www/localhost/htdocs"
  ]
}

Build Settings

lower-layer-capacity

independent_binpkgs

circulardep_breaker

{
  circulardep_breaker: {
    packages: ["media-libs/freetype", "media-libs/harfbuzz"],
    use: "-truetype -harfbuzz"
  }
}

The packages specified in packages are first installed with the USE flags specified in use, and then rebuilt with the correct flags during the subsequent normal build.

Conditional Settings

arch

Only the settings for keys matching the current machine's architecture (uname -m) are merged.

{
  arch: {
    x86_64: {
      packages: ["app-misc/x86-specific"],
      use: {
        "media-video/ffmpeg": "CPU_FLAGS_X86: avx avx2 sse4_2"
      }
    },
    aarch64: {
      accept_keywords: {
        "app-emulation/qemu-guest-agent": null
      }
    }
  }
}

Mergeable fields: packages, buildtime_packages, accept_keywords, use, mask, license, env, binpkg_excludes, setup_commands, services

variants

{
  packages: ["genpack/gnome"],
  services: ["gdm"],
  variants: {
    paravirt: {
      // packages are merged with the parent definition
      packages: ["-x11-drivers/nvidia-drivers"],
      use: {
        "media-libs/mesa": "VIDEO_CARDS: virgl"
      }
    },
    cuda: {
      packages: ["x11-drivers/nvidia-drivers"],
      use: {
        "sci-libs/pytorch": "CUDA_TARGETS: sm_89"
      }
    }
  }
}

Within a variant, most top-level fields including name, profile, and outfile can be overridden or merged. Additionally, arch can be included within a variant.

default_variant

Merge Behavior

Settings in genpack.json5 are merged in the following order:

  1. Base settings: Top-level fields
  2. Architecture-specific: Settings for the matching architecture within arch are merged
  3. Variant: Settings for the selected variant within variants are merged (including arch within the variant)

Behavior of list-type fields during merging:

Deprecated Field Names

The following hyphenated names are deprecated, and using them will result in an error:

Deprecated NameCurrent Name
buildtime-packagesbuildtime_packages
binpkg-excludebinpkg_excludes
circulardep-breakercirculardep_breaker

Within user objects, hyphenated names are still accepted for compatibility:

Complete Configuration Example

{
  // Basic information
  name: "nextcloud",
  profile: "paravirt",
  compression: "xz",

  // Packages
  packages: [
    "genpack/paravirt",
    "www-apps/nextcloud",
    "dev-db/mysql",
    "dev-lang/php",
    "net-misc/redis",
    "www-servers/apache"
  ],
  buildtime_packages: [
    "app-arch/rpm2targz"
  ],
  binpkg_excludes: ["sys-kernel/gentoo-kernel"],

  // Portage settings
  use: {
    "dev-lang/php": "mysql curl gd xml zip",
    "www-servers/apache": "APACHE2_MODULES: http2 proxy proxy_fcgi"
  },
  accept_keywords: {
    "net-vpn/frp": null
  },
  license: {
    "net-analyzer/fping": "fping",
    "dev-db/redis": "SSPL-1"
  },

  // Users and services
  users: [
    { name: "nextcloud", uid: 1000 }
  ],
  services: ["apache2", "mysqld", "redis"],

  // Setup
  setup_commands: [
    "sed -i 's/-D SSL //' /etc/conf.d/apache2"
  ],

  // Variants
  variants: {
    selftestable: {
      profile: "weston/paravirt",
      packages: ["www-client/google-chrome"],
      users: [
        { name: "user", uid: 1000, empty_password: true }
      ]
    }
  }
}

Source References

This document was written based on the following repository snapshots:

Update History