fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , stdenv , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . twmn ; 8 9animationOpts = { 10curve = mkOption { 11type = types . ints . between 0 40 ; 12default = 38 ; 13example = 19 ; 14description = '' 15The qt easing-curve animation to use for the animation. See 16[ 17QEasingCurve documentation](https://doc.qt.io/qt-5/qeasingcurve.html#Type-enum). 18'' ; 19}; 20 21duration = mkOption { 22type = types . ints . unsigned ; 23default = 1000 ; 24example = 618 ; 25description = "The animation duration in milliseconds." ; 26}; 27}; 28 29in { 30meta . maintainers = [ hm . maintainers . austreelis ]; 31 32options . services . twmn = { 33enable = mkEnableOption "twmn, a tiling window manager notification daemon" ; 34 35duration = mkOption { 36type = types . ints . unsigned ; 37default = 3000 ; 38example = 5000 ; 39description = '' 40The time each notification remains visible, in milliseconds. 41'' ; 42}; 43 44extraConfig = mkOption { 45type = types . attrs ; 46default = { }; 47example = literalExpression 48''{ main.activation_command = "\ ${ pkgs . hello } /bin/hello"; }'' ; 49description = '' 50Extra configuration options to add to the twmnd config file. See 51<https://github.com/sboli/twmn/blob/master/README.md> 52for details. 53'' ; 54}; 55 56host = mkOption { 57type = types . str ; 58default = "127.0.0.1" ; 59example = "laptop.lan" ; 60description = "Host address to listen on for notifications." ; 61}; 62 63icons = { 64critical = mkOption { 65type = types . nullOr types . path ; 66default = null ; 67description = "Path to the critical notifications' icon." ; 68}; 69 70info = mkOption { 71type = types . nullOr types . path ; 72default = null ; 73description = "Path to the informative notifications' icon." ; 74}; 75 76warning = mkOption { 77type = types . nullOr types . path ; 78default = null ; 79description = "Path to the warning notifications' icon." ; 80}; 81}; 82 83port = mkOption { 84type = types . port ; 85default = 9797 ; 86description = "UDP port to listen on for notifications." ; 87}; 88 89screen = mkOption { 90type = types . nullOr types . int ; 91default = null ; 92example = 0 ; 93description = '' 94Screen number to display notifications on when using a multi-head 95desktop. 96'' ; 97}; 98 99soundCommand = mkOption { 100type = types . str ; 101default = "" ; 102description = "Command to execute to play a notification's sound." ; 103}; 104 105text = { 106color = mkOption { 107type = types . str ; 108default = "#999999" ; 109example = "lightgray" ; 110description = '' 111Notification's text color. RGB hex and keywords (e.g. `lightgray`) 112are supported. 113'' ; 114}; 115 116font = { 117package = mkOption { 118type = types . nullOr types . package ; 119default = null ; 120example = literalExpression "pkgs.dejavu_fonts" ; 121description = '' 122Notification text's font package. If `null` then 123the font is assumed to already be available in your profile. 124'' ; 125}; 126 127family = mkOption { 128type = types . str ; 129default = "Sans" ; 130example = "Noto Sans" ; 131description = "Notification text's font family." ; 132}; 133 134size = mkOption { 135type = types . ints . unsigned ; 136default = 13 ; 137example = 42 ; 138description = "Notification text's font size." ; 139}; 140 141variant = mkOption { 142# These are the font variant supported by twmn 143# See https://github.com/sboli/twmn/blob/master/README.md?plain=1#L42 144type = types . enum [ 145"oblique" 146"italic" 147"ultra-light" 148"light" 149"medium" 150"semi-bold" 151"bold" 152"ultra-bold" 153"heavy" 154"ultra-condensed" 155"extra-condensed" 156"condensed" 157"semi-condensed" 158"semi-expanded" 159"expanded" 160"extra-expanded" 161"ultra-expanded" 162]; 163default = "medium" ; 164example = "heavy" ; 165description = "Notification text's font variant." ; 166}; 167}; 168 169maxLength = mkOption { 170type = types . nullOr types . ints . unsigned ; 171default = null ; 172example = 80 ; 173description = '' 174Maximum length of the text before it is cut and suffixed with "...". 175Never cuts if `null`. 176'' ; 177}; 178}; 179 180window = { 181alwaysOnTop = 182mkEnableOption "forcing the notification window to always be on top" ; 183 184animation = { 185easeIn = mkOption { 186type = types . submodule { options = animationOpts ; }; 187default = { }; 188example = literalExpression '' 189{ 190curve = 19; 191duration = 618; 192} 193'' ; 194description = "Options for the notification appearance's animation." ; 195}; 196 197easeOut = mkOption { 198type = types . submodule { options = animationOpts ; }; 199default = { }; 200example = literalExpression '' 201{ 202curve = 19; 203duration = 618; 204} 205'' ; 206description = 207"Options for the notification disappearance's animation." ; 208}; 209 210bounce = { 211enable = mkEnableOption 212"notification bounce when displaying next notification directly" ; 213 214duration = mkOption { 215type = types . ints . unsigned ; 216default = 500 ; 217example = 618 ; 218description = "The bounce animation duration in milliseconds." ; 219}; 220}; 221}; 222 223color = mkOption { 224type = types . str ; 225default = "#000000" ; 226example = "lightgray" ; 227description = '' 228Notification's background color. RGB hex and keywords (e.g. 229`lightgray`) are supported. 230'' ; 231}; 232 233height = mkOption { 234type = types . ints . unsigned ; 235default = 18 ; 236example = 42 ; 237description = '' 238Height of the slide bar. Useful to match your tiling window 239manager's bar. 240'' ; 241}; 242 243offset = { 244x = mkOption { 245type = types . int ; 246default = 0 ; 247example = 50 ; 248description = '' 249Offset of the notification's slide starting point in pixels on the 250horizontal axis (positive is rightward). 251'' ; 252}; 253 254y = mkOption { 255type = types . int ; 256default = 0 ; 257example = - 100 ; 258description = '' 259Offset of the notification's slide starting point in pixels on the 260vertical axis (positive is upward). 261'' ; 262}; 263}; 264 265opacity = mkOption { 266type = types . ints . between 0 100 ; 267default = 100 ; 268example = 80 ; 269description = "The notification window's opacity." ; 270}; 271 272position = mkOption { 273type = types . enum [ 274"tr" 275"top_right" 276"tl" 277"top_left" 278"br" 279"bottom_right" 280"bl" 281"bottom_left" 282"tc" 283"top_center" 284"bc" 285"bottom_center" 286"c" 287"center" 288]; 289default = "top_right" ; 290example = "bottom_left" ; 291description = '' 292Position of the notification slide. The notification will slide 293in vertically from the border if placed in 294`top_center` or `bottom_center`, 295horizontally otherwise. 296'' ; 297}; 298}; 299}; 300 301################# 302# Implementation 303 304config = mkIf cfg . enable { 305assertions = [ 306( lib . hm . assertions . assertPlatform "services.twmn" pkgs 307lib . platforms . linux ) 308]; 309 310home . packages = 311lib . optional ( ! isNull cfg . text . font . package ) cfg . text . font . package 312++ [ pkgs . twmn ]; 313 314xdg . configFile . "twmn/twmn.conf" . text = let 315conf = recursiveUpdate { 316gui = { 317always_on_top = if cfg . window . alwaysOnTop then "true" else "false" ; 318background_color = cfg . window . color ; 319bounce = 320if cfg . window . animation . bounce . enable then "true" else "false" ; 321bounce_duration = toString cfg . window . animation . bounce . duration ; 322font = cfg . text . font . family ; 323font_size = toString cfg . text . font . size ; 324font_variant = cfg . text . font . variant ; 325foreground_color = cfg . text . color ; 326height = toString cfg . window . height ; 327in_animation = toString cfg . window . animation . easeIn . curve ; 328in_animation_duration = toString cfg . window . animation . easeIn . duration ; 329max_length = toString 330( if isNull cfg . text . maxLength then - 1 else cfg . text . maxLength ); 331offset_x = with cfg . window . offset ; 332if x < 0 then toString x else "+ ${ toString x } " ; 333offset_y = with cfg . window . offset ; 334if y < 0 then toString y else "+ ${ toString y } " ; 335opacity = toString cfg . window . opacity ; 336out_animation = toString cfg . window . animation . easeOut . curve ; 337out_animation_duration = 338toString cfg . window . animation . easeOut . duration ; 339position = cfg . window . position ; 340screen = toString cfg . screen ; 341}; 342# map null values to empty strings because formats.toml generator fails 343# when encountering a null. 344icons = mapAttrs ( _ :toString ) cfg . icons ; 345main = { 346duration = toString cfg . duration ; 347host = cfg . host ; 348port = toString cfg . port ; 349sound_command = cfg . soundCommand ; 350}; 351} cfg . extraConfig ; 352 353mkLine = name :value :" ${ name } = ${ value } " ; 354 355mkSection = section :conf :'' 356[ ${ section } ] 357${ concatStringsSep "\n" ( mapAttrsToList mkLine conf )} 358'' ; 359in concatStringsSep "\n" ( mapAttrsToList mkSection conf ) + "\n" ; 360 361systemd . user . services . twmnd = { 362Unit = { 363Description = "twmn daemon" ; 364After = [ "graphical-session-pre.target" ]; 365PartOf = [ "graphical-session.target" ]; 366X-Restart-Triggers = 367[ " ${ config . xdg . configFile . "twmn/twmn.conf" . source } " ]; 368}; 369 370Install . WantedBy = [ "graphical-session.target" ]; 371 372Service = { 373ExecStart = " ${ pkgs . twmn } /bin/twmnd" ; 374Restart = "on-failure" ; 375Type = "simple" ; 376StandardOutput = "null" ; 377}; 378}; 379}; 380}