Open stepbrobd opened 2 months ago
cc @fricklerhandwerk
This is in principle possible but likely very inefficient, already because by default the entire module list's import graph is traversed eagerly. I recommend doing a quick hack and running a comparison.
Also file location should be stored in the module value IIRC, please check the module system source.
I tried running the following for a couple times, and the result seem to settle around 0.72s
$ time nix-instantiate --eval --expr 'let lib = import <nixpkgs/lib>; in (lib.evalModules { modules = (map (m: lib.setDefaultModuleLocation m m) (import (<nixpkgs> + "/nixos/modules/module-list.nix"))) ++ [{ nixpkgs.hostPlatform = builtins.currentSystem; }]; }).options' > /dev/null
nix-instantiate --eval --expr > /dev/null 0.71s user 0.08s system 97% cpu 0.805 total
However, in the REPL, unsafeGetAttrPos
seem to return null
for all attrsets under options
Context: https://github.com/ngi-nix/ngipkgs/pull/305#discussion_r1654628524
TLDR:
Currently, in ngipkgs, we are re-exposing nixpkgs modules like this:
But the ideal way to expose those modules would be this:
Proposed solution:
We can call
evalModules
on https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/module-list.nix (AFAIK this is where all default NixOS modules are imported from) and getoptions
on the result, finally, useunsafeGetAttrPos
to get the file location.Am I missing anything? I want to double check here before I go on and implement this