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

doc: explain where the "pkgs" comes from in a module #107601

Merged
merged 1 commit into from Mar 3, 2021

Conversation

laikq
Copy link
Contributor

@laikq laikq commented Dec 25, 2020

Ahoj! While reading the NixOS manual, I noticed that I didn't really see where "pkgs" is explained. So, I added a link to the "Writing Modules" (which could also be titled "Understanding Modules") chapter, and explained that pkgs is usually taken from the nixpkgs entry of the NIX_PATH environment variable. For me, this was not at all obvious from reading the manual.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@jtojnar
Copy link
Contributor

jtojnar commented Dec 25, 2020

To be precise, it comes from this module:

_module.args = {
pkgs = finalPkgs;
};

when not overridden here:

_module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_);

The former defaults to location relative to the module:

defaultPkgs = import ../../.. {
inherit (cfg) config overlays localSystem crossSystem;
};

so it really depends on how the system is built by nixos-rebuild. It does indeed use <nixpkgs/nixos> by default:

pathToConfig="$(nixBuild '<nixpkgs/nixos>' --no-out-link -A system "${extraBuildFlags[@]}")"

@laikq
Copy link
Contributor Author

laikq commented Dec 25, 2020

Thank you for this explanation, I guess I can update my PR based on that.

It also seems like this could benefit from an overview section in the manual, something like "Anatomy of NixOS modules"

@laikq laikq marked this pull request as draft January 3, 2021 12:34
@tomberek
Copy link
Contributor

Manual builds fine. PR needs a squash. @laikq, ready for merge?

@laikq laikq marked this pull request as ready for review March 3, 2021 10:08
@laikq
Copy link
Contributor Author

laikq commented Mar 3, 2021

Yes! I wanted to prepare a more in-depth explanation based on what @jtojnar wrote, but realistically this won't happen soon. I think this change to the documentation (as it is now) is very small, but I guess it is also not very controversial and some users might benefit from it.

The manual mentions how "[config and pkgs] are explained later". Added a link
to where they are explained, and a hint pointing to the NIX_PATH variable.
@tomberek tomberek merged commit 5c99d24 into NixOS:master Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants