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

kde: enable custom decorations #772

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

rkuklik
Copy link
Contributor

@rkuklik rkuklik commented Jan 11, 2025

Hi.

Fixing Plasma activation in #708 worked bit too well. Every time the theme is applied, it resets all custom theming options. I noticed this with decorations, so I added a new option to override org.kde.breeze with custom string.

I also took the liberty of refactoring the module a bit. To improve module maintenance, I mainly reduced the scope of with expressions and improve color handling.

@rkuklik
Copy link
Contributor Author

rkuklik commented Jan 11, 2025

I am bit unsure why nixfmt fails, perhaps there is a version mismatch (I used one from newest nixos-unstable).

@trueNAHO
Copy link
Collaborator

trueNAHO commented Jan 12, 2025

I am bit unsure why nixfmt fails, perhaps there is a version mismatch (I used one from newest nixos-unstable).

We are using the new nixfmt-rfc-style formatter, which is not the same as the older nixfmt formatter.

If the behavior of nixfmt-rfc-style recently changed, we might first have to update the nixpkgs input and re-apply nixfmt-rfc-style in a seperate PR. I will look into this once I have more time (probably in two days).

@rkuklik
Copy link
Contributor Author

rkuklik commented Jan 12, 2025

That is the one I used, nixfmt nixpkgs-unstable-2024-12-04 to be precise. I can reformat the code, but I would say that it is not necessary, if the style updates in the near future.

@trueNAHO
Copy link
Collaborator

For reference, the following patch should make the CI pass:

diff --git a/modules/kde/hm.nix b/modules/kde/hm.nix
index 92878a3..44f643c 100644
--- a/modules/kde/hm.nix
+++ b/modules/kde/hm.nix
@@ -33,7 +33,9 @@ let
     types
     ;

-  formatValue = value: if isBool value then if value then "true" else "false" else toString value;
+  formatValue =
+    value:
+    if isBool value then if value then "true" else "false" else toString value;

   formatSection =
     path: data:
@@ -45,7 +47,9 @@ let
       directChildren = partitioned.right;
       indirectChildren = partitioned.wrong;
     in
-    optional (directChildren != [ ]) header ++ directChildren ++ flatten indirectChildren;
+    optional (directChildren != [ ]) header
+    ++ directChildren
+    ++ flatten indirectChildren;

   formatLines =
     path: data:
@@ -72,7 +76,9 @@ let
   # PascalCase is the standard naming for color scheme files. Schemes named
   # in kebab-case will load when selected manually, but don't work with a
   # look and feel package.
-  colorschemeSlug = concatStrings (filter isString (builtins.split "[^a-zA-Z]" colors.scheme));
+  colorschemeSlug = concatStrings (
+    filter isString (builtins.split "[^a-zA-Z]" colors.scheme)
+  );

   colorEffect = {
     ColorEffect = 0;
@@ -326,29 +332,31 @@ in
     };
   };

-  config = mkIf (config.stylix.enable && cfg.enable && pkgs.stdenv.hostPlatform.isLinux) {
-    home = {
-      packages = [ themePackage ];
-
-      # This activation entry will run the theme activator when the homeConfiguration is activated
-      activation.stylixLookAndFeel = hm.dag.entryAfter [ "writeBoundary" ] ''
-        ${activator} || verboseEcho \
-          "Stylix KDE theme setting failed. Note that it only works in an already running Plasma session."
-      '';
-    };
-
-    xdg = {
-      systemDirs.config = [ "${configPackage}" ];
-
-      # This desktop entry will run the theme activator when a new Plasma session is started
-      # Note: This doesn't run again if a new homeConfiguration is activated from a running Plasma session
-      configFile."autostart/stylix-activator.desktop".text = ''
-        [Desktop Entry]
-        Type=Application
-        Exec=${activator}
-        Name=Stylix Activator
-        X-KDE-AutostartScript=true
-      '';
-    };
-  };
+  config =
+    mkIf (config.stylix.enable && cfg.enable && pkgs.stdenv.hostPlatform.isLinux)
+      {
+        home = {
+          packages = [ themePackage ];
+
+          # This activation entry will run the theme activator when the homeConfiguration is activated
+          activation.stylixLookAndFeel = hm.dag.entryAfter [ "writeBoundary" ] ''
+            ${activator} || verboseEcho \
+              "Stylix KDE theme setting failed. Note that it only works in an already running Plasma session."
+          '';
+        };
+
+        xdg = {
+          systemDirs.config = [ "${configPackage}" ];
+
+          # This desktop entry will run the theme activator when a new Plasma session is started
+          # Note: This doesn't run again if a new homeConfiguration is activated from a running Plasma session
+          configFile."autostart/stylix-activator.desktop".text = ''
+            [Desktop Entry]
+            Type=Application
+            Exec=${activator}
+            Name=Stylix Activator
+            X-KDE-AutostartScript=true
+          '';
+        };
+      };
 }

