mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 06:56:40 +01:00
* Add Basic Nix Cataloger Signed-off-by: Julio Tain Sueiras <juliosueiras@gmail.com> * Update nix def for the latest syft definition Signed-off-by: Julio Tain Sueiras <juliosueiras@gmail.com> * capture nix package files on pkg.NixStoreMetadata Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix unit tests and linting Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update JSON schema Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * address review comments Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * Update syft/pkg/cataloger/nix/parse_nix_store_path_test.go Co-authored-by: Florian Klink <flokli@flokli.de> Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * support unstable version conventions Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update json schema relative to main branch Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update syft json with v7.1.1 schema Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * fix CLI tests Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * remove extra continue statement Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * add Nix to list of supported ecosystems Signed-off-by: Alex Goodman <alex.goodman@anchore.com> --------- Signed-off-by: Julio Tain Sueiras <juliosueiras@gmail.com> Signed-off-by: Alex Goodman <alex.goodman@anchore.com> Co-authored-by: Julio Tain Sueiras <juliosueiras@gmail.com> Co-authored-by: Florian Klink <flokli@flokli.de>
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package nix
|
|
|
|
import (
|
|
"github.com/anchore/packageurl-go"
|
|
"github.com/anchore/syft/syft/pkg"
|
|
"github.com/anchore/syft/syft/source"
|
|
)
|
|
|
|
func newNixStorePackage(storePath nixStorePath, locations ...source.Location) pkg.Package {
|
|
p := pkg.Package{
|
|
Name: storePath.name,
|
|
Version: storePath.version,
|
|
FoundBy: catalogerName,
|
|
Locations: source.NewLocationSet(locations...),
|
|
Type: pkg.NixPkg,
|
|
PURL: packageURL(storePath),
|
|
MetadataType: pkg.NixStoreMetadataType,
|
|
Metadata: pkg.NixStoreMetadata{
|
|
OutputHash: storePath.outputHash,
|
|
Output: storePath.output,
|
|
},
|
|
}
|
|
|
|
p.SetID()
|
|
|
|
return p
|
|
}
|
|
|
|
func packageURL(storePath nixStorePath) string {
|
|
var qualifiers packageurl.Qualifiers
|
|
if storePath.output != "" {
|
|
// since there is no nix pURL type yet, this is a guess, however, it is reasonable to assume that
|
|
// if only a single output is installed the pURL should be able to express this.
|
|
qualifiers = append(qualifiers,
|
|
packageurl.Qualifier{
|
|
Key: "output",
|
|
Value: storePath.output,
|
|
},
|
|
)
|
|
}
|
|
if storePath.outputHash != "" {
|
|
// it's not immediately clear if the hash found in the store path should be encoded in the pURL
|
|
qualifiers = append(qualifiers,
|
|
packageurl.Qualifier{
|
|
Key: "outputhash",
|
|
Value: storePath.outputHash,
|
|
},
|
|
)
|
|
}
|
|
pURL := packageurl.NewPackageURL(
|
|
// TODO: nix pURL type has not been accepted yet (only proposed at this time)
|
|
"nix",
|
|
"",
|
|
storePath.name,
|
|
storePath.version,
|
|
qualifiers,
|
|
"")
|
|
return pURL.ToString()
|
|
}
|