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

Expose some additional nixosModules #261660

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

Conversation

sellout
Copy link
Contributor

@sellout sellout commented Oct 17, 2023

These are “general” modules that provide options without config and are already relied on by other projects (such as home-manager). Exposing them this way makes them an explicit part of the nixpkgs flake interface and can allow other projects to use, e.g.,

nixpkgs.nixosModules.assertions

rather than something like

(pkgs.path + "/nixos/modules/misc/assertions.nix")

which is bad not only because it treats the directory structure of nixpkgs as an interface, but also because it shouldn’t be necessary to have pkgs at the point modules are loaded (as opposed to when they are applied).

These are “general” modules that provide options without config and are already
relied on by other projects (such as home-manager). Exposing them this way makes
them an explicit part of the nixpkgs flake interface and can allow other
projects to use, e.g.,

    nixpkgs.nixosModules.assertions

rather than something like

    (pkgs.path + "/nixos/modules/misc/assertions.nix")

which is bad not only because it treats the directory structure of nixpkgs as an
interface, but also because it shouldn’t be necessary to have `pkgs` at the
point modules are loaded (as opposed to when they are applied).
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Oct 17, 2023
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 19, 2024
@sellout sellout requested a review from roberth May 17, 2024 14:42
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, but we have some work to do before we make these modules official.

These modules are already loaded by NixOS, so the use case they serve is either

  • for disabling
    • in these cases: not feasible, unless replaced by equivalent module
      • a very minor use case, for which it's fine or preferable to just use the paths
  • publish for use by other projects
    • your use case

Publishing modules as attributes will come with some expectations that aren't met. Currently they don't have a well defined scope. Rather, they're quite arbitrary sets of implementation details. (And if you're ok with relying on implementation details, that's what file paths are for)

More concretely, because they haven't been developed as "stand alone" modules, they have problems, at least some of which I've highlighted in the file comments.
I think they're significant problems and I wouldn't be comfortable suggesting that others use it, and make all the other Nixpkgs maintainers half-responsible for those problems.

Before we make any module public, I think they should have the following:

  • Designated maintainers
    • Maybe not using meta.maintainers, because the module that declares that is optional; it would be an unnecessary constraint on module system applications that want to use these modules. A comment or CODEOWNERS entry would be sufficient.
  • Unit tests, i.e. that don't load NixOS
  • Independent documentation. Could be included in the Nixpkgs manual, but must not rely on NixOS for its context.

@@ -56,6 +56,9 @@
legacyPackages = forAllSystems (system: import ./. { inherit system; });

nixosModules = {
assertions = ./nixos/modules/misc/assertions.nix;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has only half of the logic, so I'm surprised that other projects use it.
Maybe #207187 is worth revisiting.

It's not a NixOS module if it's supposed to be used in other projects, so it should be moved to modules.generic. (See also NixOS/nix#6257)

@@ -56,6 +56,9 @@
legacyPackages = forAllSystems (system: import ./. { inherit system; });

nixosModules = {
assertions = ./nixos/modules/misc/assertions.nix;
lib = ./nixos/modules/misc/lib.nix;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one has a bug. Type should be lazyAttrsOf.
Not really a NixOS module either.

@@ -56,6 +56,9 @@
legacyPackages = forAllSystems (system: import ./. { inherit system; });

nixosModules = {
assertions = ./nixos/modules/misc/assertions.nix;
lib = ./nixos/modules/misc/lib.nix;
meta = ./nixos/modules/misc/meta.nix;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Meta" is not a suitable scope for a module. This file has meta.buildDocsInSandbox, meta.doc and meta.maintainers. It should probably be split into meta/docs.nix and meta/maintainers.nix, at least, but even then, those modules aren't usable on their own either.

@stale stale bot removed 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md labels May 17, 2024
@roberth roberth added 6.topic: flakes The experimental Nix feature 6.topic: module system About "NixOS" module system internals labels May 17, 2024
@sellout
Copy link
Contributor Author

sellout commented May 17, 2024

I like the idea, but we have some work to do before we make these modules official.

Thanks! This is exactly what I was hoping for. I’ll work on changes in this vein.

@sellout sellout marked this pull request as draft May 17, 2024 15:33
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: flakes The experimental Nix feature 6.topic: module system About "NixOS" module system internals 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants