Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
Loading...
Searching...
No Matches
path-references.hh File Reference
#include "nix/store/references.hh"
#include "nix/store/path.hh"
#include "nix/util/source-accessor.hh"
#include <functional>
#include <vector>

Go to the source code of this file.

Classes

class  nix::PathRefScanSink
struct  nix::FileRefScanResult

Functions

StorePathSet nix::scanForReferences (Sink &toTee, const std::filesystem::path &path, const StorePathSet &refs)
void nix::scanForReferencesDeep (SourceAccessor &accessor, const CanonPath &rootPath, const StorePathSet &refs, fun< void(FileRefScanResult)> callback)
std::map< CanonPath, StorePathSet > nix::scanForReferencesDeep (SourceAccessor &accessor, const CanonPath &rootPath, const StorePathSet &refs)

Function Documentation

◆ scanForReferencesDeep() [1/2]

std::map< CanonPath, StorePathSet > nix::scanForReferencesDeep ( SourceAccessor & accessor,
const CanonPath & rootPath,
const StorePathSet & refs )

Scan a store path tree and return which references appear in which files.

This is a convenience wrapper around the callback-based scanForReferencesDeep() that collects all results into a map for efficient lookups.

Note: This function only searches for the hash part of store paths, not the name part. See the callback-based overload for details.

Parameters
accessorSource accessor to read the tree
rootPathRoot path to scan
refsSet of store paths to search for
Returns
Map from file paths to the set of references found in each file

◆ scanForReferencesDeep() [2/2]

void nix::scanForReferencesDeep ( SourceAccessor & accessor,
const CanonPath & rootPath,
const StorePathSet & refs,
fun< void(FileRefScanResult)> callback )

Scan a store path tree and report which references appear in which files.

This is like scanForReferences() but provides per-file granularity. Useful for cycle detection and detailed dependency analysis like nix why-depends --precise.

The function walks the tree using the provided accessor and streams each file's contents through a RefScanSink to detect hash references. For each file that contains at least one reference, a callback is invoked with the file path and the set of references found.

Note: This function only searches for the hash part of store paths (e.g., "dc04vv14dak1c1r48qa0m23vr9jy8sm0"), not the name part. A store path like "/nix/store/dc04vv14dak1c1r48qa0m23vr9jy8sm0-foo" will be detected if the hash appears anywhere in the scanned content, regardless of the "-foo" suffix.

Parameters
accessorSource accessor to read the tree
rootPathRoot path to scan
refsSet of store paths to search for
callbackCalled for each file that contains at least one reference