NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.15k stars 13.42k forks source link

Configure Global Cursor Theme - Breeze, Paper, etc... #22652

Open erlandsona opened 7 years ago

erlandsona commented 7 years ago

Issue description

On Arch Linux an index.theme file can be placed under /usr/share/icons/default/ which declares a simple Inherits line for configuring what the default cursor theme is. See https://wiki.archlinux.org/index.php/Cursor_themes

I'm trying to learn how to safely make a similar modification / configuration / derivation with Nix, so that I can experiment with cursor themes that behave consistently across the login manager and other applications.

Steps to reproduce

So far I've used lxappearance to quickly toggle between themes I've installed with environment.systemPackages and then created symlinks from /run/current-system/sw/share/icons/Breeze (for example) to my ~/.icons directory.

This is a local solution that only works post login and feels very brittle.

Technical details

langston-barrett commented 7 years ago

You might already know this, but for an individual user you can place the index.theme file at ~/.icons/default/index.theme.

erlandsona commented 7 years ago

Yeah that's what I have now but it doesn't work for lightdm :confused: Also it just doesn't feel right making symlinks from the "Global" (environment.systemPackages) to that ~/.icons directory.

erlandsona commented 7 years ago

I found this on the irc logs, but it's incomplete. https://botbot.me/freenode/nixos/2016-12-23/?msg=78370282&page=4 it doesn't show the rest of whatever derivation I suppose inf-rec ended up building? In anycase now I'm stuck trying to learn how to make a derivation just for the purpose of adding a simple file to a read only directory? :man_shrugging: life.

grahamc commented 7 years ago

Looking here: https://nixos.org/nixos/options.html#lightdm

I think you can configure lightdm to use the Breeze theme by:

{
  services.xserver.displayManager.lightdm.greeters.gtk.iconTheme = {
    package = pkgs.gnome-breeze;
    name = "Breeze-gtk";
  };
}

or maybe using services.xserver.displayManager.lightdm.greeters.gtk.theme.name / services.xserver.displayManager.lightdm.greeters.gtk.theme.package

erlandsona commented 7 years ago

@grahamc Hey so I tried that but it just makes all the Icons like the face and the icons for buttons and stuff disappear or use their defaults or whatever.

Neither option seems to affect the Mouse Cursor theme. Any other thoughts would be welcome?

I've also tried looking at KDE code but it gets a bit confusing and I don't know what's relevant or not?

pbogdan commented 7 years ago

I'm not sure about setting it globally but FWIW the way I deal with avoiding symlinks in ~/.icons is by installing the themes into my user's profile and then adding ~/.nix-profile/share/icons to XCURSOR_PATH environment variable like so:

export XCURSOR_PATH=~/.icons:~/.nix-profile/share/icons/:$XCURSOR_PATH

and sticking that into my .xsessionrc.

For system-wide installed packages I believe lightdm could be modified to set XCURSOR_PATH to include those like for example in GDM. That would make those packages / cursors available in users' sessions spawned by lightdm without needing to fiddle with XCURSOR_PATH directly. There is also a pending pr https://github.com/NixOS/nixpkgs/pull/24005 to do that globally independent of any display manager.

For lightdm specifically I was able to patch its source, package definition and service to allow changing cursor theme in a way similar to how services.xserver.displayManager.lightdm.greeters.gtk.iconTheme can be customised. It allows changing both the theme as well as cursor size. That seems a bit heavy handed and I guess would require more maintenance due to needing to verify lightm patch whenever package version is bumped. Any thoughts on that?

srhb commented 7 years ago

@pbogdan Can you elaborate on this method? I have ~/.nix-profile/share/icons/ on my $XCURSOR_PATH but if I nix-env -iA nixpgs.breeze-gtk I still have the new, ugly, 17.03 mouseover hand pointer.

erlandsona commented 7 years ago

@pbogdan I just saw your comment and I was hoping someone had tried patching the lightdm derivation... the lightdm.greeters.gtk.iconTheme works well for icons and whatnot so I was hoping it could be extended to include the configurations for mouse theme. Didn't seem like it would be that difficult but you're correct about the versioning and I'm still not savvy enough with Nix as a language to know where to look to get on the right path. And what's sad, is the docs / packages seem to have the answer to just about every other question I've had about NixOS.

