---
title: "Source RPMs"
linkTitle: Source RPMs
weight: 50
---

{{< g_version "v2.15" >}}

GoReleaser can generate Source RPM (`.src.rpm`) packages.

Source RPMs are the standard way to distribute software source code for RPM-based
Linux distributions (Fedora, RHEL, CentOS, etc.). They contain the source code
archive and a `.spec` file that describes how to build binary RPMs from the source.

> [!WARNING]
> Source RPM generation is an **alpha** feature.
> You must write your own `.spec` file template — GoReleaser does not provide a
> default template because the content of `.spec` files varies considerably
> between projects.

> [!NOTE]
> Source RPMs require a [source archive][sourcearchive] to be configured.
> Make sure to enable `source.enabled: true` and set
> `source.prefix_template` appropriately in your configuration.

## Configuration

```yaml {filename=".goreleaser.yaml"}
srpm:
  # Whether to enable source RPM generation.
  #
  # Default: false.
  enabled: true

  # Name of the source RPM package.
  #
  # Default: ProjectName.
  package_name: myproject

  # RPM epoch.
  epoch: "1"

  # RPM section.
  section: devel

  # Package maintainer.
  maintainer: My Name <me@example.com>

  # Path to the .spec file Go template.
  # This file is required and must be provided by you.
  spec_file: myproject.spec.tmpl

  # Template for the source RPM file name.
  #
  # Default: '{{ .PackageName }}-{{ .Version }}.src.rpm'.
  # Templates: allowed.
  file_name_template: "{{ .ConventionalFileName }}.src.rpm"

  # Import path for the Go package (used in Fedora-style spec templates).
  import_path: github.com/myorg/myproject

  # One-line summary of the package.
  summary: My project summary

  # License identifier.
  license: MIT

  # Name of the license file to include.
  license_file_name: LICENSE

  # URL of the project homepage.
  url: https://myproject.example.com

  # Long description of the package.
  description: |
    A longer description of my project.

  # The person or organization that built this package.
  packager: My Name <me@example.com>

  # Software vendor name.
  vendor: My Organization

  # Map of binary names to their Go import paths for %gobuild directives.
  # The key is the binary name, the value is the Go import path.
  #
  # Default: { ProjectName: '%{goipath}' }.
  bins:
    myproject: github.com/myorg/myproject/cmd/myproject

  # List of documentation files to include.
  docs:
    - README.md
    - CHANGELOG.md

  # RPM-specific fields, shared with nfpms[].rpm.
  group: Applications/Internet
  compression: lzma

  # Signature configuration.
  #
  # If the key is password-protected, you'll need to set the `%SRPM_PASSPHRASE`
  # environment variable when calling GoReleaser.
  signature:
    # Templates: allowed.
    key_file: "{{ .Env.GPG_KEY_FILE }}"

  # Extra files to include in the SRPM beyond the source archive and spec file.
  # The `src`, `dst`, `file_info.owner`, `file_info.group`, and `file_info.mtime`
  # fields support templates.
  contents:
    - src: "{{ .Env.PATCH_DIR }}/fix-build-{{ .Version }}.patch"
      dst: "fix-build-{{ .Version }}.patch"
      type: config
      packager: rpm
      file_info:
        owner: mockbuild
        group: mockbuild
        mode: 0644
        mtime: "2006-01-02T15:04:05Z"
```

## Spec file template

You must provide a `.spec` file template. The template is rendered using
[Go's text/template][gotmpl] with the following variables available:

| Variable           | Description                         |
| ------------------ | ----------------------------------- |
| `.Version`         | The release version                 |
| `.FullCommit`      | The full git commit SHA             |
| `.PackageName`     | The package name                    |
| `.ImportPath`      | The Go import path                  |
| `.Summary`         | One-line summary                    |
| `.License`         | License identifier                  |
| `.LicenseFileName` | License file name                   |
| `.URL`             | Project homepage URL                |
| `.Description`     | Long description                    |
| `.Packager`        | Packager name                       |
| `.Vendor`          | Vendor name                         |
| `.Group`           | RPM group                           |
| `.Epoch`           | RPM epoch                           |
| `.Section`         | Section                             |
| `.Maintainer`      | Maintainer                          |
| `.Source`          | Source archive file name            |
| `.Bins`            | Map of binary names to import paths |
| `.Docs`            | List of documentation files         |

All standard [GoReleaser template variables][tmpl] are also available.

A minimal example for a Fedora-style Go project:

```spec {filename="myproject.spec.tmpl"}
# Generated by goreleaser
%bcond_without check

%global goipath         {{ .ImportPath }}
%global commit          {{ .FullCommit }}

%gometa -f

%global common_description %{expand:
{{ .Description }}}

{{ if .LicenseFileName }}%global golicenses      {{ .LicenseFileName }}{{ end }}
{{ if .Docs }}%global godocs         {{ range .Docs }} {{ . }}{{ end }}{{ end }}

Name:           %{goname}
Version:        {{ .Version }}
Release:        %autorelease -p
Summary:        {{ .Summary }}

License:        {{ .License }}
URL:            {{ .URL }}
Source:         {{ .Source }}

%description %{common_description}

%gopkg

%prep
%goprep

%generate_buildrequires
%go_generate_buildrequires

%build
{{ range $binary, $importPath := .Bins }}
%gobuild -o %{gobuilddir}/bin/{{ $binary }} {{ $importPath }}
{{ end }}

%install
%gopkginstall
install -m 0755 -vd                     %{buildroot}%{_bindir}
install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/

%if %{with check}
%check
%gocheck
%endif

%files
{{ range .Docs }}%doc {{ . }}
{{ end }}
{{ if .LicenseFileName }}%license {{ .LicenseFileName }}{{ end }}
%{_bindir}/*

%gopkgfiles

%changelog
%autochangelog
```

[sourcearchive]: /customization/package/source/
[gotmpl]: https://pkg.go.dev/text/template
[tmpl]: /customization/general/templates/
