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

nix flake check: Allow modules attribute #10860

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

roberth
Copy link
Member

@roberth roberth commented Jun 5, 2024

Motivation

Do not warn about another known community attribute, which solves the problem for potentially all "modules" attributes.

Contrext

This is intended as a module system "library" in the format

<flake>.modules.<class>.<name>

where class is e.g. "nixos" or "homeManager", and the name is of the author's choice.

Modules that can be loaded in any module system application should use the name "generic".

Priorities and Process

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

This is intended as a module system "library" in the format

<flake>.modules.<class>.<name>

where class is e.g. "nixos" or "homeManager", and the name
is of the author's choice.

Modules that can be loaded in any module system application should
use the name "generic".

- Implemented in the module system in NixOS/nixpkgs#197547

- Class parameter for checking: https://nixos.org/manual/nixpkgs/stable/index.html#module-system-lib-evalModules-param-class
@roberth roberth requested a review from edolstra as a code owner June 5, 2024 11:22
@github-actions github-actions bot added the new-cli Relating to the "nix" command label Jun 5, 2024
@roberth roberth added the flakes label Jun 5, 2024
@edolstra
Copy link
Member

edolstra commented Jun 5, 2024

Not really in favor of this since such a generic attribute would be uncheckable via flake schemas (#8892). So then we may as well provide a flake output attribute named "generic" or "freeform" or something like that.

I'm also not convinced that a two-level hierarchy modules.<class>.<name> is any better than <class>Modules.<name>.

Are there any real-world use cases for modules that can be loaded into any module system?

@Mic92
Copy link
Member

Mic92 commented Jun 6, 2024

Something to consider is that the duplication would make it harder for nix tooling. Now you would need to check both .nixosModules and .modules.nixos, so any change needs to have a very good reason to justify the cost onto the ecosystem. Do we have stats how widely this is used?

@roberth
Copy link
Member Author

roberth commented Jun 6, 2024

@edolstra what is even checkable about modules? Their syntax can be attrsets or functions, and it's only since recently that we can potentially check some modules, if they set _class, which kinda needs to be done by frameworks, which is rare for now.
Option definitions are not checkable without having a full configuration, and knowing which option(s) must be valid for a given module system application. The latter could be taught by hardcoding or "schemas", but the prior makes it a non-starter.

I'm also not convinced that a two-level hierarchy modules.<class>.<name> is any better than <class>Modules.<name>.

It's a single schema for all module system applications. This allows for more generalized tooling, such as aforementioned frameworks, a library that makes imports more convenient, that kind of thing. All while saving unnecessary boilerplate.
By removing that boilerplate, it is also feasible to have more custom classes, such as configurations for individual services (ie at the submodule level when applied in NixOS, etc). These are new usages of the module system; for instance a design for RFC 163 Portable Service Layer would make these patterns more prevalent, and therefore make the reduction of flake schema boilerplate actually useful.

Are there any real-world use cases for modules that can be loaded into any module system?

This is only relevant for modules.generic.<name>, but yes, they do exist. Examples:

  • assertions.nix
  • documentation generation (assuming a pkgs module argument perhaps, but that's available in most module system applications)
  • misc/nixpkgs.nix (or a replacement without the legacy options)
  • meta.nix

There's also interest in having generic modules for external reuse

Now you would need to check both .nixosModules and .modules.nixos, so any change needs to have a very good reason to justify the cost onto the ecosystem.

The very good reason that justifies it is that it allows modules for all module system applications to be checked with the same code and no per-application boilerplate. We could deprecate all .<class>Modules, reducing the complexity of the ecosystem rather than increasing it.

Do we have stats how widely this is used?

No, but I don't think it's all that relevant.
How should conventions be changed? This exists in no-man's land between Nix and many other organizational boundaries.
A worse but good enough solution already exists, and nobody has signaled that modules.* might actually become a replacement. So why would the ecosystem anticipate a change that might not come?

Nonetheless, #6257 is a 3rd percentile 👍 issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flakes new-cli Relating to the "nix" command
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants