fork/home-manager
git clone https://git.julia.blue/fork/home-manager
a0ad9817
master
1{ config , options , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . home . pointerCursor ; 8 9pointerCursorModule = types . submodule { 10options = { 11package = mkOption { 12type = types . package ; 13example = literalExpression "pkgs.vanilla-dmz" ; 14description = "Package providing the cursor theme." ; 15}; 16 17name = mkOption { 18type = types . str ; 19example = "Vanilla-DMZ" ; 20description = "The cursor name within the package." ; 21}; 22 23size = mkOption { 24type = types . int ; 25default = 32 ; 26example = 64 ; 27description = "The cursor size." ; 28}; 29 30x11 = { 31enable = mkEnableOption '' 32x11 config generation for {option}`home.pointerCursor` 33'' ; 34 35defaultCursor = mkOption { 36type = types . str ; 37default = "left_ptr" ; 38example = "X_cursor" ; 39description = "The default cursor file to use within the package." ; 40}; 41}; 42 43gtk = { 44enable = mkEnableOption '' 45gtk config generation for {option}`home.pointerCursor` 46'' ; 47}; 48}; 49}; 50 51cursorPath = " ${ cfg . package } /share/icons/ ${ escapeShellArg cfg . name } /cursors/ ${ 52escapeShellArg cfg . x11 . defaultCursor 53} " ; 54 55defaultIndexThemePackage = pkgs . writeTextFile { 56name = "index.theme" ; 57destination = "/share/icons/default/index.theme" ; 58# Set name in icons theme, for compatibility with AwesomeWM etc. See: 59# https://github.com/nix-community/home-manager/issues/2081 60# https://wiki.archlinux.org/title/Cursor_themes#XDG_specification 61text = '' 62[Icon Theme] 63Name=Default 64Comment=Default Cursor Theme 65Inherits= ${ cfg . name } 66'' ; 67}; 68 69in { 70meta . maintainers = [ maintainers . polykernel maintainers . league ]; 71 72imports = [ 73( mkAliasOptionModule [ "xsession" "pointerCursor" "package" ] [ 74"home" 75"pointerCursor" 76"package" 77]) 78( mkAliasOptionModule [ "xsession" "pointerCursor" "name" ] [ 79"home" 80"pointerCursor" 81"name" 82]) 83( mkAliasOptionModule [ "xsession" "pointerCursor" "size" ] [ 84"home" 85"pointerCursor" 86"size" 87]) 88( mkAliasOptionModule [ "xsession" "pointerCursor" "defaultCursor" ] [ 89"home" 90"pointerCursor" 91"x11" 92"defaultCursor" 93]) 94 95({ ...} :{ 96warnings = optional ( any ( x : 97getAttrFromPath 98([ "xsession" "pointerCursor" ] ++ [ x ] ++ [ "isDefined" ]) 99options ) [ "package" "name" "size" "defaultCursor" ]) '' 100The option `xsession.pointerCursor` has been merged into `home.pointerCursor` and will be removed 101in the future. Please change to set `home.pointerCursor` directly and enable `home.pointerCursor.x11.enable` 102to generate x11 specific cursor configurations. You can refer to the documentation for more details. 103'' ; 104}) 105]; 106 107options = { 108home . pointerCursor = mkOption { 109type = types . nullOr pointerCursorModule ; 110default = null ; 111description = '' 112Cursor configuration. Set to `null` to disable. 113 114Top-level options declared under this submodule are backend independent 115options. Options declared under namespaces such as `x11` 116are backend specific options. By default, only backend independent cursor 117configurations are generated. If you need configurations for specific 118backends, you can toggle them via the enable option. For example, 119[](#opt-home.pointerCursor.x11.enable) 120will enable x11 cursor configurations. 121 122Note that this will merely generate the cursor configurations. 123To apply the configurations, the relevant subsytems must also be configured. 124For example, [](#opt-home.pointerCursor.gtk.enable) will generate 125the gtk cursor configuration, but [](#opt-gtk.enable) needs 126to be set for it to be applied. 127'' ; 128}; 129}; 130 131config = mkIf ( cfg != null ) ( mkMerge [ 132{ 133assertions = [ 134( hm . assertions . assertPlatform "home.pointerCursor" pkgs platforms . linux ) 135]; 136 137home . packages = [ cfg . package defaultIndexThemePackage ]; 138 139# Set directory to look for cursors in, needed for some applications 140# that are unable to find cursors otherwise. See: 141# https://github.com/nix-community/home-manager/issues/2812 142# https://wiki.archlinux.org/title/Cursor_themes#Environment_variable 143home . sessionVariables = { 144XCURSOR_PATH = mkDefault ( "$XCURSOR_PATH\${XCURSOR_PATH:+:}" 145+ " ${ config . home . profileDirectory } /share/icons" ); 146XCURSOR_SIZE = mkDefault cfg . size ; 147XCURSOR_THEME = mkDefault cfg . name ; 148}; 149 150# Add symlink of cursor icon directory to $HOME/.icons, needed for 151# backwards compatibility with some applications. See: 152# https://specifications.freedesktop.org/icon-theme-spec/latest/ar01s03.html 153home . file . ".icons/default/index.theme" . source = 154" ${ defaultIndexThemePackage } /share/icons/default/index.theme" ; 155home . file . ".icons/ ${ cfg . name } " . source = 156" ${ cfg . package } /share/icons/ ${ cfg . name } " ; 157 158# Add cursor icon link to $XDG_DATA_HOME as well for redundancy. 159xdg . dataFile . ".icons/default/index.theme" . source = 160" ${ defaultIndexThemePackage } /share/icons/default/index.theme" ; 161xdg . dataFile . ".icons/ ${ cfg . name } " . source = 162" ${ cfg . package } /share/icons/ ${ cfg . name } " ; 163} 164 165( mkIf cfg . x11 . enable { 166xsession . initExtra = '' 167${ pkgs . xorg . xsetroot } /bin/xsetroot -xcf ${ cursorPath } ${ 168toString cfg . size 169} 170'' ; 171 172xresources . properties = { 173"Xcursor.theme" = cfg . name ; 174"Xcursor.size" = cfg . size ; 175}; 176}) 177 178( mkIf cfg . gtk . enable { 179gtk . cursorTheme = mkDefault { inherit ( cfg ) package name size ; }; 180}) 181]); 182}