Skip to content

Conversation

c0d3m0nky
Copy link

@c0d3m0nky c0d3m0nky commented Oct 3, 2025

For me the way rc2nix.py outputs it's Nix conversion is unreadable. Not a criticism, just an accommodation I need, so I made it an option

When executing rc2nix.py with no arguments the output remains unchanged

{
  programs.plasma = {
    enable = true;
    shortcuts = {
      ActivityManager.switch-to-activity-1595ee1f-09c7-4e54-9969-1f629be88458 = [ ];
      "KDE Keyboard Layout Switcher"."Switch to Last-Used Keyboard Layout" = "Meta+Alt+L";
      "KDE Keyboard Layout Switcher"."Switch to Next Keyboard Layout" = "Meta+Alt+K";
      ksmserver."Lock Session" = [ "Meta+L" "Screensaver,Meta+L" "Screensaver,Lock Session" ];
      ...
    };
    ...
}

But with the -n|--nested-format argument it will nest the output, attr sets and lists with a single child remain in-line

{
  programs.plasma = {
    enable = true;
    shortcuts = {
      ActivityManager.switch-to-activity-1595ee1f-09c7-4e54-9969-1f629be88458 = [ ];
      "KDE Keyboard Layout Switcher" = {
        "Switch to Last-Used Keyboard Layout" = "Meta+Alt+L";
        "Switch to Next Keyboard Layout" = "Meta+Alt+K";
      };
      ksmserver."Lock Session" = [
        "Meta+L"
        "Screensaver,Meta+L"
        "Screensaver,Lock Session"
      ];
      ...
    };
    ...
}

I also introduced a minor change that will only quote keys when necessary using this regular expression

^[a-z_][\w_-]*?$

If the key begins with a letter or underscore, and the rest of the characters are all alphanumeric, underscore, or dash, it will not unnecessarily quote the key. I'm actually not 100% sure those are all the valid characters, but by making it inclusive it is fail-safe

Additional bugfixes:

  • When splitting shortcut values, a regular expression pattern was being used but called in a way it was treating it as a literal string. Using the split function from re now. See this comment for an example

@AlexNabokikh
Copy link
Contributor

A very much needed change!

@c0d3m0nky
Copy link
Author

I'm starting to think 'compact' is the wrong term here. Should I change it to 'pretty'? Other suggestions welcome

@AlexNabokikh
Copy link
Contributor

@c0d3m0nky --format or --fmt also could work

@c0d3m0nky
Copy link
Author

c0d3m0nky commented Oct 3, 2025

@c0d3m0nky --format or --fmt also could work

'format' feels too vague

The other option I'm thinking is --nested

Why is coming up with good names always the hardest part? 🥲

@AlexNabokikh
Copy link
Contributor

The official Nix formatting RFC uses expanded and nestedattribute terms, so maybe stick to them. Adding format for clarity wouldn't hurt, though (e.g., --expanded-format or --nested-format)

@c0d3m0nky
Copy link
Author

Changed it to -n|--nested-format

@c0d3m0nky
Copy link
Author

So I found a bug in rc2nix.py but I'm not sure I should include it in this PR or wait and make a followup PR.

For shortcuts when multiple or none are set it outputs invalid values like

{
        "Window Minimize" = [
          "Meta+Down"
          "Meta+PgDown,Meta+PgDown,Minimize Window"
        ];
        "Window Move" = "none,,Move Window";
}

I have confirmed it happens with the HEAD of this repo too, I did not accidentally introduce this.

Should I include the fix in this PR?

@c0d3m0nky
Copy link
Author

c0d3m0nky commented Oct 3, 2025

Turned out to be an extremely simple fix, so I just included it.

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