Skip to content

Add mkEnableTargetWith and use it for documenting dynamic autoEnable conditions#1244

Merged
danth merged 7 commits intonix-community:masterfrom
MattSturgeon:mkEnableTargetWith
Jun 9, 2025
Merged

Add mkEnableTargetWith and use it for documenting dynamic autoEnable conditions#1244
danth merged 7 commits intonix-community:masterfrom
MattSturgeon:mkEnableTargetWith

Conversation

@MattSturgeon
Copy link
Copy Markdown
Member

@MattSturgeon MattSturgeon commented May 9, 2025

Note

This PR is comprised of intentionally separate commits, please don't squash 🙂

This is a solution to the issues uncovered by #1212. This should fix #98 (not tested).

  • Avoid evaluating dynamic conditions while rendering the docs.
  • Define literal expressions describing dynamic conditions.
  • Tested: all workarounds can be removed in #1212, when merged with this PR.

Previously, the literal markdown same as `stylix.autoEnable` was used. When an additional conditionText is supplied, it will now use the literal expression stylix.autoEnable && ${expr}.

If the expr contains any nix operators with a lower priority than &&, it will be auto-wrapped in parentheses, unless autoWrapExpr = false is used.

image

image

We could stick with the previous markdown approach, but I'm unsure what the best way to approach merging it with a autoEnableExpr or autoEnableText or autoEnableMD style arg would be. Suggestions and/or followup PRs welcome.

Things done

Notify relevant people

@MattSturgeon MattSturgeon force-pushed the mkEnableTargetWith branch from 6f5af4e to dcb83df Compare May 9, 2025 13:56
@MattSturgeon MattSturgeon requested a review from 0xda157 May 10, 2025 23:56
@stylix-automation stylix-automation bot added topic: documentation Documentation additions or improvements topic: nixos NixOS target topic: home-manager Home Manager target labels May 11, 2025
@MattSturgeon MattSturgeon force-pushed the mkEnableTargetWith branch 2 times, most recently from 6d0e88a to bf825ef Compare May 11, 2025 20:59
@MattSturgeon MattSturgeon changed the title Add mkEnableTargetWith and use if for documenting dynamic autoEnable conditions Add mkEnableTargetWith and use it for documenting dynamic autoEnable conditions May 15, 2025
@MattSturgeon

This comment was marked as outdated.

@MattSturgeon MattSturgeon requested a review from trueNAHO May 16, 2025 22:41
@0xda157

This comment was marked as outdated.

@MattSturgeon

This comment was marked as resolved.

@0xda157 0xda157 mentioned this pull request May 20, 2025
5 tasks
Copy link
Copy Markdown
Member

@trueNAHO trueNAHO left a comment

Choose a reason for hiding this comment

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

The implementation looks very nice :)

Should we merge this patchset with the following merge commit message:

treewide: add and apply mkEnableIf and mkEnableTargetWith functions

Link: https://github.com/nix-community/stylix/pull/1244

Reviewed-by: awwpotato <awwpotato@voidq.com>
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>

@MattSturgeon MattSturgeon requested a review from trueNAHO May 28, 2025 16:50
@stylix-automation stylix-automation bot added the status: merge conflict Merge conflict label May 31, 2025
@stylix-automation stylix-automation bot removed the status: merge conflict Merge conflict label Jun 1, 2025
@stylix-automation stylix-automation bot added the status: merge conflict Merge conflict label Jun 3, 2025
Copy link
Copy Markdown
Member

@trueNAHO trueNAHO left a comment

Choose a reason for hiding this comment

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

it's getting frustrating to keep rebasing this, would it be possible to get a final review?

Sorry for letting this PR pend so long.

Either way, unless this patchset depends on new commits or this patchset would substantially change with the new commits, continuously running git rebase master is technically not required while the patchset itself is being discussed. A simpler approach would be to resolve the current state and git rebase master once at the very end just before merging the patchset.

Continuously running git rebase master does have the benefit that the patchset can be directly merged without requesting another git rebase master. This is a trade-off between being merge-ready and going insane with git rebase master. Although successfully completing git rebase master is its own reward.

