doc: ensure config is not used in option docs

With a few exceptions for `lib.stylix` functions.

Once these exceptions are removed, we will have solved the issue with
NixOS's documentation.nixos.includeAllModules option.

See https://github.com/nix-community/stylix/issues/98
This commit is contained in:
Matt Sturgeon 2025-06-10 19:33:29 +01:00 committed by awwpotato
parent e1ae98f979
commit 100b968012
2 changed files with 41 additions and 19 deletions

View file

@ -25,12 +25,47 @@ let
}) pkgs.formats;
};
# A stub config used while evaluating the stylix modules for the docs
#
# TODO: remove all dependency on `config` and simplify to `noConfig = null`.
# Doing that should resolve https://github.com/nix-community/stylix/issues/98
noConfig =
let
configuration = evalDocs {
# The config.lib option, as found in NixOS and home-manager.
# Required by the `target.nix` module.
options.lib = lib.mkOption {
type = lib.types.attrsOf lib.types.attrs;
description = ''
This option allows modules to define helper functions, constants, etc.
'';
default = { };
visible = false;
};
# The target.nix module defines functions that are currently needed to
# declare options
imports = [ ../stylix/target.nix ];
};
in
{
lib.stylix = {
inherit (configuration.config.lib.stylix)
mkEnableIf
mkEnableTarget
mkEnableTargetWith
mkEnableWallpaper
;
};
};
evalDocs =
module:
lib.evalModules {
modules = [ ./eval_compat.nix ] ++ lib.toList module;
specialArgs = {
pkgs = noPkgs;
config = noConfig;
};
};

View file

@ -1,24 +1,11 @@
{ lib, ... }:
{
options = {
# Declare the arbitrarily named __stub attribute to allow modules to evaluate
# 'options.programs ? «OPTION»'.
#
# TODO: Replace 'options.programs ? «OPTION»' instances with
# 'options ? programs.«OPTION»' to remove this __stub workaround.
programs.__stub = lib.mkSinkUndeclaredOptions { };
# The config.lib option, as found in NixOS and home-manager.
# Many option declarations depend on `config.lib.stylix`.
lib = lib.mkOption {
type = lib.types.attrsOf lib.types.attrs;
description = ''
This option allows modules to define helper functions, constants, etc.
'';
default = { };
visible = false;
};
};
# Declare the arbitrarily named __stub attribute to allow modules to evaluate
# 'options.programs ? «OPTION»'.
#
# TODO: Replace 'options.programs ? «OPTION»' instances with
# 'options ? programs.«OPTION»' to remove this __stub workaround.
options.programs.__stub = lib.mkSinkUndeclaredOptions { };
# Third-party options are not included in the module eval,
# so disable checking options definitions have matching declarations