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

countAttrs doesn't work as expected #34

Closed
archer-65 opened this issue Oct 15, 2022 · 1 comment
Closed

countAttrs doesn't work as expected #34

archer-65 opened this issue Oct 15, 2022 · 1 comment
Labels

Comments

@archer-65
Copy link

What did you expect to happen?

Here we are. My nix-fu isn't great, but maybe I found an issue with this function. I'm trying to use countAttrs as done in this assertion.

I have a similar setup for my WMs, like that:

  cfgXorg = config.user-modules.desktop.xorg;
  cfgWayland = config.user-modules.desktop.wayland;

  ...
  
  {
    assertion = (countAttrs (n: v: n == "enable" && v) cfgXorg) < 2;
    message = "[Xorg] Can't have more than one WM/DE enable at a time.";
  }
  {
    assertion = (countAttrs (n: v: n == "enable" && v) cfgWayland) < 2;
    message = "[Wayland] Can't have more than one WM/DE enable at a time.";
  }

Something like this should print a backtrace!

 user-modules.desktop.wayland = {
      enable = true;
      sway.enable = true;
      hyprland.enable = true;
 };

What actually happened?

The evaluation continues, instead of printing the backtrace.

Describe your attempts to resolve the issue

No response

Steps to reproduce

Enable at least two WMs (I'm using your functions for the same purpose)

Package commit

089f1a9

System Information

No response

@archer-65 archer-65 added the bug label Oct 15, 2022
@hlissner
Copy link
Owner

Sorry for only noticing this issue now, and you've probably already figured this out by now, but the problem is with the predicate function. Yours is only searching for a top-level enabled property, and not nested ones. They'd need to be rewritten to:

  {
    assertion = (countAttrs (_: v: v.enable or false) cfgXorg) < 2;
    message = "[Xorg] Can't have more than one WM/DE enable at a time.";
  }
  {
    assertion = (countAttrs (_: v: v.enable or false) cfgWayland) < 2;
    message = "[Wayland] Can't have more than one WM/DE enable at a time.";
  }

Hope that helps someone!

@hlissner hlissner closed this as not planned Won't fix, can't repro, duplicate, stale Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants