Skip to content

feat(nixpkgs-clarity): add the scan_nix_package pipeline for single nixpkg #1938 - #2291

Draft
tdruez wants to merge 8 commits into
mainfrom
2209-nix-pipeline
Draft

tdruez wants to merge 8 commits into
mainfrom
2209-nix-pipeline

Conversation

@tdruez

@tdruez tdruez commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Issues

Changes

  • Add the scan_nix_package pipeline, reusing all the deploy_to_develop steps
  • Validate the nixpkgs PURL and check that the commit is on the official master or release-* branches
  • Resolve the nixpkgs commit from search.devbox.sh when the PURL has no commit qualifier
  • Fetch the source with the nixpkgs patches applied, falling back to the upstream source
  • Download the package outputs from cache.nixos.org and extract them with nix-store --restore
  • Enable the ELF mapping by default
  • Scan the undeployed source files, keeping their not-deployed status
  • Create the Nix package from the nixpkgs metadata and store the uncovered licenses in its extra_data
  • Delete the Nix store paths and the nixpkgs tarballs cache at the end of each run
  • Install nix-bin and zstd in the full Docker image

Signed-off-by: tdruez <tdruez@aboutcode.org>
@tdruez
tdruez marked this pull request as draft November 5, 2026 07:16
Signed-off-by: tdruez <tdruez@aboutcode.org>
Signed-off-by: tdruez <tdruez@aboutcode.org>
Signed-off-by: tdruez <tdruez@aboutcode.org>

@chinyeungli chinyeungli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@tdruez It looks very good. I've made some comments and see if you agree.

Comment thread scanpipe/pipelines/scan_nix_package.py Resolved
Comment on lines +140 to +144
is_fetched = nix.fetch_binary(
store_path=store_path,
destination=self.project.codebase_path / d2d.TO / output,
download_directory=self.project.tmp_path,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If there is no "selected_output", all outputs from self.metadata["outputs"].items() will be fetched such as dev, doc, man, info, etc. Those contain source-like content that maps cleanly to from/ and may produces noise in the D2D report, the binary side is supposed to represent the deployed artifacts, not the whole package.

Should we default to a preferred list instead, e.g. out, debug, and fall back to all outputs if none of those exist?

Comment thread scanpipe/pipes/nix.py
Comment on lines +115 to +128
PATCHED_SOURCE_EXPRESSION = (
NIXPKGS_EXPRESSION
+ """
pkgs.applyPatches {
name = "source";
src = package.src;
patches = package.patches or [ ];
prePatch = package.prePatch or "";
postPatch = package.postPatch or "";
}
"""
)

UPSTREAM_SOURCE_EXPRESSION = NIXPKGS_EXPRESSION + "package.src"

@chinyeungli chinyeungli Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we add a guard when there is no "src" attribute?
Two examples — these .nix files don't have a src attribute:

Something like

if !(package ? src) then
   throw "PACKAGE_HAS_NO_SOURCE"
else

and then catch the error in fetch_source ()?

Even without source, the pipeline can still fetch the binary from the cache and create the package from the nixpkgs metadata, so it's worth finishing with a warning rather than failing the run.

If we plan to add a guard, perhaps we can set a self.d2d_enable field to bypass all the d2d_steps.

I think we can skip srcs support in v1 and add it in a later release.

This branch has not been deployed

No deployments
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.

nixpkgs-clarity: Design and implement Scancode pipeline for single nixpkg

2 participants