nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.27k stars 1.68k forks source link

bug: Impossible to disable theming for GTK4 #5133

Open Quadrubo opened 3 months ago

Quadrubo commented 3 months ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

The commit https://github.com/nix-community/home-manager/commit/e9b9ecef4295a835ab073814f100498716b05a96#diff-7d7e3718822ace30b2dc9dd86ef97329bfc89c9262ccad07f5777d0ff3cc8924 introduced a bug for me, as I was using adw-gtk3 to theme legacy applications.

I don't want to theme gtk4 applications with that theme. The manpage for nix also states that gtk.enable enables theming for gtk2/3. gtk.theme says the gtk2/3 theme to use.

I don't think setting the theme using this option should automatically apply to all gtk versions. Please note that I'm new to nixos so if one could inform me of any way to overwrite the gtk4Css variable this would work for me.

However I think a better approach would be to let the user choose themes for each different gtk version. Something like this:

gtk = {
    enable = true;

    gtk3 = {
      enable = true;
      theme = {
        package = pkgs.adw-gtk3;
        name = "adw-gtk3";
      };
    };

    gtk4 = {
      enable = false;
    };
  };

Maintainer CC

@rycee

System information

- system: `"x86_64-linux"`
 - host os: `Linux 6.6.21, NixOS, 24.05 (Uakari), 24.05.20240309.3030f18`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/nix/store/nra828scc8qs92b9pxra5csqzffb6hpl-source`
howyay commented 3 months ago

A workaround is to use home.activation to delete ~/.config/gtk-4.0/gtk.css for now:

home.activation.removeGTK4Theming = lib.hm.dag.entryAfter ["writeBoundary"] ''rm ${config.xdg.configHome}/gtk-4.0/gtk.css'';

Quadrubo commented 3 months ago

A workaround is to use home.activation to delete ~/.config/gtk-4.0/gtk.css for now:

home.activation.removeGTK4Theming = lib.hm.dag.entryAfter ["writeBoundary"] ''rm ${config.xdg.configHome}/gtk-4.0/gtk.css'';

Thank you for the workaround. This is working for now.

MOIS3Y commented 3 months ago

@howyay hi!

This also breaks the work of gtk4.extraCss

2024-03-26-18-28-20

2024-03-26-18-30-49

Is there a way to override gtk4Css so that it doesn't import from the theme? So far I only see the opportunity to copy the module into the configuration and change its behavior. This is clearly not right

This workaround won't work (

  home.activation.removeGTK4Theming = lib.hm.dag.entryAfter ["writeBoundary"] ''rm ${config.xdg.configHome}/gtk-4.0/gtk.css'';
  home.file."${config.xdg.configHome}/gtk-4.0/gtk.css".text = ''${extraCss}'';
howyay commented 3 months ago

@howyay hi!

This also breaks the work of gtk4.extraCss

2024-03-26-18-28-20

2024-03-26-18-30-49

Is there a way to override gtk4Css so that it doesn't import from the theme? So far I only see the opportunity to copy the module into the configuration and change its behavior. This is clearly not right

This workaround won't work (

  home.activation.removeGTK4Theming = lib.hm.dag.entryAfter ["writeBoundary"] ''rm ${config.xdg.configHome}/gtk-4.0/gtk.css'';
  home.file."${config.xdg.configHome}/gtk-4.0/gtk.css".text = ''${extraCss}'';

I trust that you probably already figured this out - but its worth noting that there is no need to delete it in the first place if you just wish to overwrite it. Using output redirection > should discard any existing content and overwrite with your desired content.

KaiserCalm commented 1 week ago

I was about to write a new bug report. I am pretty sure that line 291 of this commit is completely broken and forces home manager to always create the gtk4.css file, because the string on line 238 is never going to be empty.

I propose to change 291 from:

xdg.configFile."gtk-4.0/gtk.css" = mkIf (gtk4Css != "") { text = gtk4Css; };

To this:

xdg.configFile."gtk-4.0/gtk.css" = mkIf (cfg4.extraCss != "") { text = gtk4Css; };

It would work the same way the gtk3.css option currently works.