But seemingly mouse configuration and fhs user environments / nix-shell are still ambiguous to me.

pbogdan commented 7 years ago

@srhb I tried installing breeze-gtk, breeze-icons and breeze-gnome and it doesn't look like any of those contain any custom cursors :-(. I could be wrong but it looks like only breeze-qt5 has them but it pulls in a ton of qt / kde dependencies and I'm assuming you are not running a DE like KDE or GNOME. Also - how are you setting the active theme?

@erlandsona you can see my lightdm changes here https://github.com/pbogdan/nixpkgs/commit/dfe9a1522928ea02df36712b953b171a8bbb055f They are applied on top of 17.03 channel so not sure if they would work with unstable or master. With those in place cursor theme in lightdm can be set in same way as theme / icon theme:

services.xserver = {
   ...
   displayManager = {
     lightdm = {
       enable = true;
         greeters = {
           gtk = {
             enable = true;
             cursorTheme = {
               package = pkgs.gnome3.defaultIconTheme;
               name = "Adwaita";
               size = 32;
           };
         };
       };
    };
    ...
  };
};

It would need some refining but I guess the changes could be submitted to nixpkgs though still not sure if that's a good idea. But in any case it seems to work for me. And it seems like a bit of a pain, I'm guessing particularly when not using a full DE like GNOME / KDE. Needed some additional fiddling as well for urxvt :-(.

erlandsona commented 7 years ago

At the risk of sounding pedantic @pbogdan how do I use your patch?

pbogdan commented 7 years ago

@erlandsona at the moment the only way I'm aware of would be creating your own nixpkgs fork then cherry picking my commit into your fork. Somehow I can't seem to be able to find documentation on that in the official manuals at the moment - are you familiar with working with your own fork?

erlandsona commented 7 years ago

@pbogdan Forking projects in git yes... under the context of nix & channels and what not, no 😕

pbogdan commented 7 years ago

@erlandsona sorry for delay, I added some instructions based on how I work with my fork here

samueldr commented 6 years ago

Working off of pbogdan's work, I have devised a way to change the cursor globally when using lightdm-gtk-greeter; this was specifically asked on IRC by @ylwghst earlier this evening. Sharing here since I believe it can might help others too while waiting for a more comprehensive method. It might be possible to adapt this to another DM.

In the example, it uses the Paper theme. It also resizes the cursor to a HUGE one.

{ config, lib, pkgs, ... }:
let
  # Not sure if this will work when changed, but this is a good default.
  theme = config.services.xserver.displayManager.lightdm.greeters.gtk.iconTheme.package;
  icons = config.services.xserver.displayManager.lightdm.greeters.gtk.theme.package;

  # This is adapted from `<nixpkgs>/nixos/modules/services/x11/display-managers/lightdm-greeters/gtk.nix`
  wrappedGtkGreeter = pkgs.runCommand "lightdm-gtk-greeter"
    { buildInputs = [ pkgs.makeWrapper ]; }
    ''
      # This wrapper ensures that we actually get themes
      makeWrapper ${pkgs.lightdm_gtk_greeter}/sbin/lightdm-gtk-greeter \
        $out/greeter \
        --prefix PATH : "${pkgs.glibc.bin}/bin" \
        --set GDK_PIXBUF_MODULE_FILE "${pkgs.gdk_pixbuf.out}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache" \
        --set GTK_PATH "${theme}:${pkgs.gtk3.out}" \
        --set GTK_EXE_PREFIX "${theme}" \
        --set GTK_DATA_PREFIX "${theme}" \
        --set XDG_DATA_DIRS "${theme}/share:${icons}/share" \
        --set XDG_CONFIG_HOME "${theme}/share" \
        --set XCURSOR_PATH "/run/current-system/sw/share/icons" \
        --set XCURSOR_SIZE "64"
      cat - > $out/lightdm-gtk-greeter.desktop << EOF
      [Desktop Entry]
      Name=LightDM Greeter
      Comment=This runs the LightDM Greeter
      Exec=$out/greeter
      Type=Application
      EOF
    '';
in
{
  environment.pathsToLink = [ "/share" ];
  environment.systemPackages = with pkgs; [
    paper-icon-theme

    # Adds a package defining a default icon/cursor theme.
    # Based off of: https://github.com/NixOS/nixpkgs/pull/25974#issuecomment-305997110
    (pkgs.callPackage ({ stdenv }: stdenv.mkDerivation {
      name = "global-cursor-theme";
      unpackPhase = "true";
      outputs = [ "out" ];
      installPhase = ''
        mkdir -p $out/share/icons/default
        cat << EOF > $out/share/icons/default/index.theme
        [Icon Theme]
        Name=Default
        Comment=Default Cursor Theme
        Inherits=Paper
        EOF
      '';
    }) {})
  ];

  services.xserver.displayManager.lightdm.enable = true;
  services.xserver.displayManager.lightdm.greeter.package = wrappedGtkGreeter;
}
stale[bot] commented 4 years ago

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.
sbosnick commented 3 years ago

This issue is still important to me. The lack of a "default" cursor theme may cause cursor related problems for many graphical programs implemented in Rust when using a Wayland compositor. The alacritty/alacritty#4780 may be one such example. I am working on narrowing this down further.

samueldr commented 3 years ago

I don't know if / when I'll ever contribute a proper solution, but using xsettingsd and its default behaviour of loading from /etc/xdg it is possible to make a correct enough global configuration for many "X resource" type options, including cursor theme and size. (Assuming xsettingsd is ran through e.g. a systemd-user service in the user session.)

Maybe these hints will help someone write up a module for these things.

yuuyins commented 3 years ago

While useful for some, I don't think depending on a display manager to set the cursor is ideal (I don't use any display manager; on Arch I just set it on ~/.Xresources and ~/.config/gtk-3.0/settings.ini). I'll look into xsettingsd

