Skip to content

Commit 92623ed

Browse files
committed
Copied all tests and modified them to work with tcl. All pass!
1 parent 3438417 commit 92623ed

File tree

212 files changed

+862
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+862
-35
lines changed

src/eval.nix

Lines changed: 100 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,24 @@
88
configPath,
99
}:
1010
let
11-
# trace = builtins.trace
11+
# trace = builtins.trace;
1212
trace = (e1: e2: e2);
1313

14+
# https://discourse.nixos.org/t/modify-an-attrset-in-nix/29919/5
15+
removeAttrByPath =
16+
attrPath: set:
17+
pkgs.lib.updateManyAttrsByPath [
18+
{
19+
path = pkgs.lib.init attrPath;
20+
update = old: pkgs.lib.filterAttrs (n: v: n != (pkgs.lib.last attrPath)) old;
21+
}
22+
] set;
23+
removeAttrsByPaths =
24+
set: attrPathStrings:
25+
builtins.foldl' (acc: elem: removeAttrByPath elem acc) set (
26+
map (s: pkgs.lib.splitString "." s) attrPathStrings
27+
);
28+
1429
rawAttrs = trace "rawAttrs = ${(builtins.toJSON (builtins.fromJSON (builtins.readFile attrsPath)))}" (
1530
builtins.fromJSON (builtins.readFile attrsPath)
1631
);
@@ -116,12 +131,10 @@ let
116131
# Information on all attributes that are in a `by-name` directory.
117132
byNameAttrsForDir =
118133
byNameDir:
119-
pkgs.lib.mergeAttrsList (
120-
# pkgs.lib.foldl pkgs.lib.recursiveUpdate { } (
134+
builtins.foldl' pkgs.lib.recursiveUpdate { } (
121135
map (
122136
package:
123137
let
124-
# attrPath = trace "eval.nix:106: name = ${name}" (pkgs.lib.splitString "." name);
125138
attrPath = pkgs.lib.splitString "." package.attr_path;
126139
result = pkgs.lib.setAttrByPath attrPath {
127140
ByName =
@@ -216,7 +229,7 @@ let
216229
newName: newValue: markNonByNameAttribute (attrPath ++ [ newName ]) newValue
217230
) value;
218231
in
219-
(trace "recursing into name = ${builtins.toJSON pname}" (
232+
(trace "recursing into name = ${builtins.toJSON pname}, which has attributes ${builtins.toJSON (builtins.attrNames recursiveResult)}" (
220233
builtins.seq (trace "result of recursing into ${builtins.toJSON pname}: ${builtins.toJSON recursiveResult}" recursiveResult) (
221234
trace "done recursing into ${builtins.toJSON pname}" recursiveResult
222235
)
@@ -241,9 +254,17 @@ let
241254
# We need this to enforce placement in a `by-name` directory for new packages.
242255

243256
# Second-newest
257+
# nonByNameAttrs = (
258+
# builtins.mapAttrs markNonByNameAttribute (
259+
# builtins.removeAttrs pkgs (
260+
# allAttrPaths ++ [ "lib" ] # Need to exclude lib to avoid infinite recursion
261+
# )
262+
# )
263+
# );
264+
244265
nonByNameAttrs = (
245266
builtins.mapAttrs markNonByNameAttribute (
246-
builtins.removeAttrs pkgs (
267+
removeAttrsByPaths pkgs (
247268
allAttrPaths ++ [ "lib" ] # Need to exclude lib to avoid infinite recursion
248269
)
249270
)
@@ -269,8 +290,80 @@ let
269290
# }
270291
# ) (builtins.removeAttrs pkgs (attrs ++ [ "lib" ])); # Need to exclude lib to avoid infinite recursion
271292

293+
customMergeAttrs =
294+
byName: nonByName:
295+
let
296+
inherit (builtins) isAttrs;
297+
byNameNames = builtins.trace "byNameNames is ${builtins.toJSON (builtins.attrNames byName)}" (
298+
builtins.attrNames byName
299+
);
300+
nonByNameNames = builtins.trace "nonByNameNames is ${builtins.toJSON (builtins.attrNames nonByName)}" (
301+
builtins.attrNames nonByName
302+
);
303+
onlyByName = pkgs.lib.subtractLists nonByNameNames byNameNames;
304+
onlyNonByName = pkgs.lib.subtractLists byNameNames nonByNameNames;
305+
inBothLists = pkgs.lib.intersectLists byNameNames nonByNameNames;
306+
in
307+
builtins.listToAttrs (
308+
(map (x: {
309+
name = x;
310+
value = byName.${x};
311+
}) onlyByName)
312+
++ (map (x: {
313+
name = x;
314+
value = nonByName.${x};
315+
}) onlyNonByName)
316+
++ (map (
317+
x:
318+
builtins.trace
319+
"x = ${x}; byName.${x} = ${builtins.toJSON byName.${x}}; nonByName.${x} = ${builtins.toJSON nonByName.${x}}"
320+
(
321+
if
322+
!(isAttrs byName.${x}) # And nonByName.${x} is or is not an attrset, we don't care.
323+
then
324+
{
325+
name = x;
326+
value = nonByName.${x};
327+
}
328+
else if !(isAttrs nonByName.${x}) then
329+
throw "Shouldn't happen??? "
330+
else if byName.${x} ? "ByName" && nonByName.${x} ? "NonByName" then
331+
{
332+
name = x;
333+
value = {
334+
ByName = nonByName.${x}.NonByName;
335+
};
336+
}
337+
else if
338+
(builtins.removeAttrs byName.${x} [
339+
"NonByName"
340+
"ByName"
341+
]) != { }
342+
&& nonByName.${x} ? "NonByName"
343+
then
344+
{
345+
name = x;
346+
value = byName.${x};
347+
}
348+
else
349+
{
350+
name = x;
351+
value = customMergeAttrs byName.${x} nonByName.${x};
352+
}
353+
)
354+
) inBothLists)
355+
);
356+
272357
# All attributes
273-
attributes = byNameAttrs // nonByNameAttrs;
358+
# attributes = pkgs.lib.recursiveUpdateUntil (attrPath: left: right:
359+
# trace "eval.nix:293: attrPath ${builtins.toJSON attrPath}; left attrNames are ${if builtins.isAttrs left then (builtins.toJSON (builtins.attrNames left)) else "not an attrset"}; right attrNames are ${if builtins.isAttrs right then builtins.toJSON (builtins.attrNames right) else "not an attrset"}"
360+
# ((builtins.removeAttrs left ["NonByName" "ByName"]) != { } && right ? "NonByName")
361+
# # ||
362+
# # ((left ? "ByName" || left ? "NonByName") && (right ? "ByName" || right ? "NonByName"))
363+
# ) byNameAttrs nonByNameAttrs;
364+
365+
attributes = customMergeAttrs byNameAttrs nonByNameAttrs;
366+
274367
result =
275368
pkgs.lib.mapAttrsToListRecursiveCond
276369
(attrPath: attrValue: !((attrValue ? "NonByName") || (attrValue ? "ByName")))

src/eval.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub fn check_values(
213213
let nix_package = env::var("NIXPKGS_VET_NIX_PACKAGE")
214214
.with_context(|| "Could not get environment variable NIXPKGS_VET_NIX_PACKAGE")?;
215215

216-
// println!("package_names_path: {package_names_path:?}");
216+
println!("packages: {packages:?}");
217217

218218
// With restrict-eval, only paths in NIX_PATH can be accessed. We explicitly specify them here.
219219
let mut command = process::Command::new(format!("{nix_package}/bin/nix-instantiate"));
@@ -252,15 +252,25 @@ pub fn check_values(
252252
.output()
253253
.with_context(|| format!("Failed to run command {command:?}"))?;
254254

255+
println!(
256+
"{}:{}: result (stderr): {}",
257+
file!(),
258+
line!(),
259+
std::str::from_utf8(result.stderr.as_slice()).unwrap()
260+
);
261+
println!(
262+
"{}:{}: result (stdout): {}",
263+
file!(),
264+
line!(),
265+
std::str::from_utf8(result.stdout.as_slice()).unwrap()
266+
);
267+
255268
if !result.status.success() {
256269
// println!("{}:{}: : eval failed for {full_path}", file!(), line!());
257270
// Early return in case evaluation fails
258271
return Ok(npv_120::NixEvalError::new(String::from_utf8_lossy(&result.stderr)).into());
259272
}
260273

261-
// println!("{}:{}: result (stderr): {}", file!(), line!(), std::str::from_utf8(result.stderr.as_slice()).unwrap());
262-
// println!("{}:{}: result (stdout): {}", file!(), line!(), std::str::from_utf8(result.stdout.as_slice()).unwrap());
263-
264274
// Parse the resulting JSON value
265275
let attributes: Vec<(Vec<String>, Attribute)> = serde_json::from_slice(&result.stdout)
266276
.with_context(|| {

src/problem/npv_123.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl fmt::Display for NixFileContainsPathOutsideDirectory {
3333
Alternatives include:
3434
- If you are creating a new version of a package with a common file between versions, consider following the recommendation in https://github.com/NixOS/nixpkgs/tree/master/pkgs/by-name#recommendation-for-new-packages-with-multiple-versions.
3535
- If the path being referenced could be considered a stable interface with multiple uses, consider exposing it via a `pkgs` attribute, then taking it as a attribute argument in {PACKAGE_NIX_FILENAME}.
36-
- If the path being referenced is internal and has multiple uses, consider passing the file as an explicit `callPackage` argument in `pkgs/top-level/all-packages.nix`.
36+
- If the path being referenced is internal and has multiple uses, consider passing the file as an explicit `callPackage` argument in `pkgs/top-level/all-packages.nix` or equivalent.
3737
- If the path being referenced is internal and will need to be modified independently of the original, consider copying it into the {relative_package_dir} directory.
3838
"
3939
)

src/structure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub fn expected_by_name_dir_for_package(attr_path: &str, config: &Config) -> Opt
227227
// // Combine the package names contained within each shard into a longer list.
228228
// Ok(validation::sequence(shard_results).map(concat))
229229
// }
230-
#[derive(Serialize)]
230+
#[derive(Serialize, Debug)]
231231
pub struct ByNamePackage<'a> {
232232
pub attr_path: String,
233233
/*

tests/mock-nixpkgs.nix

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,10 @@ let
6868
byNameDir:
6969
let
7070
entries = builtins.readDir (
71-
builtins.trace
72-
"mock-nixpkgs.nix:73: full path = ${
73-
(lib.concatStringsSep "/" [
74-
(builtins.toString root)
75-
byNameDir.path
76-
])
77-
}"
78-
(
79-
lib.concatStringsSep "/" [
80-
(builtins.toString root)
81-
byNameDir.path
82-
]
83-
)
71+
lib.concatStringsSep "/" [
72+
(builtins.toString root)
73+
byNameDir.path
74+
]
8475
);
8576

8677
namesForShard =
@@ -120,9 +111,8 @@ let
120111
]
121112
)
122113
) fileNames;
123-
merged = lib.mergeAttrsList attrSetList;
124114
in
125-
merged;
115+
builtins.foldl' lib.recursiveUpdate { } attrSetList;
126116
in
127117
builtins.foldl' (acc: el: acc // el) { } (map namesForShard (builtins.attrNames entries));
128118

@@ -147,8 +137,8 @@ let
147137
&& (byNameDir.all_packages_path != null)
148138
&& (builtins.pathExists (root + byNameDir.all_packages_path))
149139
) byNameDirs;
150-
paths = map (byNameDir: byNameDir.all_packages_path) filteredByNameDirs;
151-
forEachPath = relativePath: import (root + relativePath);
140+
paths = map (byNameDir: (root + byNameDir.all_packages_path)) filteredByNameDirs;
141+
forEachPath = path: import path;
152142
in
153143
map forEachPath paths;
154144

tests/tcl/aliases/expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Validated successfully

tests/tcl/aliases/main/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import <test-nixpkgs> { root = ./.; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ someDrv }: someDrv
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
self: super: { baz = self.foo; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
self: super: { bar = self.foo; }

0 commit comments

Comments
 (0)