Skip to content

flake: add diff-plugins command #3510

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

Merged
merged 1 commit into from
Jun 27, 2025

Conversation

MattSturgeon
Copy link
Member

@MattSturgeon MattSturgeon commented Jun 26, 2025

Prints the plugins added or removed when compared to a particular nixvim revision.

This is intended as a starting point for automatically generating the matrix announcements, as attempted in #2255 and #2593.

I may consider moving the python script into the ci/ directory to make sparse-checkout easier if it ends up being used by CI workflows. Although, saying that the full checkout would be needed to compare its plugins to the other anyway...

A CI workflow can use this script by supplying github.event.before, which for on: push events comes from the push webhook event payload. Alternatively we might use github.event.pull_request.base.sha from pull_request_target, since that also gives us access to things like github.event.pull_request.number (pull_request: closed webhook event).

This script can be tested locally by running diff-plugins <some_sha> to compare the current local nixvim to some arbitrary "before" state.

Prints the plugins added or removed when compared to a particular nixvim
revision.
Comment on lines +75 to +104
def list_plugins(flake: str) -> list[str]:
"""
Gets a list of plugins that exist in the flake.
Grouped as "plugins" and "colorschemes"
"""
expr = """
options:
builtins.listToAttrs (
map
(name: {
inherit name;
value = builtins.attrNames options.${name};
})
[
"plugins"
"colorschemes"
]
)
"""
cmd = [
"nix",
"eval",
f"{flake}#nixvimConfiguration.options",
"--apply",
expr,
"--json",
]
out = subprocess.check_output(cmd)
# Parse as json, converting the lists to sets
return {k: set(v) for k, v in json.loads(out).items()}
Copy link
Contributor

@khaneliman khaneliman Jun 26, 2025

Choose a reason for hiding this comment

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

Does it make sense to try just leveraging our list-plugins package/script?

Copy link
Member Author

@MattSturgeon MattSturgeon Jun 26, 2025

Choose a reason for hiding this comment

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

I thought about it briefly, but I think it's simpler to keep them separate?

The list-plugins script is meant to print a user-readable summary of the plugins, right? While this one is meant to print a JSON diff.

Unless you have ideas for how we could do it without adding too much complexity to the list-plugins script?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this looks to be a pretty simple implementation. We can always refactor later since it might require some more rework for list-plugins

Copy link
Contributor

@khaneliman khaneliman left a comment

Choose a reason for hiding this comment

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

Didn't test, but changes look good to me.

Comment on lines +29 to +30
after_plugins = list_plugins(".")
before_plugins = list_plugins(args.flakeref)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could make it more robust and allow passing in 2 flakerefs if we wanted to compare between different locations, even. Then default to . when its not provided? Just a thought for future possibility

Copy link
Member Author

Choose a reason for hiding this comment

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

We had this in the previous attempts. I left it out of this one to keep things as simple as possible.

Follow-up PRs welcome 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

Ended up actually needing this in #3513 🙈

@MattSturgeon MattSturgeon added this pull request to the merge queue Jun 27, 2025
Merged via the queue into nix-community:main with commit a473ef6 Jun 27, 2025
2 checks passed
@MattSturgeon MattSturgeon deleted the diff-plugins branch June 27, 2025 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants