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

nix/module: toHyprconf -> toHyprlang #9221

Merged
merged 6 commits into from
Mar 2, 2025
Merged

nix/module: toHyprconf -> toHyprlang #9221

merged 6 commits into from
Mar 2, 2025

Conversation

fufexan
Copy link
Member

@fufexan fufexan commented Jan 29, 2025

Describe your PR, what does it fix/add?

Reworks the current Nix to hyprland.conf generator implementation by using a more generic Nix 2 Hyprlang generator.
This allows any application using hyprlang to use this for easy config generation.

This is the second step towards getting this module into Nixpkgs.

Considerations:

  • Rename section -> category, to be in line with the documentation.
  • Use category[special]:field = value for special categories. This reduces the complexity in finding the special key inside the attrset and then properly ordering it as the first in the generated category. But this poses a question: how should we let the user define these categories?
    • Write them verbatim ("device[some-device:0baf3-952c]" = { sensitivity = 0.3; })
    • Parse a list of devices in the module, rewrite the attrset and pass it to toHyprlang:
      device = [
        {
          name = "some-device:0baf3-952c";
          sensitivity = 0.3;
        }
        {
          # ...
        }
      ];
      
      # this will be transformed to the syntax in the point above
  • Ensure nested categories are handled by recursing over them.
  • Use category:field = value for everything instead of nested categories (category {...}). This further reduces complexity by having only one code path for all categories.
  • Remove indentLevel, no longer needed without expanded categories.
  • Change importantPrefixes -> topCommandsPrefixes and also add bottomCommandsPrefixes for greater flexibility. Group these as the first argument (called options from now on).
  • Separate attrs into a standalone argument, after the options arg. This is the actual config that will be translated to hyprlang.

CC: @bloxx12 @donovanglover @JohnRTitor @khaneliman @NotAShelf

Is there anything you want to mention? (unchecked code, possible bugs, found problems, breaking compatibility, etc.)

Needs testing. Different ideas and constructive criticism welcome.

Is it ready for merging, or does it need work?

Needs testing and discussion.

@github-actions github-actions bot added the Nix NixOS issue label Jan 29, 2025
@fufexan
Copy link
Member Author

fufexan commented Feb 14, 2025

Even simpler now, in case y'all found this too daunting to review :P

After implementing flattenAttrs I searched Nixpkgs PRs and found this. 🤷‍♂️

Updated generator that will end up living in Nixpkgs' `lib/generators`.
The downstream module already applies hyprland's
finalPackage to the portalPackage.
Flattening attributes means we no longer need to process categories
separately. For all intents and purposes, they do not exist.

Simplify the codebase once again, while introducing an easy to grasp
recursive function.

Add a bit of documentation for toHyprlang, though I doubt it's clear
enough even now. Still needs proper NixDoc.
@fufexan fufexan marked this pull request as ready for review February 24, 2025 21:12
Copy link
Member

@NotAShelf NotAShelf left a comment

Choose a reason for hiding this comment

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

I have nothing left to add, LGTM.

One thing that might possibly come to bite you in the back is the fact that nixpkgs requires test for new library functions, but since this'll be put in generators that might be necessary.

@fufexan
Copy link
Member Author

fufexan commented Feb 25, 2025

One thing that might possibly come to bite you in the back is the fact that nixpkgs requires test for new library functions, but since this'll be put in generators that might be necessary.

Tests for these functions should be relatively easy to implement.

@fufexan
Copy link
Member Author

fufexan commented Mar 2, 2025

Since there haven't been any objections, I'll merge this.

@fufexan fufexan merged commit 905ca39 into main Mar 2, 2025
20 checks passed
@fufexan fufexan deleted the nix-module branch March 2, 2025 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Nix NixOS issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants