github.com/anchore/syft@v1.38.2/syft/pkg/nix.go (about)

     1  package pkg
     2  
     3  import (
     4  	"sort"
     5  
     6  	"github.com/scylladb/go-set/strset"
     7  )
     8  
     9  // NixStoreEntry represents a package in the Nix store (/nix/store) with its derivation information and metadata.
    10  type NixStoreEntry struct {
    11  	// Path is full store path for this output (e.g. /nix/store/abc123...-package-1.0)
    12  	Path string `mapstructure:"path" json:"path,omitempty"`
    13  
    14  	// Output is the specific output name for multi-output packages (empty string for default "out" output, can be "bin", "dev", "doc", etc.)
    15  	Output string `mapstructure:"output" json:"output,omitempty"`
    16  
    17  	// OutputHash is hash prefix of the store path basename (first part before the dash)
    18  	OutputHash string `mapstructure:"outputHash" json:"outputHash"`
    19  
    20  	// Derivation is information about the .drv file that describes how this package was built
    21  	Derivation NixDerivation `mapstructure:"derivation" json:"derivation,omitempty"`
    22  
    23  	// Files are the list of files under the nix/store path for this package
    24  	Files []string `mapstructure:"files" json:"files,omitempty"`
    25  }
    26  
    27  // NixDerivation represents a Nix .drv file that describes how to build a package including inputs, outputs, and build instructions.
    28  type NixDerivation struct {
    29  	// Path is path to the .drv file in Nix store
    30  	Path string `mapstructure:"path" json:"path,omitempty"`
    31  
    32  	// System is target system string indicating where derivation can be built (e.g. "x86_64-linux", "aarch64-darwin"). Must match current system for local builds.
    33  	System string `mapstructure:"system" json:"system,omitempty"`
    34  
    35  	// InputDerivations are the list of other derivations that were inputs to this build (dependencies)
    36  	InputDerivations []NixDerivationReference `mapstructure:"inputDerivations" json:"inputDerivations,omitempty"`
    37  
    38  	// InputSources are the list of source file paths that were inputs to this build
    39  	InputSources []string `mapstructure:"inputSources" json:"inputSources,omitempty"`
    40  }
    41  
    42  // NixDerivationReference represents a reference to another derivation used as a build input or runtime dependency.
    43  type NixDerivationReference struct {
    44  	// Path is path to the referenced .drv file
    45  	Path string `mapstructure:"path" json:"path,omitempty"`
    46  
    47  	// Outputs are which outputs of the referenced derivation were used (e.g. ["out"], ["bin", "dev"])
    48  	Outputs []string `mapstructure:"outputs" json:"outputs,omitempty"`
    49  }
    50  
    51  func (m NixStoreEntry) OwnedFiles() (result []string) {
    52  	result = strset.New(m.Files...).List()
    53  	sort.Strings(result)
    54  	return
    55  }