Provides rules for creating RPM packages via pkg_filegroup and friends.

pkg_rpm() depends on the existence of an rpmbuild toolchain. Many users will find to convenient to use the one provided with their system. To enable that toolchain add the following stanza to WORKSPACE:

# Find rpmbuild if it exists.
load("@rules_pkg//toolchains/rpm:rpmbuild_configure.bzl", "find_system_rpmbuild")



Creates an RPM format package via pkg_filegroup and friends.

The uses the outputs of the rules in mappings.bzl to construct arbitrary RPM packages. Attributes of this rule provide preamble information and scriptlets, which are then used to compose a valid RPM spec file.

This rule will fail at analysis time if:

  • Any srcs input creates the same destination, regardless of other attributes.

This rule only functions on UNIXy platforms. The following tools must be available on your system for this to function properly:

  • rpmbuild (as specified in rpmbuild_path, or available in $PATH)

  • GNU coreutils. BSD coreutils may work, but are not tested.

To set RPM file attributes (like %config and friends), set the rpm_filetag in corresponding packaging rule (pkg_files, etc). The value is prepended with "%" and added to the %files list, for example:

attrs = {"rpm_filetag": ("config(missingok, noreplace)",)},

Is the equivalent to %config(missingok, noreplace) in the %files list.

Example usage (generated)

load("@rules_pkg//pkg:rpm_pfg.bzl", "pkg_rpm")

    # A unique name for this target.
    name = "",
    # RPM "License" tag
    license = "",
    # Mapping groups to include in this RPM
    srcs = [],
    # RPM "Summary" tag
    summary = "",


A unique name for this target.


Package architecture.

This currently sets the BuildArch tag, which influences the output architecture of the package.

Typically, BuildArch only needs to be set when the package is known to be cross-platform (e.g. written in an interpreted language), or, less common, when it is known that the application is only valid for specific architectures.

When no attribute is provided, this will default to your host's architecture. This is usually what you want.


Compression mode used for this RPM

Must be a form that rpmbuild(8) knows how to process, which will depend on the version of rpmbuild in use. The value corresponds to the %_binary_payload macro and is set on the rpmbuild(8) command line if provided.

Some examples of valid values (which may not be supported on your system) can be found here. On CentOS systems (also likely Red Hat and Fedora), you can find some supported values by looking for %_binary_payload in /usr/lib/rpm/macros. Other systems have similar files and configurations.

If not provided, the compression mode will be computed by rpmbuild itself. Defaults may vary per distribution or build of rpm; consult the relevant documentation for more details.

WARNING: Bazel is currently not aware of action threading requirements for non-test actions. Using threaded compression may result in overcommitting your system.



List of capabilities that conflict with this package when it is installed.

Corresponds to the "Conflicts" preamble tag.

See also:


Debug the RPM helper script and RPM generation


Multi-line description of this package, corresponds to RPM %description.

Exactly one of description or description_file must be provided.


File containing a multi-line description of this package, corresponds to RPM %description.


Optional; RPM "Group" tag.

NOTE: some distributions (as of writing, Fedora > 17 and CentOS/RHEL

  1. have deprecated this tag. Other distributions may require it, but it is harmless in any case.


RPM "License" tag.

The software license for the code distributed in this package.

The underlying RPM builder requires you to put something here; if your package is not going to be distributed, feel free to set this to something like "Internal".


See 'Common Attributes' in the rules_pkg reference.

If this is not provided, the package file given a NVRA-style (name-version-release.arch) output, which is preferred by most RPM repositories.


Optional; RPM name override.

If not provided, the name attribute of this rule will be used instead.

This influences values like the spec file name.


See 'Common Attributes' in the rules_pkg reference


RPM %post scriptlet. Currently only allowed to be a shell script.

post_scriptlet and post_scriptlet_file are mutually exclusive.


File containing the RPM %post scriptlet


RPM %postun scriptlet. Currently only allowed to be a shell script.

postun_scriptlet and postun_scriptlet_file are mutually exclusive.


File containing the RPM %postun scriptlet


RPM %pre scriptlet. Currently only allowed to be a shell script.

pre_scriptlet and pre_scriptlet_file are mutually exclusive.


File containing the RPM %pre scriptlet


RPM %preun scriptlet. Currently only allowed to be a shell script.

preun_scriptlet and preun_scriptlet_file are mutually exclusive.


File containing the RPM %preun scriptlet


List of rpm capabilities that this package provides.

Corresponds to the "Provides" preamble tag.

See also:


RPM "Release" tag

Exactly one of release or release_file must be provided.


File containing RPM "Release" tag.


List of rpm capability expressions that this package requires.

Corresponds to the "Requires" preamble tag.

See also:


Contextualized requirement specifications

This is a map of various properties (often scriptlet types) to capability name specifications, e.g.:

{"pre": ["GConf2"],"post": ["GConf2"], "postun": ["GConf2"]}

Which causes the below to be added to the spec file's preamble:

Requires(pre): GConf2
Requires(post): GConf2
Requires(postun): GConf2

This is most useful for ensuring that required tools exist when scriptlets are run, although there may be other valid use cases. Valid keys for this attribute may include, but are not limited to:

  • pre
  • post
  • preun
  • postun
  • pretrans
  • posttrans

For capabilities that are always required by packages at runtime, use the requires attribute instead.

See also:

NOTE: pkg_rpm does not check if the keys of this dictionary are acceptable to rpm(8).


Path to a rpmbuild binary. Deprecated in favor of the rpmbuild toolchain


Value to export as SOURCE_DATE_EPOCH to facilitate reproducible builds

Implicitly sets the %clamp_mtime_to_source_date_epoch in the subordinate call to rpmbuild to facilitate more consistent in-RPM file timestamps.

Negative values (like the default) disable this feature.


File containing the SOURCE_DATE_EPOCH value.

Implicitly sets the %clamp_mtime_to_source_date_epoch in the subordinate call to rpmbuild to facilitate more consistent in-RPM file timestamps.


Spec file template.

Use this if you need to add additional logic to your spec files that is not available by default.

In most cases, you should not need to override this attribute.


Mapping groups to include in this RPM.

These are typically brought into life as pkg_filegroups.


RPM "Summary" tag.

One-line summary of this package. Must not contain newlines.


RPM "URL" tag; this project/vendor's home on the Internet.


RPM "Version" tag.

Exactly one of version or version_file must be provided.


File containing RPM "Version" tag.