-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
Description
Describe the bug
I'm playing with a tool to explore and validate derivations in nixpkgs. I encountered a few sets where some attributes generate unrecoverable exceptions. One of them is ocamlPackages.janeStreet_0_15. AFAIU the set can't be used as is as some packages require dependencies to be satisfied from the outside self.
The reproducer:
nix-instantiate --strict --eval --expr 'with import <nixpkgs> {}; lib.length (lib.attrNames (lib.filterAttrs (n: v: let e = builtins.tryEval (v.drvPath or (throw "not a drv")); in e.success) ocamlPackages.janeStreet_0_15))'
error:
… while calling the 'length' builtin
at «string»:1:27:
1| with import <nixpkgs> {}; lib.length (lib.attrNames (lib.filterAttrs (n: v: let e = builtins.tryEval (v.drvPath or (throw "not a drv")); in e.success) ocamlPackages.janeStreet_0_15))
| ^
… while calling the 'attrNames' builtin
at «string»:1:39:
1| with import <nixpkgs> {}; lib.length (lib.attrNames (lib.filterAttrs (n: v: let e = builtins.tryEval (v.drvPath or (throw "not a drv")); in e.success) ocamlPackages.janeStreet_0_15))
| ^
(stack trace truncated; use '--show-trace' to show the full trace)
error: undefined variable 'inotify'
at /nix/store/817w4lar0iawdyhv8v4hn2vmmk8s36v7-source/pkgs/development/ocaml-modules/janestreet/0.15.nix:81:42:
80| meta.description = "Async wrapper for inotify";
81| propagatedBuildInputs = [ async_find inotify ];
| ^
82| };
Note how inotify reference fails to resolve and break the whole evaluation even in presence of tryEval.FOr comparison filanl eval is fine:
nix-instantiate --strict --eval --expr 'with import <nixpkgs> {}; lib.length (lib.attrNames (lib.filterAttrs (n: v: let e = builtins.tryEval (v.drvPath or (throw "not a drv")); in e.success) ocamlPackages))'
940
What would be the best way to fix it? The simplest (but tedious) could be to add unsatisfied dependencies as throw stubs, like:
--- a/pkgs/development/ocaml-modules/janestreet/0.15.nix
+++ b/pkgs/development/ocaml-modules/janestreet/0.15.nix
@@ -6,6 +6,8 @@
, ocaml
, openssl
, zstd
+
+, inotify ? throw "'inotify' should be present in 'self' argument"
}:But it will require quite a few entries. I can propose a PR if it's sensible.
WDYT? Is it something worth fixing to ease attribute traversal from within nix?
Fun fact: stanc does use that incomplete set and happens to work as it does not use packages with unsatisfied depends:
pkgs/top-level/all-packages.nix- stanc = callPackage ../development/compilers/stanc {
pkgs/top-level/all-packages.nix: ocamlPackages = ocaml-ng.ocamlPackages_4_14_janeStreet_0_15;
pkgs/top-level/all-packages.nix- };
Expected behavior
Ideally the evaluation of ocamlPackages.janeStreet_0_15 should not produce unrecoverable exceptions to ease attribute discovery.
Notify maintainers
Metadata
[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
- system: `"x86_64-linux"`
- host os: `Linux 6.6.8, NixOS, 24.05 (Uakari), 24.05.20231230.9fafaa3`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.19.2`
- channels(root): `""`
- channels(slyfox): `""`
- nixpkgs: `/run/current-system/sw/share/nixos-flakes/inputs/nixpkgs`Add a 👍 reaction to issues you find important.