From 79703eef083d70046873dbb86f08e2ff08f58197 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 10 Apr 2023 17:55:34 +0200 Subject: [PATCH] nixos,nixpkgs: Add module classes This allows modules that declare their class to be checked. While that's not most user modules, frameworks can take advantage of this by setting declaring the module class for their users. That way, the mistake of importing a module into the wrong hierarchy can be reported more clearly in some cases. --- doc/doc-support/default.nix | 5 ++++- nixos/lib/eval-cacheable-options.nix | 1 + nixos/lib/eval-config-minimal.nix | 4 +++- nixos/lib/testing/default.nix | 5 ++++- nixos/modules/misc/documentation.nix | 1 + pkgs/top-level/default.nix | 1 + 6 files changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/doc-support/default.nix b/doc/doc-support/default.nix index bea3e12a70b3..67195a4a58b0 100644 --- a/doc/doc-support/default.nix +++ b/doc/doc-support/default.nix @@ -45,7 +45,10 @@ let # NB: This file describes the Nixpkgs manual, which happens to use module # docs infra originally developed for NixOS. optionsDoc = pkgs.nixosOptionsDoc { - inherit (pkgs.lib.evalModules { modules = [ ../../pkgs/top-level/config.nix ]; }) options; + inherit (pkgs.lib.evalModules { + modules = [ ../../pkgs/top-level/config.nix ]; + specialArgs.class = "nixpkgsConfig"; + }) options; documentType = "none"; transformOptions = opt: opt // { diff --git a/nixos/lib/eval-cacheable-options.nix b/nixos/lib/eval-cacheable-options.nix index c3ba2ce66375..d26967ebe09b 100644 --- a/nixos/lib/eval-cacheable-options.nix +++ b/nixos/lib/eval-cacheable-options.nix @@ -33,6 +33,7 @@ let ]; specialArgs = { inherit config pkgs utils; + class = "nixos"; }; }; docs = import "${nixosPath}/doc/manual" { diff --git a/nixos/lib/eval-config-minimal.nix b/nixos/lib/eval-config-minimal.nix index d45b9ffd4261..7e28f4305127 100644 --- a/nixos/lib/eval-config-minimal.nix +++ b/nixos/lib/eval-config-minimal.nix @@ -40,7 +40,9 @@ let inherit prefix modules; specialArgs = { modulesPath = builtins.toString ../modules; - } // specialArgs; + } // specialArgs // { + class = "nixos"; + }; }; in diff --git a/nixos/lib/testing/default.nix b/nixos/lib/testing/default.nix index 9d4f9dbc43d7..1bd6278ce684 100644 --- a/nixos/lib/testing/default.nix +++ b/nixos/lib/testing/default.nix @@ -1,7 +1,10 @@ { lib }: let - evalTest = module: lib.evalModules { modules = testModules ++ [ module ]; }; + evalTest = module: lib.evalModules { + modules = testModules ++ [ module ]; + specialArgs.class = "nixosTest"; + }; runTest = module: (evalTest ({ config, ... }: { imports = [ module ]; result = config.test; })).config.result; testModules = [ diff --git a/nixos/modules/misc/documentation.nix b/nixos/modules/misc/documentation.nix index e0c6af4abe10..1821dd866cb1 100644 --- a/nixos/modules/misc/documentation.nix +++ b/nixos/modules/misc/documentation.nix @@ -39,6 +39,7 @@ let _module.check = false; } ] ++ docModules.eager; specialArgs = specialArgs // { + class = "nixos"; pkgs = scrubDerivations "pkgs" pkgs; # allow access to arbitrary options for eager modules, eg for getting # option types from lazy modules diff --git a/pkgs/top-level/default.nix b/pkgs/top-level/default.nix index b32aabc3a1fd..f54ce84aedad 100644 --- a/pkgs/top-level/default.nix +++ b/pkgs/top-level/default.nix @@ -82,6 +82,7 @@ in let config = config1; }) ]; + specialArgs.class = "nixpkgsConfig"; }; # take all the rest as-is