Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 9 additions & 0 deletions .changeset/add_support_for_multiple_by_name_directories.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
default: minor
---

# Add support for multiple by-name directories

The goal is to be able to check package sets with nixpkgs-vet aswell.

See https://github.com/nixos/rfcs/pull/197
6 changes: 4 additions & 2 deletions .github/xrefcheck.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ exclusions:
- .github/issue_template.md
- .github/PULL_REQUEST_TEMPLATE/**/*
Comment thread
quantenzitrone marked this conversation as resolved.
Resolved
- .github/ISSUE_TEMPLATE/**/*
- tests/top-level/symlink-invalid/main/pkgs/by-name/fo/foo/foo
- tests/top-level/multiple-failures/main/pkgs/by-name/A/fo@/foo
- tests/integration/symlink-invalid/main/pkgs/by-name/fo/foo/foo
- tests/integration/symlink-invalid/main/pkgs/sets/fooPackages/by-name/fo/foo/foo
- tests/integration/multiple-failures/main/pkgs/by-name/A/fo@/foo
- tests/integration/multiple-failures/main/pkgs/sets/fooPackages/by-name/A/fo@/foo

# References to these paths will not be verified.
# List of glob patterns.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ colored = "3.1.1"
itertools = "0.15.0"
rowan = "0.17.0"
indoc = "2.0.7"
relative-path = "2.0.1"
relative-path = { version = "2.0.1", features = ["serde"] }
derive-enum-from-into = "0.2.1"
derive-new = "0.7.0"
derive_more = { version = "2.1.1", features = ["display"] }
Expand Down
8 changes: 8 additions & 0 deletions default-nixpkgs-vet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"package_sets": [
{
"by_name_subpath": "pkgs/by-name",
"attr_path": []
}
]
}
1 change: 1 addition & 0 deletions package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rustPlatform.buildRustPackage {
fileset = fs.unions [
./Cargo.lock
./Cargo.toml
./default-nixpkgs-vet.json
./src
./tests
];
Expand Down
58 changes: 38 additions & 20 deletions src/eval.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
# Takes a path to nixpkgs and a path to the json-encoded list of `pkgs/by-name` attributes.
# Takes a path to nixpkgs and a path to the json-encoded list of attributes in the by-name subpath.
#
# Returns a value containing information on all Nixpkgs attributes which is decoded on the Rust
# side. See ./eval.rs for the meaning of the returned values.
{ attrsPath, nixpkgsPath }:
{
packageNamesFilePath,
nixpkgsPath,
attrPath,
}:
let
attrs = builtins.fromJSON (builtins.readFile attrsPath);
attrs = builtins.fromJSON (builtins.readFile packageNamesFilePath);

# We need to check whether attributes are defined via callPackage of the same scope or not.
overlay = final: prev: {
inherit (import nixpkgsPath { }) lib;

# Adds information to each attribute about whether it's defined using this scope's `callPackage`
callPackage = fn: args: addCallPackageReference (prev.callPackage fn args);
};
# We need to check whether attributes are defined via callPackage of the same scope or not.
overlay =
final: prev:
if attrPath == [ ] then
{
# Adds information to each attribute about whether it's defined using this scope's `callPackage`
callPackage = fn: args: addCallPackageReference (prev.callPackage fn args);
}
else
lib.setAttrByPath attrPath (
(lib.getAttrFromPath attrPath prev).overrideScope (
final: prev: {
callPackage = fn: args: addCallPackageReference (final.newScope { } fn args);
}
)
);

# We can't just replace attribute values with their info in the overlay, because attributes can
# depend on other attributes, so this would break evaluation.
Expand All @@ -25,13 +41,15 @@ let
# don't return the value directly and treat it as if it wasn't a `callPackage`.
value;

pkgs = import nixpkgsPath {
# Don't let the user's home directory influence this result.
config = { };
overlays = [ overlay ];
# We check evaluation and `callPackage` only for x86_64-linux. Not ideal, but hard to fix.
system = "x86_64-linux";
};
pkgs = lib.attrByPath attrPath { } (
import nixpkgsPath {
# Don't let the user's home directory influence this result.
config = { };
overlays = [ overlay ];
# We check evaluation and `callPackage` only for x86_64-linux. Not ideal, but hard to fix.
system = "x86_64-linux";
}
);

# See AttributeInfo in ./eval.rs for the meaning of this.
attrInfo = name: value: {
Expand Down Expand Up @@ -65,7 +83,7 @@ let
in
{
AttributeSet = {
is_derivation = pkgs.lib.isDerivation value;
is_derivation = lib.isDerivation value;
strict_deps = cleanPackage.strictDeps or false;
structured_attrs = cleanPackage.__structuredAttrs or false;
uses_license_list = builtins.isList (value.meta.license or null);
Expand All @@ -75,7 +93,7 @@ let
};
};

# Information on all attributes that are in `pkgs/by-name`.
# Information on all attributes that are in the by-name subpath.
byNameAttrs = builtins.listToAttrs (
map (name: {
inherit name;
Expand All @@ -88,12 +106,12 @@ let
}) attrs
);

# Information on all attributes that exist but are not in `pkgs/by-name`.
# We need this to enforce `pkgs/by-name` for new packages.
# Information on all attributes that exist but are not in the by-name subpath.
# We need this to enforce the by-name subpath for new packages.
nonByNameAttrs = builtins.mapAttrs (
name: value:
let
# Packages outside `pkgs/by-name` often fail evaluation, so we need to handle that.
# Packages outside the by-name subpath often fail evaluation, so we need to handle that.
output = attrInfo name value;
result = builtins.tryEval (builtins.deepSeq output null);
in
Expand Down
Loading