syft/syft/pkg/nix.go
Alex Goodman d47a6c3a6d
Improve support for cataloging nix package relationships (#3837)
* add nix DB cataloger

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* add derivation path to nix store pkg metadata

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* go mod tidy

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* allow for derivation path to be optional

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* repin build image and disable syscall filtering

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* bump storage capacity

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* track nix derivation details on packages

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* image fixture should have derivation examples

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

* address comments

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>

---------

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
2025-05-05 15:35:13 +00:00

54 lines
2.0 KiB
Go

package pkg
import (
"sort"
"github.com/scylladb/go-set/strset"
)
type NixStoreEntry struct {
// Path is the store path for this output
Path string `mapstructure:"path" json:"path,omitempty"`
// Output allows for optionally specifying the specific nix package output this package represents (for packages that support multiple outputs).
// Note: the default output for a package is an empty string, so will not be present in the output.
Output string `mapstructure:"output" json:"output,omitempty"`
// OutputHash is the prefix of the nix store basename path
OutputHash string `mapstructure:"outputHash" json:"outputHash"`
// Derivation is any information about the derivation file that was used to build this package
Derivation NixDerivation `mapstructure:"derivation" json:"derivation,omitempty"`
// Files is a listing a files that are under the nix/store path for this package
Files []string `mapstructure:"files" json:"files,omitempty"`
}
type NixDerivation struct {
// Path is the path to the derivation file
Path string `mapstructure:"path" json:"path,omitempty"`
// System is the nix system string that this derivation was built for
System string `mapstructure:"system" json:"system,omitempty"`
// InputDerivations is a list of derivation paths that were used to build this package
InputDerivations []NixDerivationReference `mapstructure:"inputDerivations" json:"inputDerivations,omitempty"`
// InputSources is a list of source paths that were used to build this package
InputSources []string `mapstructure:"inputSources" json:"inputSources,omitempty"`
}
type NixDerivationReference struct {
// Path is the path to the derivation file
Path string `mapstructure:"path" json:"path,omitempty"`
// Outputs is a list of output names that were used to build this package
Outputs []string `mapstructure:"outputs" json:"outputs,omitempty"`
}
func (m NixStoreEntry) OwnedFiles() (result []string) {
result = strset.New(m.Files...).List()
sort.Strings(result)
return
}