I will resolve this issue when I have more time.

@rkuklik
Copy link
Contributor Author

rkuklik commented Jan 12, 2025

Thank you.

I will resolve this issue when I have more time.

Do you mean the formatting CI, this PR or both? I am unsure whether I should reformat the code, leave it as is for later or help with anything else.

Copy link
Collaborator

@trueNAHO trueNAHO left a comment

Choose a reason for hiding this comment

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

The problem is that your code is not formated with --width=80:

stylix/flake.nix

Lines 122 to 125 in 2985ee9

nixfmt-rfc-style = {
enable = true;
settings.width = 80;
};

For reference, the current CI command is:

/nix/store/lch913ar0a3w3f6d63crf5vfvpckddk1-nixfmt-unstable-2024-12-04/bin/nixfmt --width=80

If you do not mind the pre-commit hooks (there is currently no developer shell variant without them, although this could be trivially added), feel free to use the developer shells:

# Development environment
To enter the developer shell, run:
```console
nix develop
```
To automatically enter the developer shell upon entering the project directory
with [`direnv`](https://direnv.net), run:
```console
direnv allow
```

I can reformat the code, but I would say that it is not necessary, if the style updates in the near future. [...] I am unsure whether I should reformat the code, leave it as is for later or help with anything else.

Properly format the code, since the CI already uses the latest nixfmt-unstable-2024-12-04.

@rkuklik
Copy link
Contributor Author

rkuklik commented Jan 18, 2025

Thank you very much for your help and sorry for the trouble.

@@ -161,6 +204,7 @@ let
lookAndFeelMetadata = builtins.toJSON lookAndFeelMetadata;
lookAndFeelDefaults = formatConfig lookAndFeelDefaults;
}
# bash
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# bash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The treesitter grammar (in neovim, for instance) uses this kind of comment to detect which language is in the string, enabling syntax highlighting and other editor integration, same as fenced code blocks in markdown. Should I remove it nonetheless?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The treesitter grammar (in neovim, for instance) uses this kind of comment to detect which language is in the string, enabling syntax highlighting and other editor integration, same as fenced code blocks in markdown. Should I remove it nonetheless?

Yes.

"KDE theme setting failed. See `${activateDocs}`"
activation.stylixLookAndFeel = hm.dag.entryAfter [ "writeBoundary" ] ''
${activator} || verboseEcho \
"Stylix KDE theme setting failed. Note that it only works in an already running Plasma session."
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might be more concise:

Suggested change
"Stylix KDE theme setting failed. Note that it only works in an already running Plasma session."
"Stylix KDE theme setting failed. This only works in a running Plasma session."

modules/kde/hm.nix Show resolved Hide resolved
in
{
options.stylix.targets.kde.enable = config.lib.stylix.mkEnableTarget "KDE" true;
options.stylix.targets.kde = {
enable = mkEnableTarget "KDE" true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
enable = mkEnableTarget "KDE" true;
enable = mkEnableTarget "KDE" true;

Comment on lines +10 to +34
inherit (config.lib.stylix)
colors
mkEnableTarget
;
inherit (lib)
concatStrings
concatStringsSep
filter
flatten
getExe
isAttrs
isBool
isString
hm
last
listToAttrs
mapAttrsToList
mkIf
mkOption
optional
partition
range
toHexString
types
;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Subject: [PATCH 2/5] kde(refactor): remove top-level with and improve imports

Thanks for reducing the scope of the with expressions.

I am aware that Nixpkgs has the convention of brining everything into scope with inhert statements at the top of the file. However, Stylix currently does not really follow this to any extent. It might be better to apply this pattern treewide in a separate PR. @danth, what do you think?

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