Skip to content

Refactor: Structured Configuration Support for Home Manager Module#667

Open
ananyatimalsina wants to merge 10 commits intomangowm:mainfrom
ananyatimalsina:main
Open

Refactor: Structured Configuration Support for Home Manager Module#667
ananyatimalsina wants to merge 10 commits intomangowm:mainfrom
ananyatimalsina:main

Conversation

@ananyatimalsina
Copy link
Copy Markdown

Summary

This PR refactors the home-manager module to use structured Nix attribute sets instead of raw text configuration, following the architectural pattern from Hyprland's NixOS module.

All credit for this design goes to the Hyprland project. This is a 1:1 adaptation of their implementation, modified for mangowc's specific syntax requirements.

Motivation

The previous implementation required users to write raw config strings:

settings = ''
  blur=1
  border_radius=6
  bind=SUPER,Q,spawn,wezterm
'';

This approach had several limitations:

  • No type checking or validation at build time
  • Poor editor support (no completion or syntax highlighting)
  • String escaping issues
  • Difficult to compose or merge configurations
  • Error-prone for complex configs

New Configuration Format

settings = {
  # Simple key-value pairs
  blur = 1;
  border_radius = 6;
  
  # Nested attributes (flattened with underscores)
  blur_params = {
    radius = 5;
    num_passes = 2;
  };
  # Becomes: blur_params_radius=5, blur_params_num_passes=2
  
  # Lists for duplicate keys
  bind = [
    "SUPER,r,reload_config"
     "Alt,space,spawn,rofi -show drun"
     "Alt,Return,spawn,foot"
  ];
  tagrule = [
     "id:1,layout_name:tile"
     "id:2,layout_name:scroller"
  ];
};

Backward Compatibility

⚠️ Breaking Change: This changes the settings option from raw text to structured attributes.

Migration path: Users need to convert their configs from:

settings = ''
  blur=1
  bind=SUPER,Q,spawn,wezterm
'';

To:

settings = {
  blur = 1;
  bind = [ "SUPER,Q,spawn,wezterm" ];
};

For users who need raw text during migration, the new extraConfig option is available:

extraConfig = ''
  # Raw config lines
  special_option = 1
'';

Testing

  • Syntax validated with nix-instantiate --parse
  • Verified toMango function generates correct output format
  • Tested list expansion for duplicate keys
  • Tested nested attribute flattening with underscores
  • Confirmed automatic exec-once for autostart.sh
  • Tested for my own personal config and system

Credits

This implementation is based entirely on Hyprland's NixOS module architecture:

All architectural credit goes to the Hyprland development team. This PR simply adapts their excellent design to mangowc's specific syntax and requirements.

Related

Convert settings from raw text to structured Nix attrs, following
Hyprland's module pattern. Implementation based 1:1 on Hyprland's
design - all credit to the Hyprland project.

- Add nix/lib.nix with toMango conversion function
- Support nested attrs, lists for duplicate keys
- Add extraConfig, topPrefixes, bottomPrefixes options
- Auto-add exec-once for autostart.sh

Adapted for mangowc syntax (underscore separators vs colons).
@Tomate0613
Copy link
Copy Markdown

How does this work for keymodes?

@ananyatimalsina
Copy link
Copy Markdown
Author

Oversight on my part, thanks for pointing that out! It should work now with the new keymode syntax being:

settings = {
  bind = [
    "ALT,R,setkeymode,resize"  # Enter resize mode
  ];
  
  # Keymodes (submaps) for modal keybindings
  keymode = {
    resize = {
      bind = [
        "NONE,Left,resizewin,-10,0"
        "NONE,Escape,setkeymode,default"
      ];
    };
  };
};

@invra
Copy link
Copy Markdown

invra commented Feb 17, 2026

Could we possibly implement a check for the old config and show an evaluation warning, so there can possibly be a buffering period? Some people might just want to update mango, but refactor their expression at a later date. I think builtins.isString can be all that's really needed.

@ananyatimalsina
Copy link
Copy Markdown
Author

