fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . dunst ; 8 9eitherStrBoolIntList = with types ; 10either str ( either bool ( either int ( listOf str ))); 11 12toDunstIni = generators . toINI { 13mkKeyValue = key :value : 14let 15value' = if isBool value then 16( lib . hm . booleans . yesNo value ) 17else if isString value then 18''" ${ value } "'' 19else 20toString value ; 21in " ${ key } = ${ value' } " ; 22}; 23 24themeType = types . submodule { 25options = { 26package = mkOption { 27type = types . package ; 28example = literalExpression "pkgs.gnome.adwaita-icon-theme" ; 29description = "Package providing the theme." ; 30}; 31 32name = mkOption { 33type = types . str ; 34example = "Adwaita" ; 35description = "The name of the theme within the package." ; 36}; 37 38size = mkOption { 39type = types . str ; 40default = "32x32" ; 41example = "16x16" ; 42description = "The desired icon size." ; 43}; 44}; 45}; 46 47hicolorTheme = { 48package = pkgs . hicolor-icon-theme ; 49name = "hicolor" ; 50size = "32x32" ; 51}; 52 53in { 54meta . maintainers = [ maintainers . rycee ]; 55 56options = { 57services . dunst = { 58enable = mkEnableOption "the dunst notification daemon" ; 59 60package = mkOption { 61type = types . package ; 62default = pkgs . dunst ; 63defaultText = literalExpression "pkgs.dunst" ; 64description = "Package providing {command}`dunst`." ; 65}; 66 67configFile = mkOption { 68type = with types ; either str path ; 69default = " ${ config . xdg . configHome } /dunst/dunstrc" ; 70defaultText = "$XDG_CONFIG_HOME/dunst/dunstrc" ; 71description = '' 72Path to the configuration file read by dunst. 73 74Note that the configuration generated by Home Manager will be 75written to {file}`$XDG_CONFIG_HOME/dunst/dunstrc` 76regardless. This allows using a mutable configuration file generated 77from the immutable one, useful in scenarios where live reloading is 78desired. 79'' ; 80}; 81 82iconTheme = mkOption { 83type = themeType ; 84default = hicolorTheme ; 85description = "Set the icon theme." ; 86}; 87 88waylandDisplay = mkOption { 89type = types . str ; 90default = "" ; 91description = 92"Set the service's {env}`WAYLAND_DISPLAY` environment variable." ; 93}; 94 95settings = mkOption { 96type = types . submodule { 97freeformType = with types ; attrsOf ( attrsOf eitherStrBoolIntList ); 98options = { 99global . icon_path = mkOption { 100type = types . separatedString ":" ; 101description = "Paths where dunst will look for icons." ; 102}; 103}; 104}; 105default = { }; 106description = 107"Configuration written to {file}`$XDG_CONFIG_HOME/dunst/dunstrc`." ; 108example = literalExpression '' 109{ 110global = { 111width = 300; 112height = 300; 113offset = "30x50"; 114origin = "top-right"; 115transparency = 10; 116frame_color = "#eceff1"; 117font = "Droid Sans 9"; 118}; 119 120urgency_normal = { 121background = "#37474f"; 122foreground = "#eceff1"; 123timeout = 10; 124}; 125}; 126'' ; 127}; 128}; 129}; 130 131config = mkIf cfg . enable ( mkMerge [ 132{ 133assertions = [ 134( hm . assertions . assertPlatform "services.dunst" pkgs platforms . linux ) 135]; 136 137home . packages = [ cfg . package ]; 138 139xdg . dataFile . "dbus-1/services/org.knopwob.dunst.service" . source = 140" ${ pkgs . dunst } /share/dbus-1/services/org.knopwob.dunst.service" ; 141 142services . dunst . settings . global . icon_path = let 143useCustomTheme = cfg . iconTheme . package != hicolorTheme . package 144|| cfg . iconTheme . name != hicolorTheme . name || cfg . iconTheme . size 145!= hicolorTheme . size ; 146 147basePaths = [ 148"/run/current-system/sw" 149config . home . profileDirectory 150cfg . iconTheme . package 151] ++ optional useCustomTheme hicolorTheme . package ; 152 153themes = [ cfg . iconTheme ] ++ optional useCustomTheme 154( hicolorTheme // { size = cfg . iconTheme . size ; }); 155 156categories = [ 157"actions" 158"animations" 159"apps" 160"categories" 161"devices" 162"emblems" 163"emotes" 164"filesystem" 165"intl" 166"legacy" 167"mimetypes" 168"places" 169"status" 170"stock" 171]; 172 173mkPath = { basePath , theme , category } : 174" ${ basePath } /share/icons/ ${ theme . name } / ${ theme . size } / ${ category } " ; 175in concatMapStringsSep ":" mkPath ( cartesianProductOfSets { 176basePath = basePaths ; 177theme = themes ; 178category = categories ; 179}); 180 181systemd . user . services . dunst = { 182Unit = { 183Description = "Dunst notification daemon" ; 184After = [ "graphical-session-pre.target" ]; 185PartOf = [ "graphical-session.target" ]; 186}; 187 188Service = { 189Type = "dbus" ; 190BusName = "org.freedesktop.Notifications" ; 191ExecStart = " ${ cfg . package } /bin/dunst -config ${ cfg . configFile } " ; 192Environment = optionalString ( cfg . waylandDisplay != "" ) 193"WAYLAND_DISPLAY= ${ cfg . waylandDisplay } " ; 194}; 195}; 196} 197 198( mkIf ( cfg . settings != { }) { 199xdg . configFile . "dunst/dunstrc" = { 200text = toDunstIni cfg . settings ; 201onChange = '' 202${ pkgs . procps } /bin/pkill -u "$USER" ''${VERBOSE+-e} dunst || true 203'' ; 204}; 205}) 206]); 207}