[M5+] use devbox attr_paths for pinned-dep nixpkgs attr
This commit is contained in:
@@ -42,14 +42,19 @@ auto sanitize_input_attr(std::string_view name, std::string_view version)
|
||||
return std::format("nixpkgs_{}_{}", sanitize(name), sanitize(version));
|
||||
}
|
||||
|
||||
auto find_lockfile_rev(const lockfile::Lockfile& lock, const std::string& name,
|
||||
const std::string& version) -> std::optional<std::string> {
|
||||
struct LockfileRef {
|
||||
std::optional<std::string> rev;
|
||||
std::optional<std::string> attr;
|
||||
};
|
||||
|
||||
auto find_lockfile_ref(const lockfile::Lockfile& lock, const std::string& name,
|
||||
const std::string& version) -> LockfileRef {
|
||||
for (const auto& p : lock.packages) {
|
||||
if (p.name == name && p.version == version) {
|
||||
return p.nixpkgs_rev;
|
||||
return LockfileRef{.rev = p.nixpkgs_rev, .attr = p.nixpkgs_attr};
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
return LockfileRef{};
|
||||
}
|
||||
|
||||
auto build_bindings(const GenerateInputs& in) -> std::vector<DepBinding> {
|
||||
@@ -58,12 +63,19 @@ auto build_bindings(const GenerateInputs& in) -> std::vector<DepBinding> {
|
||||
for (std::size_t i = 0; i < in.manifest.dependencies.size(); ++i) {
|
||||
const auto& dep = in.manifest.dependencies[i];
|
||||
const auto& rec = in.recipes[i];
|
||||
auto ref = find_lockfile_ref(in.lock, dep.name, dep.version_spec);
|
||||
// For pinned deps the lockfile's nixpkgs_attr is authoritative
|
||||
// (it came from devbox's attr_paths for this specific rev). The
|
||||
// curated recipe's attr only applies to nixos-unstable, so it's
|
||||
// wrong when the dep pulls from a different rev.
|
||||
std::string attr = (ref.attr && !ref.attr->empty()) ? *ref.attr
|
||||
: rec.nixpkgs_attr;
|
||||
DepBinding b{
|
||||
.name = dep.name,
|
||||
.version = dep.version_spec,
|
||||
.nixpkgs_attr = rec.nixpkgs_attr,
|
||||
.nixpkgs_attr = std::move(attr),
|
||||
.sanitized = sanitize_input_attr(dep.name, dep.version_spec),
|
||||
.rev = find_lockfile_rev(in.lock, dep.name, dep.version_spec),
|
||||
.rev = std::move(ref.rev),
|
||||
};
|
||||
out.push_back(std::move(b));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user