Files
nfpm/nfpm.go
Dj GilcreaseandClaude Opus 5.5 2aa4b1a288 fix(config): isolate macOS overrides, honour empty passphrases, relax schema
- Config.Get deep-copies Info.plist values before merging an override.
  mergo shared the nested dictionaries and arrays, so a dmg override
  changed the base settings and every later app result.
- NFPM_APP_PASSPHRASE and NFPM_PKG_PASSPHRASE set to an empty value now
  select an empty passphrase even when NFPM_PASSPHRASE is set, using the
  presence-aware lookup MSIX uses. A custom mapping still reads nothing
  from the process environment.
- The schema no longer requires app.identifier and pkg.identifier in
  every layer: an override may leave them to the base settings. The
  packagers still require them in the merged settings.
- arch, identifier and min_os_version accept environment expressions in
  the schema; literal values are still checked against the packagers'
  rules, and expanded values are checked when packaging.
- Tests validate real documents against the generated schema with the
  validator the schema:validate task uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 11:35:50 -08:00

997 lines
51 KiB
Go

// Package nfpm provides ways to package programs in some linux packaging
// formats.
package nfpm
import (
"errors"
"fmt"
"io"
"io/fs"
"os"
"slices"
"sort"
"strings"
"sync"
"time"
"dario.cat/mergo"
"github.com/AlekSi/pointer"
"github.com/Masterminds/semver/v3"
"github.com/goreleaser/chglog"
"github.com/goreleaser/nfpm/v2/files"
"github.com/goreleaser/nfpm/v2/internal/modtime"
"go.yaml.in/yaml/v3"
)
// nolint: gochecknoglobals
var (
packagers = map[string]Packager{}
lock sync.Mutex
)
// RegisterPackager a new packager for the given format.
func RegisterPackager(format string, p Packager) {
lock.Lock()
defer lock.Unlock()
packagers[format] = p
}
// ClearPackagers clear all registered packagers, used for testing.
func ClearPackagers() {
lock.Lock()
defer lock.Unlock()
packagers = map[string]Packager{}
}
// ErrNoPackager happens when no packager is registered for the given format.
type ErrNoPackager struct {
format string
}
func (e ErrNoPackager) Error() string {
return fmt.Sprintf("no packager registered for the format %s", e.format)
}
// Get a packager for the given format.
func Get(format string) (Packager, error) {
p, ok := packagers[format]
if !ok {
return nil, ErrNoPackager{format}
}
return p, nil
}
// Enumerate lists the available packagers
func Enumerate() []string {
lock.Lock()
defer lock.Unlock()
list := make([]string, 0, len(packagers))
for key := range packagers {
if key != "" {
list = append(list, key)
}
}
sort.Strings(list)
return list
}
// Parse decodes YAML data from an io.Reader into a configuration struct.
func Parse(in io.Reader) (config Config, err error) {
return parse(in, os.Getenv, os.LookupEnv)
}
// ParseWithEnvMapping decodes YAML data from an io.Reader into a configuration struct.
// Mapping functions cannot distinguish an unset variable from an empty one;
// an empty mapped MSIX passphrase therefore uses the global default.
func ParseWithEnvMapping(in io.Reader, mapping func(string) string) (config Config, err error) {
return parse(in, mapping, nil)
}
func parse(in io.Reader, mapping func(string) string, lookup func(string) (string, bool)) (config Config, err error) {
dec := yaml.NewDecoder(in)
dec.KnownFields(true)
if err = dec.Decode(&config); err != nil {
return config, err
}
config.envMappingFunc = mapping
config.envLookupFunc = lookup
if config.envMappingFunc == nil {
config.envMappingFunc = func(s string) string { return s }
}
config.expandEnvVars()
WithDefaults(&config.Info)
return config, nil
}
// ParseFile decodes YAML data from a file path into a configuration struct.
func ParseFile(path string) (config Config, err error) {
return parseFile(path, os.Getenv, os.LookupEnv)
}
// ParseFileWithEnvMapping decodes YAML data from a file path into a configuration struct.
func ParseFileWithEnvMapping(path string, mapping func(string) string) (config Config, err error) {
return parseFile(path, mapping, nil)
}
func parseFile(path string, mapping func(string) string, lookup func(string) (string, bool)) (config Config, err error) {
if path == "-" {
return parse(os.Stdin, mapping, lookup)
}
var file *os.File
file, err = os.Open(path) //nolint:gosec
if err != nil {
return config, err
}
defer file.Close() // nolint: errcheck,gosec
return parse(file, mapping, lookup)
}
// Packager represents any packager implementation.
type Packager interface {
Package(info *Info, w io.Writer) error
ConventionalFileName(info *Info) string
}
type PackagerWithExtension interface {
Packager
ConventionalExtension() string
}
// Config contains the top level configuration for packages.
type Config struct {
Info `yaml:",inline" json:",inline"`
Overrides map[string]*Overridables `yaml:"overrides,omitempty" json:"overrides,omitempty" jsonschema:"title=overrides,description=override some fields when packaging with a specific packager"`
envMappingFunc func(string) string
envLookupFunc func(string) (string, bool)
}
// Get returns the Info struct for the given packager format. Overrides
// for the given format are merged into the final struct.
func (c *Config) Get(format string) (info *Info, err error) {
info = &Info{}
// make a deep copy of info
if err = mergo.Merge(info, c.Info, mergo.WithOverride); err != nil {
return nil, fmt.Errorf("failed to merge config into info: %w", err)
}
// mergo copies the outer Info.plist map but shares the dictionaries and
// arrays nested in it, and merging an override writes through them. Each
// result gets its own copy so that no format changes another's settings.
info.App.InfoPlist = clonePlist(c.App.InfoPlist)
override, ok := c.Overrides[format]
if !ok || override == nil {
// no overrides, or an empty override clause (e.g. "overrides:\n deb:")
return info, nil
}
isolated := *override
isolated.App.InfoPlist = clonePlist(override.App.InfoPlist)
if err = mergo.Merge(&info.Overridables, isolated, mergo.WithOverride); err != nil {
return nil, fmt.Errorf("failed to merge overrides into info: %w", err)
}
var contents []*files.Content
for _, f := range info.Contents {
if f.Packager == format || f.Packager == "" {
contents = append(contents, f)
}
}
info.Contents = contents
return info, nil
}
// clonePlist returns a deep copy of Info.plist settings.
func clonePlist(values map[string]any) map[string]any {
if values == nil {
return nil
}
copied := make(map[string]any, len(values))
for key, value := range values {
copied[key] = clonePlistValue(value)
}
return copied
}
func clonePlistValue(value any) any {
switch typed := value.(type) {
case map[string]any:
return clonePlist(typed)
case []any:
copied := make([]any, len(typed))
for n, item := range typed {
copied[n] = clonePlistValue(item)
}
return copied
}
return value
}
// Validate ensures that the config is well typed.
func (c *Config) Validate() error {
if err := Validate(&c.Info); err != nil {
return err
}
for format := range c.Overrides {
if _, err := Get(format); err != nil {
return err
}
}
return nil
}
func (c *Config) expandEnvVarsStringSlice(items []string) []string {
for i, dep := range items {
val := strings.TrimSpace(os.Expand(dep, c.envMappingFunc))
items[i] = val
}
for i := 0; i < len(items); i++ {
if items[i] == "" {
items = slices.Delete(items, i, i+1)
i-- // Since we just deleted items[i], we must redo that index
}
}
return items
}
func (c *Config) expandEnvVarsContents(contents files.Contents) files.Contents {
for i := range contents {
f := contents[i]
if !f.Expand {
continue
}
f.Destination = strings.TrimSpace(os.Expand(f.Destination, c.envMappingFunc))
f.Source = strings.TrimSpace(os.Expand(f.Source, c.envMappingFunc))
}
return contents
}
func (c *Config) expandEnvVars() {
// Version related fields
c.Release = os.Expand(c.Release, c.envMappingFunc)
c.Version = os.Expand(c.Version, c.envMappingFunc)
c.Prerelease = os.Expand(c.Prerelease, c.envMappingFunc)
c.Platform = os.Expand(c.Platform, c.envMappingFunc)
c.Arch = os.Expand(c.Arch, c.envMappingFunc)
for or := range c.Overrides {
if c.Overrides[or] == nil {
continue
}
c.Overrides[or].Conflicts = c.expandEnvVarsStringSlice(c.Overrides[or].Conflicts)
c.Overrides[or].Depends = c.expandEnvVarsStringSlice(c.Overrides[or].Depends)
c.Overrides[or].Replaces = c.expandEnvVarsStringSlice(c.Overrides[or].Replaces)
c.Overrides[or].Recommends = c.expandEnvVarsStringSlice(c.Overrides[or].Recommends)
c.Overrides[or].Provides = c.expandEnvVarsStringSlice(c.Overrides[or].Provides)
c.Overrides[or].Suggests = c.expandEnvVarsStringSlice(c.Overrides[or].Suggests)
c.Overrides[or].RPM.Requires.Post = c.expandEnvVarsStringSlice(c.Overrides[or].RPM.Requires.Post)
c.Overrides[or].Contents = c.expandEnvVarsContents(c.Overrides[or].Contents)
}
c.Conflicts = c.expandEnvVarsStringSlice(c.Conflicts)
c.Depends = c.expandEnvVarsStringSlice(c.Depends)
c.Replaces = c.expandEnvVarsStringSlice(c.Replaces)
c.Recommends = c.expandEnvVarsStringSlice(c.Recommends)
c.Provides = c.expandEnvVarsStringSlice(c.Provides)
c.Suggests = c.expandEnvVarsStringSlice(c.Suggests)
c.RPM.Requires.Post = c.expandEnvVarsStringSlice(c.RPM.Requires.Post)
c.Contents = c.expandEnvVarsContents(c.Contents)
// Basic metadata fields
c.Name = os.Expand(c.Name, c.envMappingFunc)
c.Homepage = os.Expand(c.Homepage, c.envMappingFunc)
c.Maintainer = os.Expand(c.Maintainer, c.envMappingFunc)
c.Vendor = os.Expand(c.Vendor, c.envMappingFunc)
c.Description = os.Expand(c.Description, c.envMappingFunc)
// Package signing related fields
c.Deb.Signature.KeyFile = os.Expand(c.Deb.Signature.KeyFile, c.envMappingFunc)
c.RPM.Signature.KeyFile = os.Expand(c.RPM.Signature.KeyFile, c.envMappingFunc)
c.APK.Signature.KeyFile = os.Expand(c.APK.Signature.KeyFile, c.envMappingFunc)
c.Deb.Signature.KeyID = pointer.ToString(os.Expand(pointer.GetString(c.Deb.Signature.KeyID), c.envMappingFunc))
c.RPM.Signature.KeyID = pointer.ToString(os.Expand(pointer.GetString(c.RPM.Signature.KeyID), c.envMappingFunc))
c.APK.Signature.KeyID = pointer.ToString(os.Expand(pointer.GetString(c.APK.Signature.KeyID), c.envMappingFunc))
// Package signing passphrase
generalPassphrase := os.Expand("$NFPM_PASSPHRASE", c.envMappingFunc)
c.Deb.Signature.KeyPassphrase = generalPassphrase
c.RPM.Signature.KeyPassphrase = generalPassphrase
c.APK.Signature.KeyPassphrase = generalPassphrase
debPassphrase := os.Expand("$NFPM_DEB_PASSPHRASE", c.envMappingFunc)
if debPassphrase != "" {
c.Deb.Signature.KeyPassphrase = debPassphrase
}
rpmPassphrase := os.Expand("$NFPM_RPM_PASSPHRASE", c.envMappingFunc)
if rpmPassphrase != "" {
c.RPM.Signature.KeyPassphrase = rpmPassphrase
}
apkPassphrase := os.Expand("$NFPM_APK_PASSPHRASE", c.envMappingFunc)
if apkPassphrase != "" {
c.APK.Signature.KeyPassphrase = apkPassphrase
}
// RPM specific
c.RPM.Packager = os.Expand(c.RPM.Packager, c.envMappingFunc)
// Deb specific
for k, v := range c.Deb.Fields {
c.Deb.Fields[k] = os.Expand(v, c.envMappingFunc)
}
c.Deb.Predepends = c.expandEnvVarsStringSlice(c.Deb.Predepends)
// IPK specific
for k, v := range c.IPK.Fields {
c.IPK.Fields[k] = os.Expand(v, c.envMappingFunc)
}
c.IPK.Predepends = c.expandEnvVarsStringSlice(c.IPK.Predepends)
// MSIX specific
c.MSIX.Signature.PFXFile = os.Expand(c.MSIX.Signature.PFXFile, c.envMappingFunc)
c.MSIX.Publisher = os.Expand(c.MSIX.Publisher, c.envMappingFunc)
c.MSIX.Signature.KeyPassphrase = generalPassphrase
msixPassphrase := os.Expand("$NFPM_MSIX_PASSPHRASE", c.envMappingFunc)
if msixPassphrase != "" {
c.MSIX.Signature.KeyPassphrase = msixPassphrase
}
if c.envLookupFunc != nil {
if passphrase, set := c.envLookupFunc("NFPM_MSIX_PASSPHRASE"); set {
c.MSIX.Signature.KeyPassphrase = passphrase
}
}
c.expandMSI(&c.MSI)
c.expandApp(&c.App)
c.expandPkg(&c.Pkg)
for _, override := range c.Overrides {
if override != nil {
c.expandMSI(&override.MSI)
c.expandApp(&override.App)
c.expandPkg(&override.Pkg)
}
}
}
// expandApp expands the macOS app bundle settings. Like expandPkg it runs for
// the base settings and for every override, because overrides are merged only
// after parsing.
func (c *Config) expandApp(cfg *App) {
cfg.Arch = os.Expand(cfg.Arch, c.envMappingFunc)
cfg.Name = os.Expand(cfg.Name, c.envMappingFunc)
cfg.Identifier = os.Expand(cfg.Identifier, c.envMappingFunc)
cfg.Executable = os.Expand(cfg.Executable, c.envMappingFunc)
cfg.MinOSVersion = os.Expand(cfg.MinOSVersion, c.envMappingFunc)
for key, value := range cfg.InfoPlist {
cfg.InfoPlist[key] = c.expandPlistValue(value)
}
cfg.Signature.P12File = os.Expand(cfg.Signature.P12File, c.envMappingFunc)
cfg.Signature.TimestampURL = os.Expand(cfg.Signature.TimestampURL, c.envMappingFunc)
cfg.Signature.Entitlements = os.Expand(cfg.Signature.Entitlements, c.envMappingFunc)
cfg.Signature.KeyPassphrase = c.passphrase("NFPM_APP_PASSPHRASE")
}
// expandPlistValue expands every string in an Info.plist value, however
// deeply it is nested. Keys are left alone.
func (c *Config) expandPlistValue(value any) any {
switch typed := value.(type) {
case string:
return os.Expand(typed, c.envMappingFunc)
case []any:
for n := range typed {
typed[n] = c.expandPlistValue(typed[n])
}
case map[string]any:
for key := range typed {
typed[key] = c.expandPlistValue(typed[key])
}
}
return value
}
// expandPkg expands the macOS pkg settings. It runs for the base settings and
// for every override, because overrides are merged only after parsing.
func (c *Config) expandPkg(cfg *Pkg) {
cfg.Arch = os.Expand(cfg.Arch, c.envMappingFunc)
cfg.Identifier = os.Expand(cfg.Identifier, c.envMappingFunc)
cfg.MinOSVersion = os.Expand(cfg.MinOSVersion, c.envMappingFunc)
cfg.Signature.P12File = os.Expand(cfg.Signature.P12File, c.envMappingFunc)
cfg.Signature.TimestampURL = os.Expand(cfg.Signature.TimestampURL, c.envMappingFunc)
cfg.Signature.KeyPassphrase = c.passphrase("NFPM_PKG_PASSPHRASE")
}
// passphrase returns the signing passphrase for one format: the value of its
// own variable, or NFPM_PASSPHRASE when that variable is not set. A variable
// that is set but empty selects an empty passphrase. Only the process
// environment can tell an unset variable from an empty one; with a custom
// mapping an empty value falls back to NFPM_PASSPHRASE, as it does for MSIX.
func (c *Config) passphrase(name string) string {
if c.envLookupFunc != nil {
if passphrase, set := c.envLookupFunc(name); set {
return passphrase
}
}
if passphrase := os.Expand("$"+name, c.envMappingFunc); passphrase != "" {
return passphrase
}
return os.Expand("$NFPM_PASSPHRASE", c.envMappingFunc)
}
func (c *Config) expandMSI(cfg *MSI) {
// MSI specific
cfg.Arch = expandMSIValue(cfg.Arch, c.envMappingFunc)
cfg.Version = expandMSIValue(cfg.Version, c.envMappingFunc)
cfg.ProductName = expandMSIValue(cfg.ProductName, c.envMappingFunc)
cfg.Manufacturer = expandMSIValue(cfg.Manufacturer, c.envMappingFunc)
cfg.ProductCode = expandMSIValue(cfg.ProductCode, c.envMappingFunc)
cfg.UpgradeCode = expandMSIValue(cfg.UpgradeCode, c.envMappingFunc)
cfg.InstallDir = expandMSIValue(cfg.InstallDir, c.envMappingFunc)
cfg.Upgrade.DowngradeErrorMessage = expandMSIValue(cfg.Upgrade.DowngradeErrorMessage, c.envMappingFunc)
for k, v := range cfg.Properties {
cfg.Properties[k] = expandMSIValue(v, c.envMappingFunc)
}
for k, v := range cfg.FileVersions {
cfg.FileVersions[k] = expandMSIValue(v, c.envMappingFunc)
}
for i := range cfg.Shortcuts {
cfg.Shortcuts[i].Name = expandMSIValue(cfg.Shortcuts[i].Name, c.envMappingFunc)
cfg.Shortcuts[i].Target = expandMSIValue(cfg.Shortcuts[i].Target, c.envMappingFunc)
cfg.Shortcuts[i].Directory = expandMSIValue(cfg.Shortcuts[i].Directory, c.envMappingFunc)
cfg.Shortcuts[i].Arguments = expandMSIValue(cfg.Shortcuts[i].Arguments, c.envMappingFunc)
cfg.Shortcuts[i].Description = expandMSIValue(cfg.Shortcuts[i].Description, c.envMappingFunc)
cfg.Shortcuts[i].Icon = expandMSIValue(cfg.Shortcuts[i].Icon, c.envMappingFunc)
}
for i := range cfg.Services {
cfg.Services[i].Name = expandMSIValue(cfg.Services[i].Name, c.envMappingFunc)
cfg.Services[i].DisplayName = expandMSIValue(cfg.Services[i].DisplayName, c.envMappingFunc)
cfg.Services[i].Executable = expandMSIValue(cfg.Services[i].Executable, c.envMappingFunc)
cfg.Services[i].Description = expandMSIValue(cfg.Services[i].Description, c.envMappingFunc)
cfg.Services[i].StartType = expandMSIValue(cfg.Services[i].StartType, c.envMappingFunc)
cfg.Services[i].Account = expandMSIValue(cfg.Services[i].Account, c.envMappingFunc)
cfg.Services[i].Arguments = expandMSIValue(cfg.Services[i].Arguments, c.envMappingFunc)
for j := range cfg.Services[i].Dependencies {
cfg.Services[i].Dependencies[j] = expandMSIValue(cfg.Services[i].Dependencies[j], c.envMappingFunc)
}
}
for i := range cfg.Registry {
cfg.Registry[i].Root = expandMSIValue(cfg.Registry[i].Root, c.envMappingFunc)
cfg.Registry[i].Key = expandMSIValue(cfg.Registry[i].Key, c.envMappingFunc)
cfg.Registry[i].Name = expandMSIValue(cfg.Registry[i].Name, c.envMappingFunc)
cfg.Registry[i].Value = expandMSIValue(cfg.Registry[i].Value, c.envMappingFunc)
}
cfg.Signature.PFXFile = expandMSIValue(cfg.Signature.PFXFile, c.envMappingFunc)
cfg.Signature.TimestampURL = expandMSIValue(cfg.Signature.TimestampURL, c.envMappingFunc)
cfg.Signature.KeyPassphrase = os.Expand("$NFPM_PASSPHRASE", c.envMappingFunc)
msiPassphrase := os.Expand("$NFPM_MSI_PASSPHRASE", c.envMappingFunc)
if msiPassphrase != "" {
cfg.Signature.KeyPassphrase = msiPassphrase
}
}
// Info contains information about a single package.
type Info struct {
Overridables `yaml:",inline" json:",inline"`
Name string `yaml:"name" json:"name" jsonschema:"title=package name"`
Arch string `yaml:"arch" json:"arch" jsonschema:"title=target architecture,example=amd64"`
Platform string `yaml:"platform,omitempty" json:"platform,omitempty" jsonschema:"title=target platform,example=linux,default=linux"`
Epoch string `yaml:"epoch,omitempty" json:"epoch,omitempty" jsonschema:"title=version epoch,example=2,default=extracted from version"`
Version string `yaml:"version" json:"version" jsonschema:"title=version,example=v1.0.2,example=2.0.1"`
VersionSchema string `yaml:"version_schema,omitempty" json:"version_schema,omitempty" jsonschema:"title=version schema,enum=semver,enum=none,default=semver"`
Release string `yaml:"release,omitempty" json:"release,omitempty" jsonschema:"title=version release,example=1"`
Prerelease string `yaml:"prerelease,omitempty" json:"prerelease,omitempty" jsonschema:"title=version prerelease,default=extracted from version"`
VersionMetadata string `yaml:"version_metadata,omitempty" json:"version_metadata,omitempty" jsonschema:"title=version metadata,example=git"`
Section string `yaml:"section,omitempty" json:"section,omitempty" jsonschema:"title=package section,example=default"`
Priority string `yaml:"priority,omitempty" json:"priority,omitempty" jsonschema:"title=package priority,example=extra"`
Maintainer string `yaml:"maintainer,omitempty" json:"maintainer,omitempty" jsonschema:"title=package maintainer,example=me@example.com"`
Description string `yaml:"description,omitempty" json:"description,omitempty" jsonschema:"title=package description"`
Vendor string `yaml:"vendor,omitempty" json:"vendor,omitempty" jsonschema:"title=package vendor,example=MyCorp"`
Homepage string `yaml:"homepage,omitempty" json:"homepage,omitempty" jsonschema:"title=package homepage,example=https://example.com"`
License string `yaml:"license,omitempty" json:"license,omitempty" jsonschema:"title=package license,example=MIT"`
Changelog string `yaml:"changelog,omitempty" json:"changelog,omitempty" jsonschema:"title=package changelog,example=changelog.yaml,description=see https://github.com/goreleaser/chglog for more details"`
DisableGlobbing bool `yaml:"disable_globbing,omitempty" json:"disable_globbing,omitempty" jsonschema:"title=whether to disable file globbing,default=false"`
MTime time.Time `yaml:"mtime,omitempty" json:"mtime,omitempty" jsonschema:"title=time to set into the files generated by nFPM"`
Target string `yaml:"-" json:"-"`
}
func (i *Info) Validate() error {
return Validate(i)
}
// GetChangeLog parses the provided changelog file.
func (i *Info) GetChangeLog() (log *chglog.PackageChangeLog, err error) {
// if the file does not exist chglog.Parse will just silently
// create an empty changelog but we should notify the user instead
if _, err = os.Stat(i.Changelog); errors.Is(err, fs.ErrNotExist) {
return nil, err
}
entries, err := chglog.Parse(i.Changelog)
if err != nil {
return nil, err
}
return &chglog.PackageChangeLog{
Name: i.Name,
Entries: entries,
}, nil
}
func (i *Info) parseSemver() {
// parse the version as a semver so we can properly split the parts
// and support proper ordering for both rpm and deb
if v, err := semver.NewVersion(i.Version); err == nil {
i.Version = fmt.Sprintf("%d.%d.%d", v.Major(), v.Minor(), v.Patch())
if i.Prerelease == "" {
i.Prerelease = v.Prerelease()
}
if i.VersionMetadata == "" {
i.VersionMetadata = v.Metadata()
}
}
}
// Overridables contain the field which are overridable in a package.
type Overridables struct {
Replaces []string `yaml:"replaces,omitempty" json:"replaces,omitempty" jsonschema:"title=replaces directive,example=nfpm"`
Provides []string `yaml:"provides,omitempty" json:"provides,omitempty" jsonschema:"title=provides directive,example=nfpm"`
Depends []string `yaml:"depends,omitempty" json:"depends,omitempty" jsonschema:"title=depends directive,example=nfpm"`
Recommends []string `yaml:"recommends,omitempty" json:"recommends,omitempty" jsonschema:"title=recommends directive,example=nfpm"`
Suggests []string `yaml:"suggests,omitempty" json:"suggests,omitempty" jsonschema:"title=suggests directive,example=nfpm"`
Conflicts []string `yaml:"conflicts,omitempty" json:"conflicts,omitempty" jsonschema:"title=conflicts directive,example=nfpm"`
Contents files.Contents `yaml:"contents,omitempty" json:"contents,omitempty" jsonschema:"title=files to add to the package"`
Umask os.FileMode `yaml:"umask,omitempty" json:"umask,omitempty" jsonschema:"title=umask for file contents,example=112"`
Scripts Scripts `yaml:"scripts,omitempty" json:"scripts,omitempty" jsonschema:"title=scripts to execute"`
RPM RPM `yaml:"rpm,omitempty" json:"rpm,omitempty" jsonschema:"title=rpm-specific settings"`
Deb Deb `yaml:"deb,omitempty" json:"deb,omitempty" jsonschema:"title=deb-specific settings"`
APK APK `yaml:"apk,omitempty" json:"apk,omitempty" jsonschema:"title=apk-specific settings"`
ArchLinux ArchLinux `yaml:"archlinux,omitempty" json:"archlinux,omitempty" jsonschema:"title=archlinux-specific settings"`
IPK IPK `yaml:"ipk,omitempty" json:"ipk,omitempty" jsonschema:"title=ipk-specific settings"`
MSIX MSIX `yaml:"msix,omitempty" json:"msix,omitempty" jsonschema:"title=msix-specific settings"`
MSI MSI `yaml:"msi,omitempty" json:"msi,omitempty" jsonschema:"title=msi-specific settings"`
App App `yaml:"app,omitempty" json:"app,omitempty" jsonschema:"title=macOS app bundle settings,description=used by the app and dmg packagers"`
Pkg Pkg `yaml:"pkg,omitempty" json:"pkg,omitempty" jsonschema:"title=macOS pkg-specific settings"`
}
type ArchLinux struct {
Pkgbase string `yaml:"pkgbase,omitempty" json:"pkgbase,omitempty" jsonschema:"title=explicitly specify the name used to refer to a split package, defaults to name"`
Arch string `yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"title=architecture in archlinux nomenclature"`
Packager string `yaml:"packager,omitempty" json:"packager,omitempty" jsonschema:"title=organization that packaged the software"`
Scripts ArchLinuxScripts `yaml:"scripts,omitempty" json:"scripts,omitempty" jsonschema:"title=archlinux-specific scripts"`
}
type ArchLinuxScripts struct {
PreUpgrade string `yaml:"preupgrade,omitempty" json:"preupgrade,omitempty" jsonschema:"title=preupgrade script"`
PostUpgrade string `yaml:"postupgrade,omitempty" json:"postupgrade,omitempty" jsonschema:"title=postupgrade script"`
}
// RPM is custom configs that are only available on RPM packages.
type RPM struct {
Arch string `yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"title=architecture in rpm nomenclature"`
BuildHost string `yaml:"buildhost,omitempty" json:"buildhost,omitempty" jsonschema:"title=host name of the build environment, default=os.Hostname()"`
Scripts RPMScripts `yaml:"scripts,omitempty" json:"scripts,omitempty" jsonschema:"title=rpm-specific scripts"`
Requires RPMRequires `yaml:"requires,omitempty" json:"requires,omitempty" jsonschema:"title=rpm-specific requires"`
Group string `yaml:"group,omitempty" json:"group,omitempty" jsonschema:"title=package group,example=Unspecified"`
Summary string `yaml:"summary,omitempty" json:"summary,omitempty" jsonschema:"title=package summary"`
Compression string `yaml:"compression,omitempty" json:"compression,omitempty" jsonschema:"title=compression algorithm to be used,enum=gzip,enum=lzma,enum=xz,enum=zstd,default=gzip:-1"`
Signature RPMSignature `yaml:"signature,omitempty" json:"signature,omitempty" jsonschema:"title=rpm signature"`
Packager string `yaml:"packager,omitempty" json:"packager,omitempty" jsonschema:"title=organization that actually packaged the software"`
Prefixes []string `yaml:"prefixes,omitempty" json:"prefixes,omitempty" jsonschema:"title=Prefixes for relocatable packages"`
ScriptRequires bool `yaml:"script_requires,omitempty" json:"script_requires,omitempty" jsonschema:"title=require the interpreters of executable scripts,default=false"`
}
// RPMScripts represents scripts only available on RPM packages.
type RPMScripts struct {
PreTrans string `yaml:"pretrans,omitempty" json:"pretrans,omitempty" jsonschema:"title=pretrans script"`
PostTrans string `yaml:"posttrans,omitempty" json:"posttrans,omitempty" jsonschema:"title=posttrans script"`
Verify string `yaml:"verify,omitempty" json:"verify,omitempty" jsonschema:"title=verify script"`
}
// RPMRequires represents qualified RPM Requires dependencies.
type RPMRequires struct {
Post []string `yaml:"post,omitempty" json:"post,omitempty" jsonschema:"title=post requires directive,example=nfpm"`
}
type PackageSignature struct {
// PGP secret key, can be ASCII-armored
KeyFile string `yaml:"key_file,omitempty" json:"key_file,omitempty" jsonschema:"title=key file,example=key.gpg"`
KeyID *string `yaml:"key_id,omitempty" json:"key_id,omitempty" jsonschema:"title=key id,example=bc8acdd415bd80b3"`
KeyPassphrase string `yaml:"-" json:"-"` // populated from environment variable
// SignFn, if set, will be called with the package-specific data to sign.
// For deb and rpm packages, data is the full package content.
// For apk packages, data is the SHA1 digest of control tgz.
//
// This allows for signing implementations other than using a local file
// (for example using a remote signer like KMS).
SignFn func(data io.Reader) ([]byte, error) `yaml:"-" json:"-"` // populated when used as a library
}
type RPMSignature struct {
PackageSignature `yaml:",inline" json:",inline"`
}
type APK struct {
Arch string `yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"title=architecture in apk nomenclature"`
Signature APKSignature `yaml:"signature,omitempty" json:"signature,omitempty" jsonschema:"title=apk signature"`
Scripts APKScripts `yaml:"scripts,omitempty" json:"scripts,omitempty" jsonschema:"title=apk scripts"`
}
type APKSignature struct {
PackageSignature `yaml:",inline" json:",inline"`
// defaults to <maintainer email>.rsa.pub
KeyName string `yaml:"key_name,omitempty" json:"key_name,omitempty" jsonschema:"title=key name,example=origin,default=maintainer_email.rsa.pub"`
}
type APKScripts struct {
PreUpgrade string `yaml:"preupgrade,omitempty" json:"preupgrade,omitempty" jsonschema:"title=pre upgrade script"`
PostUpgrade string `yaml:"postupgrade,omitempty" json:"postupgrade,omitempty" jsonschema:"title=post upgrade script"`
}
// Deb is custom configs that are only available on deb packages.
type Deb struct {
Arch string `yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"title=architecture in deb nomenclature"`
ArchVariant string `yaml:"arch_variant,omitempty" json:"arch_variant,omitempty" jsonschema:"title=target architecture variant in deb nomenclature,example=amd64v3"`
Scripts DebScripts `yaml:"scripts,omitempty" json:"scripts,omitempty" jsonschema:"title=scripts"`
Triggers DebTriggers `yaml:"triggers,omitempty" json:"triggers,omitempty" jsonschema:"title=triggers"`
Breaks []string `yaml:"breaks,omitempty" json:"breaks,omitempty" jsonschema:"title=breaks"`
Signature DebSignature `yaml:"signature,omitempty" json:"signature,omitempty" jsonschema:"title=signature"`
Compression string `yaml:"compression,omitempty" json:"compression,omitempty" jsonschema:"title=compression algorithm to be used,enum=gzip,enum=xz,enum=zstd,enum=none,default=gzip:-1"`
Fields map[string]string `yaml:"fields,omitempty" json:"fields,omitempty" jsonschema:"title=fields"`
Predepends []string `yaml:"predepends,omitempty" json:"predepends,omitempty" jsonschema:"title=predepends directive,example=nfpm"`
}
type DebSignature struct {
PackageSignature `yaml:",inline" json:",inline"`
// Only debsign still supported
Method string `yaml:"method,omitempty" json:"method,omitempty" jsonschema:"title=method role,enum=dpkg-sig,enum=debsign,default=debsign"`
// origin, maint or archive (defaults to origin)
Type string `yaml:"type,omitempty" json:"type,omitempty" jsonschema:"title=signer role,enum=origin,enum=maint,enum=archive,default=origin"`
Signer string `yaml:"signer,omitempty" json:"signer,omitempty" jsonschema:"title=signer"`
}
// DebTriggers contains triggers only available for deb packages.
// https://wiki.debian.org/DpkgTriggers
// https://man7.org/linux/man-pages/man5/deb-triggers.5.html
type DebTriggers struct {
Interest []string `yaml:"interest,omitempty" json:"interest,omitempty" jsonschema:"title=interest"`
InterestAwait []string `yaml:"interest_await,omitempty" json:"interest_await,omitempty" jsonschema:"title=interest await"`
InterestNoAwait []string `yaml:"interest_noawait,omitempty" json:"interest_noawait,omitempty" jsonschema:"title=interest noawait"`
Activate []string `yaml:"activate,omitempty" json:"activate,omitempty" jsonschema:"title=activate"`
ActivateAwait []string `yaml:"activate_await,omitempty" json:"activate_await,omitempty" jsonschema:"title=activate await"`
ActivateNoAwait []string `yaml:"activate_noawait,omitempty" json:"activate_noawait,omitempty" jsonschema:"title=activate noawait"`
}
// DebScripts is scripts only available on deb packages.
type DebScripts struct {
Rules string `yaml:"rules,omitempty" json:"rules,omitempty" jsonschema:"title=rules"`
Templates string `yaml:"templates,omitempty" json:"templates,omitempty" jsonschema:"title=templates"`
Config string `yaml:"config,omitempty" json:"config,omitempty" jsonschema:"title=config"`
}
// IPK is custom configs that are only available on deb packages.
type IPK struct {
ABIVersion string `yaml:"abi_version,omitempty" json:"abi_version,omitempty" jsonschema:"title=abi version"`
Alternatives []IPKAlternative `yaml:"alternatives,omitempty" json:"alternatives,omitempty" jsonschema:"title=alternatives"`
Arch string `yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"title=architecture in deb nomenclature"`
AutoInstalled bool `yaml:"auto_installed,omitempty" json:"auto_installed,omitempty" jsonschema:"title=auto installed,default=false"`
Essential bool `yaml:"essential,omitempty" json:"essential,omitempty" jsonschema:"title=whether package is essential,default=false"`
Fields map[string]string `yaml:"fields,omitempty" json:"fields,omitempty" jsonschema:"title=fields"`
Predepends []string `yaml:"predepends,omitempty" json:"predepends,omitempty" jsonschema:"title=predepends directive,example=nfpm"`
Tags []string `yaml:"tags,omitempty" json:"tags,omitempty" jsonschema:"title=tags"`
}
// IPKAlternative represents an alternative for an IPK package.
type IPKAlternative struct {
Priority int `yaml:"priority,omitempty" json:"priority,omitempty" jsonschema:"title=priority"`
Target string `yaml:"target,omitempty" json:"target,omitempty" jsonschema:"title=target"`
LinkName string `yaml:"link_name,omitempty" json:"link_name,omitempty" jsonschema:"title=link name"`
}
// MSIX contains configs that are only available on MSIX packages.
type MSIX struct {
Arch string `yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"title=architecture in msix nomenclature"`
Publisher string `yaml:"publisher,omitempty" json:"publisher,omitempty" jsonschema:"title=publisher identity,description=defaults to the signing certificate subject when signing or CN=<vendor or maintainer>,example=CN=MyCompany\\, O=MyCompany\\, C=US"`
Identity MSIXIdentity `yaml:"identity,omitempty" json:"identity,omitempty" jsonschema:"title=package identity"`
Properties MSIXProperties `yaml:"properties,omitempty" json:"properties,omitempty" jsonschema:"title=package properties"`
Applications []MSIXApplication `yaml:"applications" json:"applications" jsonschema:"title=applications in the package"`
Dependencies MSIXDependencies `yaml:"dependencies,omitempty" json:"dependencies,omitempty" jsonschema:"title=target device families"`
Capabilities MSIXCapabilities `yaml:"capabilities,omitempty" json:"capabilities,omitempty" jsonschema:"title=package capabilities"`
Signature MSIXSignature `yaml:"signature,omitempty" json:"signature,omitempty" jsonschema:"title=msix signature"`
}
// MSIXIdentity contains identity fields for MSIX packages.
type MSIXIdentity struct {
ResourceID string `yaml:"resource_id,omitempty" json:"resource_id,omitempty" jsonschema:"title=resource identifier"`
}
// MSIXProperties contains display properties for MSIX packages.
type MSIXProperties struct {
DisplayName string `yaml:"display_name,omitempty" json:"display_name,omitempty" jsonschema:"title=display name"`
PublisherDisplayName string `yaml:"publisher_display_name,omitempty" json:"publisher_display_name,omitempty" jsonschema:"title=publisher display name"`
Logo string `yaml:"logo,omitempty" json:"logo,omitempty" jsonschema:"title=package logo path"`
}
// MSIXApplication describes an application entry in an MSIX package.
type MSIXApplication struct {
ID string `yaml:"id" json:"id" jsonschema:"title=application ID"`
Executable string `yaml:"executable" json:"executable" jsonschema:"title=executable path in package"`
EntryPoint string `yaml:"entry_point,omitempty" json:"entry_point,omitempty" jsonschema:"title=entry point,default=Windows.FullTrustApplication"`
VisualElements MSIXVisualElements `yaml:"visual_elements,omitempty" json:"visual_elements,omitempty" jsonschema:"title=visual elements"`
}
// MSIXVisualElements contains visual presentation settings for an MSIX application.
type MSIXVisualElements struct {
DisplayName string `yaml:"display_name,omitempty" json:"display_name,omitempty"`
Description string `yaml:"description,omitempty" json:"description,omitempty"`
BackgroundColor string `yaml:"background_color,omitempty" json:"background_color,omitempty" jsonschema:"default=transparent"`
Square150x150Logo string `yaml:"square150x150_logo,omitempty" json:"square150x150_logo,omitempty"`
Square44x44Logo string `yaml:"square44x44_logo,omitempty" json:"square44x44_logo,omitempty"`
}
// MSIXDependencies contains dependency information for MSIX packages.
type MSIXDependencies struct {
TargetDeviceFamilies []MSIXTargetDeviceFamily `yaml:"target_device_families,omitempty" json:"target_device_families,omitempty"`
}
// MSIXTargetDeviceFamily describes a target device family for an MSIX package.
type MSIXTargetDeviceFamily struct {
Name string `yaml:"name" json:"name" jsonschema:"title=device family name,example=Windows.Desktop"`
MinVersion string `yaml:"min_version" json:"min_version" jsonschema:"title=minimum OS version,example=10.0.17763.0"`
MaxVersionTested string `yaml:"max_version_tested" json:"max_version_tested" jsonschema:"title=max tested version,example=10.0.22621.0"`
}
// MSIXCapabilities contains capability declarations for MSIX packages.
type MSIXCapabilities struct {
Capabilities []string `yaml:"capabilities,omitempty" json:"capabilities,omitempty"`
DeviceCapabilities []string `yaml:"device_capabilities,omitempty" json:"device_capabilities,omitempty"`
Restricted []string `yaml:"restricted,omitempty" json:"restricted,omitempty"`
}
// MSIXSignature contains signing configuration for MSIX packages.
type MSIXSignature struct {
PFXFile string `yaml:"pfx_file,omitempty" json:"pfx_file,omitempty" jsonschema:"title=PFX certificate file"`
KeyPassphrase string `yaml:"-" json:"-"` // populated from NFPM_MSIX_PASSPHRASE, falling back to NFPM_PASSPHRASE
}
// MSI contains configs that are only available on MSI packages.
type MSI struct {
Arch string `yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"title=architecture in msi nomenclature"`
Version string `yaml:"version,omitempty" json:"version,omitempty" jsonschema:"title=version in msi nomenclature,description=overrides \"version\"; still normalized to major.minor.build and must fit 255.255.65535,example=24.1.0"`
ProductName string `yaml:"product_name,omitempty" json:"product_name,omitempty" jsonschema:"title=product name,description=defaults to the package name"`
Manufacturer string `yaml:"manufacturer,omitempty" json:"manufacturer,omitempty" jsonschema:"title=manufacturer/author of the product,description=defaults to the vendor or maintainer,example=My Company"`
ProductCode string `yaml:"product_code,omitempty" json:"product_code,omitempty" jsonschema:"title=product code GUID,description=derived from manufacturer/product name/arch/version (changes every release) when empty; pinning it breaks upgrades,example={12345678-1234-1234-1234-123456789ABC}"`
UpgradeCode string `yaml:"upgrade_code,omitempty" json:"upgrade_code,omitempty" jsonschema:"title=upgrade code GUID,description=derived from manufacturer/product name/arch (stable across releases) when empty,example={ABCDEF01-2345-6789-ABCD-EF0123456789}"`
InstallDir string `yaml:"install_dir,omitempty" json:"install_dir,omitempty" jsonschema:"title=default install folder name,description=created under Program Files (or the user's local app data for per-user installs); defaults to the product name"`
PerUser bool `yaml:"per_user,omitempty" json:"per_user,omitempty" jsonschema:"title=per-user install,description=install for the current user only without elevation; keep context fixed across upgrades or uninstall/migrate first; defaults to a per-machine install"`
Properties map[string]string `yaml:"properties,omitempty" json:"properties,omitempty" jsonschema:"title=arbitrary MSI Property rows"`
FileVersions map[string]string `yaml:"file_versions,omitempty" json:"file_versions,omitempty" jsonschema:"title=file version overrides by contents destination,description=PE file versions are detected automatically; an empty override explicitly keeps a file unversioned"`
MinimalUI bool `yaml:"minimal_ui,omitempty" json:"minimal_ui,omitempty" jsonschema:"title=install the canned minimal install wizard"`
Upgrade MSIUpgrade `yaml:"upgrade,omitempty" json:"upgrade,omitempty" jsonschema:"title=major upgrade behavior"`
Shortcuts []MSIShortcut `yaml:"shortcuts,omitempty" json:"shortcuts,omitempty" jsonschema:"title=shortcuts to create"`
Services []MSIService `yaml:"services,omitempty" json:"services,omitempty" jsonschema:"title=windows services to install"`
Registry []MSIRegistry `yaml:"registry,omitempty" json:"registry,omitempty" jsonschema:"title=registry entries to create"`
Signature MSISignature `yaml:"signature,omitempty" json:"signature,omitempty" jsonschema:"title=msi signature"`
}
// MSIUpgrade contains major-upgrade configuration for MSI packages. Major
// upgrades are always enabled: every release replaces older installs of the
// same upgrade code.
type MSIUpgrade struct {
DowngradeErrorMessage string `yaml:"downgrade_error_message,omitempty" json:"downgrade_error_message,omitempty" jsonschema:"title=message shown when a newer version is already installed"`
AllowDowngrades bool `yaml:"allow_downgrades,omitempty" json:"allow_downgrades,omitempty" jsonschema:"title=allow installing over a newer version,description=disables the downgrade block; defaults to false"`
AllowSameVersion bool `yaml:"allow_same_version,omitempty" json:"allow_same_version,omitempty" jsonschema:"title=treat an equal version as an upgrade,description=replace the same major.minor.build within one install context; requires a new ProductCode via distinct release metadata or an explicit new code; defaults to false"`
}
// MSIShortcut describes an advertised shortcut in an MSI package.
type MSIShortcut struct {
Name string `yaml:"name" json:"name" jsonschema:"title=shortcut display name"`
Target string `yaml:"target" json:"target" jsonschema:"title=destination path of an installed file the shortcut points to"`
Directory string `yaml:"directory,omitempty" json:"directory,omitempty" jsonschema:"title=standard folder ID,default=ProgramMenuFolder,example=DesktopFolder"`
Arguments string `yaml:"arguments,omitempty" json:"arguments,omitempty" jsonschema:"title=command-line arguments"`
Description string `yaml:"description,omitempty" json:"description,omitempty" jsonschema:"title=shortcut description"`
Icon string `yaml:"icon,omitempty" json:"icon,omitempty" jsonschema:"title=path to a PE file containing icon resources,description=advertised shortcuts require EXE-format icon data; raw .ico files are not supported"`
}
// MSIService describes a Windows service to install from an MSI package.
type MSIService struct {
Name string `yaml:"name" json:"name" jsonschema:"title=service name"`
DisplayName string `yaml:"display_name,omitempty" json:"display_name,omitempty" jsonschema:"title=service display name"`
Executable string `yaml:"executable" json:"executable" jsonschema:"title=destination path of the installed service executable"`
Description string `yaml:"description,omitempty" json:"description,omitempty" jsonschema:"title=service description"`
StartType string `yaml:"start_type,omitempty" json:"start_type,omitempty" jsonschema:"title=service start type,pattern=^([aA][uU][tT][oO]|[dD][eE][mM][aA][nN][dD]|[dD][iI][sS][aA][bB][lL][eE][dD])$,default=demand"`
Account string `yaml:"account,omitempty" json:"account,omitempty" jsonschema:"title=account the service runs as"`
Arguments string `yaml:"arguments,omitempty" json:"arguments,omitempty" jsonschema:"title=service arguments"`
Dependencies []string `yaml:"dependencies,omitempty" json:"dependencies,omitempty" jsonschema:"title=service dependencies"`
Start bool `yaml:"start,omitempty" json:"start,omitempty" jsonschema:"title=start the service on install,description=the service is always stopped before install/upgrade and stopped and deleted on uninstall"`
}
// MSIRegistry describes a registry entry to create from an MSI package.
type MSIRegistry struct {
Root string `yaml:"root" json:"root" jsonschema:"title=registry root,pattern=^[hH][kK]([lL][mM]|[cC][uU]|[cC][rR]|[mM][uU]|[uU])$"`
Key string `yaml:"key" json:"key" jsonschema:"title=registry key path"`
Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"title=value name"`
Value string `yaml:"value,omitempty" json:"value,omitempty" jsonschema:"title=value data"`
}
// MSISignature contains signing configuration for MSI packages.
type MSISignature struct {
PFXFile string `yaml:"pfx_file,omitempty" json:"pfx_file,omitempty" jsonschema:"title=PFX certificate file"`
TimestampURL string `yaml:"timestamp_url,omitempty" json:"timestamp_url,omitempty" jsonschema:"title=RFC3161 timestamp URL"`
KeyPassphrase string `yaml:"-" json:"-"` // populated from NFPM_MSI_PASSPHRASE, falling back to NFPM_PASSPHRASE
}
// App contains configs for macOS application bundles. It is used by both the
// app packager (a zipped .app) and the dmg packager (the same .app in a disk
// image). The bundle itself comes from the shared fields: name, version and
// contents.
type App struct {
Arch string `yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"title=architecture in macOS nomenclature,description=arm64; x86_64 or universal; an environment variable may supply it,pattern=^(arm64|x86_64|universal|.*[$].*)$"`
Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"title=bundle name,description=name of the .app folder and the name macOS shows for the application; defaults to the package name,example=My App"`
Identifier string `yaml:"identifier,omitempty" json:"identifier,omitempty" jsonschema:"title=bundle identifier,description=reverse-DNS identifier (CFBundleIdentifier) macOS knows the application by; the app and dmg packagers require it; keep it the same across releases,example=com.example.myapp,pattern=^([A-Za-z0-9][A-Za-z0-9.-]*|.*[$].*)$"`
Executable string `yaml:"executable,omitempty" json:"executable,omitempty" jsonschema:"title=main executable,description=name of the file in Contents/MacOS that macOS launches; defaults to the package name"`
MinOSVersion string `yaml:"min_os_version,omitempty" json:"min_os_version,omitempty" jsonschema:"title=minimum macOS version,description=macOS refuses to launch the application on an older version,example=13.0,pattern=^([0-9]+([.][0-9]+)?([.][0-9]+)?|.*[$].*)$"`
InfoPlist map[string]any `yaml:"info_plist,omitempty" json:"info_plist,omitempty" jsonschema:"title=additional Info.plist keys,description=added to the generated Info.plist; the keys nFPM sets from other fields cannot be set here"`
Signature AppSignature `yaml:"signature,omitempty" json:"signature,omitempty" jsonschema:"title=app signature"`
}
// AppSignature contains code signing configuration for macOS application
// bundles and the disk images that carry them.
type AppSignature struct {
P12File string `yaml:"p12_file,omitempty" json:"p12_file,omitempty" jsonschema:"title=PKCS#12 file holding the Developer ID Application certificate and its private key"`
TimestampURL string `yaml:"timestamp_url,omitempty" json:"timestamp_url,omitempty" jsonschema:"title=RFC3161 timestamp URL,description=defaults to Apple's timestamp service; set to none to sign without a timestamp,example=none"`
Entitlements string `yaml:"entitlements,omitempty" json:"entitlements,omitempty" jsonschema:"title=entitlements property list file"`
KeyPassphrase string `yaml:"-" json:"-"` // populated from NFPM_APP_PASSPHRASE, falling back to NFPM_PASSPHRASE
}
// Pkg contains configs that are only available on macOS installer packages
// (.pkg). Everything else comes from the shared fields: name, version, arch,
// contents and the preinstall/postinstall scripts.
type Pkg struct {
Arch string `yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"title=architecture in macOS nomenclature,description=arm64; x86_64 or universal; an environment variable may supply it,pattern=^(arm64|x86_64|universal|.*[$].*)$"`
Identifier string `yaml:"identifier,omitempty" json:"identifier,omitempty" jsonschema:"title=package identifier,description=reverse-DNS identifier macOS records the installation under; the pkg packager requires it; it must stay the same across releases or a new version is treated as a different package,example=com.example.myapp,pattern=^([A-Za-z0-9][A-Za-z0-9._-]*|.*[$].*)$"`
MinOSVersion string `yaml:"min_os_version,omitempty" json:"min_os_version,omitempty" jsonschema:"title=minimum macOS version,description=the installer refuses to install on an older macOS,example=13.0,pattern=^([0-9]+([.][0-9]+)?([.][0-9]+)?|.*[$].*)$"`
Signature PkgSignature `yaml:"signature,omitempty" json:"signature,omitempty" jsonschema:"title=pkg signature"`
}
// PkgSignature contains signing configuration for macOS installer packages.
type PkgSignature struct {
P12File string `yaml:"p12_file,omitempty" json:"p12_file,omitempty" jsonschema:"title=PKCS#12 file holding the Developer ID Installer certificate and its private key"`
TimestampURL string `yaml:"timestamp_url,omitempty" json:"timestamp_url,omitempty" jsonschema:"title=RFC3161 timestamp URL,description=defaults to Apple's timestamp service; set to none to sign without a timestamp,example=none"`
KeyPassphrase string `yaml:"-" json:"-"` // populated from NFPM_PKG_PASSPHRASE, falling back to NFPM_PASSPHRASE
}
// Scripts contains information about maintainer scripts for packages.
type Scripts struct {
PreInstall string `yaml:"preinstall,omitempty" json:"preinstall,omitempty" jsonschema:"title=pre install"`
PostInstall string `yaml:"postinstall,omitempty" json:"postinstall,omitempty" jsonschema:"title=post install"`
PreRemove string `yaml:"preremove,omitempty" json:"preremove,omitempty" jsonschema:"title=pre remove"`
PostRemove string `yaml:"postremove,omitempty" json:"postremove,omitempty" jsonschema:"title=post remove"`
}
// ErrFieldEmpty happens when some required field is empty.
type ErrFieldEmpty struct {
field string
}
func (e ErrFieldEmpty) Error() string {
return fmt.Sprintf("package %s must be provided", e.field)
}
// PrepareForPackager validates the configuration for the given packager and
// prepares the contents for said packager.
func PrepareForPackager(info *Info, packager string) (err error) {
if info.Name == "" {
return ErrFieldEmpty{"name"}
}
if info.Arch == "" &&
((packager == "deb" && info.Deb.Arch == "") ||
(packager == "rpm" && info.RPM.Arch == "") ||
(packager == "apk" && info.APK.Arch == "") ||
(packager == "msix" && info.MSIX.Arch == "") ||
(packager == "msi" && info.MSI.Arch == "") ||
((packager == "app" || packager == "dmg") && info.App.Arch == "") ||
(packager == "pkg" && info.Pkg.Arch == "")) {
return ErrFieldEmpty{"arch"}
}
if info.Version == "" {
return ErrFieldEmpty{"version"}
}
info.Contents, err = files.PrepareForPackager(
info.Contents,
info.Umask,
packager,
info.DisableGlobbing,
info.MTime,
)
return err
}
// Validate the given Info and returns an error if it is invalid. Validate will
// no change the info's contents.
func Validate(info *Info) (err error) {
if info.Name == "" {
return ErrFieldEmpty{"name"}
}
if info.Arch == "" && (info.Deb.Arch == "" || info.RPM.Arch == "" || info.APK.Arch == "") {
return ErrFieldEmpty{"arch"}
}
if info.Version == "" {
return ErrFieldEmpty{"version"}
}
for packager := range packagers {
_, err := files.PrepareForPackager(
info.Contents,
info.Umask,
packager,
info.DisableGlobbing,
info.MTime,
)
if err != nil {
return err
}
}
return nil
}
// WithDefaults set some sane defaults into the given Info.
func WithDefaults(info *Info) *Info {
if info.Platform == "" {
info.Platform = "linux"
}
if info.Description == "" {
info.Description = "no description given"
}
if info.Arch == "" {
info.Arch = "amd64"
}
if strings.HasPrefix(info.Arch, "mips") {
info.Arch = strings.NewReplacer(
"softfloat", "",
"hardfloat", "",
).Replace(info.Arch)
}
if info.Version == "" {
info.Version = "v0.0.0-rc0"
}
if info.Umask == 0 {
info.Umask = 0o02
}
if info.MTime.IsZero() {
info.MTime = modtime.FromEnv()
}
switch info.VersionSchema {
case "none":
// No change to the version or prerelease info set in the YAML file
break
case "semver":
fallthrough
default:
info.parseSemver()
}
return info
}
// ErrSigningFailure is returned whenever something went wrong during
// the package signing process. The underlying error can be unwrapped
// and could be crypto-related or something that occurred while adding
// the signature to the package.
type ErrSigningFailure struct {
Err error
}
func (s *ErrSigningFailure) Error() string {
return fmt.Sprintf("signing error: %v", s.Err)
}
func (s *ErrSigningFailure) Unwrap() error {
return s.Err
}