Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(re-)exposing upstream (nixpkgs) modules #329

Open
stepbrobd opened this issue Aug 6, 2024 · 3 comments
Open

(re-)exposing upstream (nixpkgs) modules #329

stepbrobd opened this issue Aug 6, 2024 · 3 comments
Labels
maintenance Cleanup, refactoring, improving discoverability, tending to continuos integration service Create a NixOS service module

Comments

@stepbrobd
Copy link
Member

Context: #305 (comment)

TLDR:

Currently, in ngipkgs, we are re-exposing nixpkgs modules like this:

modules.services.forgejo = "${sources.inputs.nixpkgs}/nixos/modules/services/misc/forgejo.nix";

But the ideal way to expose those modules would be this:

modules.services.forejo = nixos.modules.services.forejo;

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 get options on the result, finally, use unsafeGetAttrPos to get the file location.

Am I missing anything? I want to double check here before I go on and implement this

@stepbrobd
Copy link
Member Author

cc @fricklerhandwerk

@stepbrobd stepbrobd added service Create a NixOS service module maintenance Cleanup, refactoring, improving discoverability, tending to continuos integration labels Aug 6, 2024
@fricklerhandwerk
Copy link
Collaborator

fricklerhandwerk commented Aug 6, 2024

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.

@stepbrobd
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Cleanup, refactoring, improving discoverability, tending to continuos integration service Create a NixOS service module
Projects
None yet
Development

No branches or pull requests

2 participants