sbosnick commented 2 years ago

The concern that I have with xsettingsd is that it is X11 specific and will not work for Wayland (which is what I use). The solution that I propose is the one described in the ArchWiki Cursor themes pages under XDG specification. In broad stokes this consists of creating an index.theme file with specific content in one a few specific locations.

The index.theme file should contain an Inherits key whose value is the directory name of the cursor theme that should be the default. The file should be created in a directory named default that is in found in the search order for cursor themes (the ArchWiki page gives two specific directories that are generally found in that search order).

Calling this approach an "XDG specification" is not exactly accurate. I was unable to find an XDG specification that specifically references this approach, though the approach does draw on elements of the Icon Theme Specification (specifically the format of the index.theme file and, to some extent, the search order).

There is, though, some cross-distribution support for this approach. In addition to the description on the ArchWiki, this appears to be supported by default in Debian distributions (through the update-alternatives system). I don't have a good way to check if any of the Red Hat derived distributions support this approach.

I have prepared a module for my local use which implements this strategy (and which does solve the problems I was having). This module relies on the config/xdg/icons.nix module setting XCURSOR_PATH.

# Module to set a default cursor theme

{ config, pkgs, lib, ... }:

with lib;
let
  cfg = config.environment.defaultCursor;

  indexThemeText = theme: generators.toINI {} {"icon theme" = { Inherits = "${theme}"; }; };

  mkDefaultCursorFile = theme: pkgs.writeTextDir
    "share/icons/default/index.theme"
    "${indexThemeText theme}";

  defaultCursorPkg = mkDefaultCursorFile cfg.theme;
in
{
  options = {
    environment.defaultCursor = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Whether to set a default cursor theme for graphical environments.
        '';
      };

      theme = mkOption {
        type = types.str;
        default = "";
        example = "Adwaita";
        description = "The name of the defualt cursor theme.";
      };
    };
  };

  config = mkIf cfg.enable {
    environment.systemPackages = [
      defaultCursorPkg
    ];
  };
}

It may be possible to use some variation of this module to add this capability to NixOS generally.

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

jtrees commented 2 years ago

Still relevant.

nixos-discourse commented 2 years ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/alacritty-weird-focus-behaviour/20383/1

viccuad commented 1 month ago

Still relevant. For the alacritty example, a workaround is XCURSOR_THEME=Adwaita alacritty.

dmchmk commented 1 month ago

Yeah, still reproduces