Copy link
Copy Markdown
Member

@trueNAHO trueNAHO left a comment

Choose a reason for hiding this comment

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

Looks great, except for one small question.

I would adapt my previous merge commit message (not squash commit message) proposal to the following:

treewide: use mkEnableTargetWith for dynamic autoEnable conditions

Use the new mkEnableTargetWith function for dynamic autoEnable
conditions to prevent the evaluation of dynamic conditions during
documentation rendering.

The 'same as `stylix.autoEnable`' defaultText is replaced with
'stylix.autoEnable' or 'stylix.autoEnable && ${autoEnableExpr}'
depending on whether autoEnableExpr is provided. For readability,
autoEnable expressions containing Nix operators of lower precedence than
'&&' are automatically wrapped in parentheses, unless autoWrapExpr is
disabled.

Closes: https://github.com/nix-community/stylix/issues/98
Link: https://github.com/nix-community/stylix/pull/1244

Reviewed-by: awwpotato <awwpotato@voidq.com>
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
Reviewed-by: Daniel Thwaites <danth@danth.me>

Let's optimistically close #98 with this patchset. If this issue is in fact not resolved, we can simply re-open it.

MattSturgeon and others added 7 commits June 4, 2025 15:48
Drop the redundant "same as" prefix and instead use a `literalExpression`.

Co-authored-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
Refactor `mkEnableTarget` and `mkEnableWallpaper` to use `mkEnableIf`.
This allows correctly documenting dynamic enable conditions.

E.g:
```nix
    enable = mkEnableTargetWith {
      name = "QT";
      autoEnable = pkgs.stdenv.hostPlatform.isLinux;
      autoEnableExpr = "pkgs.stdenv.hostPlatform.isLinux";
    };
```

`autoEnableExpr` will be wrapped in parentheses if it contains a nix
operator with lower precedence than `&&`.

Added a note in the docs mentioning `mkEnableTarget` should either have
a static `autoEnable` or specify `autoEnableExpr`.
Ensure enable options with dynamic `autoEnable` are documented
correctly.
@MattSturgeon
Copy link
Copy Markdown
Member Author

MattSturgeon commented Jun 4, 2025

I would adapt my previous merge commit message (not squash commit message) proposal to the following:

SGTM

Let's optimistically close #98 with this patchset. If this issue is in fact not resolved, we can simply re-open it.

SGTM. There are likely other cases of unintentionally dynamic docs values this PR hasn't caught, since it doesn't introduce any enforcement. But let's be optimistic for now!

Copy link
Copy Markdown
Member

@danth danth left a comment

Choose a reason for hiding this comment

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

Latest revision looks good to me. Thanks for working on this :))

@danth danth merged commit d73d8f6 into nix-community:master Jun 9, 2025
5 checks passed
@stylix-automation
Copy link
Copy Markdown
Contributor

Successfully created backport PR for release-25.05:

@MattSturgeon MattSturgeon deleted the mkEnableTargetWith branch June 9, 2025 15:24
danth added a commit that referenced this pull request Jun 9, 2025
#1244)

Use the new `mkEnableTargetWith` function for dynamic `autoEnable`
conditions to prevent the evaluation of dynamic conditions during
documentation rendering.

The "same as `stylix.autoEnable`" `defaultText` is replaced with
`stylix.autoEnable` or `stylix.autoEnable && ${autoEnableExpr}`,
depending on whether `autoEnableExpr` is provided. For readability,
`autoEnable` expressions containing Nix operators of lower precedence
than `&&` are automatically wrapped in parentheses, unless
`autoWrapExpr` is disabled.

Closes: #98
Link: #1244

Reviewed-by: awwpotato <awwpotato@voidq.com>
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
Reviewed-by: Daniel Thwaites <danth@danth.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: documentation Documentation additions or improvements topic: home-manager Home Manager target topic: nixos NixOS target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Breaks documentation.nixos.includeAllModules

4 participants