Done

@invra
Copy link
Copy Markdown

invra commented Feb 17, 2026

Alright, cool!

@DreamMaoMao DreamMaoMao force-pushed the main branch 4 times, most recently from dc016eb to 6b2d694 Compare February 22, 2026 03:52
@Yappaholic
Copy link
Copy Markdown
Contributor

Looks good to me, but

  1. I think it needs more testing before going upstream and
  2. PR commits can be squashed into one commit for clarity

@Tomate0613
Copy link
Copy Markdown

I think its also worth validating the config, like I do in #655

@invra
Copy link
Copy Markdown

invra commented Feb 25, 2026

I think its also worth validating the config

I think that would be not easy to maintain, because of the config specs do change a bit, whilst mkOption will be the way, we need a spec with a script which generates the nix, using said spec, which wont work nicely, unless we also refactor parts of the config system on mango which make it work together, but that's a burden.

@Tomate0613
Copy link
Copy Markdown

I don't quite understand what you mean by that?
I think just validating the output using mango -c is good enough

@invra
Copy link
Copy Markdown

invra commented Feb 26, 2026

nevemind then, i wasnt aware -c existed, nor could do that

Uses `pkgs.runCommand` in the home-manager module to parse and validate
the generated config file prior to deployment, preventing broken setups.
@ananyatimalsina
Copy link
Copy Markdown
Author

I think its also worth validating the config, like I do in #655

Done, pretty much a copy paste of your approach thx a lot

@SamuelHDieterich
Copy link
Copy Markdown

Sorry if this is just considered noise for the PR, but thanks, @ananyatimalsina, for putting this together!

I've been looking to migrate from Hyprland to MangoWC and I had some mixed feelings when most of the configs were similar, but the home-manager settings was expecting a raw string. I just pulled your flake, and it is working as I would've expected.

Just giving my thumbs up that this is great deal for someone like me that was expecting a more nix-friendly home-manager configuration.

@Yappaholic
Copy link
Copy Markdown
Contributor

Sorry if this is just considered noise for the PR, but thanks, @ananyatimalsina, for putting this together!

I've been looking to migrate from Hyprland to MangoWC and I had some mixed feelings when most of the configs were similar, but the home-manager settings was expecting a raw string. I just pulled your flake, and it is working as I would've expected.

Just giving my thumbs up that this is great deal for someone like me that was expecting a more nix-friendly home-manager configuration.

Definitely not a noise, user testing is appreciated

Copy link
Copy Markdown

@SamuelHDieterich SamuelHDieterich left a comment

Choose a reason for hiding this comment

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

Although the restructure settings has been working great, my systemd services were not been correctly initialized. After digging a bit, I found that if I manually added the dbus command to the autostart_sh config, things would work as expected.

wayland.windowManager.mango = {
  enable = true;
  systemd = {
    enable = true;
    variables = [ "--all" ];
  };
  autostart_sh = "dbus-update-activation-environment --systemd --all"; # Extra line
};

I think the problem is easy to solve. You have prepended this command to the autostart_sh variable defined in the let in block, but still using the value from cfg.autostart_sh to create the file and add the exec-once command to mango.conf.

Can you review if these changes make sense?

@DreamMaoMao DreamMaoMao force-pushed the main branch 3 times, most recently from 673ec40 to db30977 Compare March 9, 2026 05:28
@DreamMaoMao DreamMaoMao force-pushed the main branch 2 times, most recently from 17ff2ad to 064bcad Compare March 23, 2026 02:56
Copy link
Copy Markdown

@SamuelHDieterich SamuelHDieterich left a comment

Choose a reason for hiding this comment

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

I've been using this fork for weeks now, I don't see a reason to not move this upstream.

After this is merged, I can check if I will still have that problem with dbus or not. If so, I can raise an issue.

Good job, @ananyatimalsina! 🚀

@DreamMaoMao DreamMaoMao force-pushed the main branch 2 times, most recently from 0d3ed31 to 5267649 Compare March 30, 2026 10:35
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.

5 participants