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

GTK: Cleanup 'attrsHasPrefix' function #19

Merged
merged 1 commit into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions modules/collection/misc/gtk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) listOf package lines;
inherit (lib.modules) mkIf;
inherit (lib.lists) optionals;
inherit (lib.attrsets) optionalAttrs;
inherit (lib.rum.generators.gtk) toGtk2Text toGtkINI;
inherit (lib.rum.types) gtkType;
inherit (lib.strings) hasPrefix;
inherit (lib.lists) optionals any;
inherit (lib.attrsets) optionalAttrs;
inherit (builtins) attrNames hasAttr;
inherit (lib.rum.attrsets) attrNamesHasPrefix;
inherit (builtins) hasAttr;

cfg = config.rum.gtk;
in {
Expand Down Expand Up @@ -77,12 +77,9 @@ in {
config = mkIf cfg.enable {
# We could also just automatically fix it, but for now, simply
# check if the user accidentally included a 'gtk-' prefix.
warnings = let
attrsHasPrefix = prefix: attrs: (any (hasPrefix prefix) (attrNames attrs));
in
optionals (attrsHasPrefix "gtk-" cfg.settings) [
"Each option in 'rum.gtk.settings' is automatically prefixed with 'gtk-' if it is not present already. You have added this to an option unnecessarily."
];
warnings = optionals (attrNamesHasPrefix "gtk-" cfg.settings) [
"Each option in 'rum.gtk.settings' is automatically prefixed with 'gtk-' if it is not present already. You have added this to an option unnecessarily."
];

inherit (cfg) packages;

Expand Down
10 changes: 10 additions & 0 deletions modules/lib/attrsets/attrNamesHasPrefix.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{lib}: let
inherit (lib.strings) hasPrefix;
inherit (lib.lists) any;
inherit (builtins) attrNames;
in
# Super simple function to check if any attributes' names
# in the input attrset contain the input prefix
prefix: attrs: (
any (hasPrefix prefix) (attrNames attrs)
)
1 change: 1 addition & 0 deletions modules/lib/attrsets/default.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{lib}: {
attrNamesHasPrefix = import ./attrNamesHasPrefix.nix {inherit lib;};
filterKeysPrefixes = import ./filterKeysPrefixes.nix {inherit lib;};
}