Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Nix extractor. #356

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

brnpl
Copy link
Contributor

@brnpl brnpl commented Dec 19, 2024

Pull request for the Nix package manager extractor.

Implemented:

  • Extractor implementation;
  • Unit test implementation;
  • Integrated extractor in the main tool;


// Check if uniquePath has been already processed. Scalibr scans through files but the info
// about the nix packages are saved in the directory name.
if _, exists := visitedDir[uniquePath]; !exists {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be executed for all files in the nix directory. Is there no file pattern you can match on?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understood, Scalibr scans each file individually, and matching on the nix/store/ pattern is the only viable way to identify relevant files.
If you have any suggestions or alternative approaches to optimize this process, I would be happy to explore them.

PackageName string
PackageVersion string
PackageHash string
PackageOutput string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is packageOutput?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a part of what gets built when a package is created.
Ref: https://nixos.org/manual/nixpkgs/stable/#sec-package-naming

return osID + ":" + m.OSVersionID
}

func toNamespace(m *Metadata) string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a spec for nix purls? I only see nix as the package type. Why do you set the namespace? I'd leave it empty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, there isn’t a formal specification for Nix PURLs beyond nix as the package type. We initially set the namespace to include OSID (or fall back to "nixos") to provide additional context about the package's origin. I can update the implementation to return an empty namespace if that aligns better with the project's goals

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd keep namespace empty for now. I think it would be always nixos and that can be derived from the package type.

Context: For debian namespace is relevant, as it might be ubuntu for example. Ubuntu has a different vuln feed than debian afaik.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the code, removed the toNamespace function, and modified the Ecosystem function to return an empty string, similar to the behavior for Homebrew. Since there is no defined ecosystem for Nix, I aligned the implementation with that of the Homebrew extractor

Let me know if this works for you

Ref: https://ossf.github.io/osv-schema/#debian-vulnerability

Copy link
Collaborator

@vpasdf vpasdf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the highlighted issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants