fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3let 4inherit ( lib ) all filterAttrs isStorePath literalExpression types ; 5inherit ( lib . options ) mkEnableOption mkPackageOption mkOption ; 6inherit ( lib . modules ) mkIf ; 7inherit ( lib . strings ) concatMapStrings ; 8inherit ( builtins ) toJSON ; 9 10cfg = config . programs . wlogout ; 11 12jsonFormat = pkgs . formats . json { }; 13 14wlogoutLayoutConfig = with types ; 15submodule { 16freeformType = jsonFormat . type ; 17 18options = { 19label = mkOption { 20type = str ; 21default = "" ; 22example = "shutdown" ; 23description = "CSS label of button." ; 24}; 25 26action = mkOption { 27type = either path str ; 28default = "" ; 29example = "systemctl poweroff" ; 30description = "Command to execute when clicked." ; 31}; 32 33text = mkOption { 34type = str ; 35default = "" ; 36example = "Shutdown" ; 37description = "Text displayed on button." ; 38}; 39 40keybind = mkOption { 41type = str ; 42default = "" ; 43example = "s" ; 44description = "Keyboard character to trigger this action." ; 45}; 46 47height = mkOption { 48type = nullOr ( numbers . between 0 1 ); 49default = null ; 50example = 0.5 ; 51description = "Relative height of tile." ; 52}; 53 54width = mkOption { 55type = nullOr ( numbers . between 0 1 ); 56default = null ; 57example = 0.5 ; 58description = "Relative width of tile." ; 59}; 60 61circular = mkOption { 62type = nullOr bool ; 63default = null ; 64example = true ; 65description = "Make button circular." ; 66}; 67}; 68}; 69in { 70meta . maintainers = [ lib . maintainers . Scrumplex ]; 71 72options . programs . wlogout = with lib . types ; { 73enable = mkEnableOption "wlogout" ; 74 75package = mkPackageOption pkgs "wlogout" { }; 76 77layout = mkOption { 78type = listOf wlogoutLayoutConfig ; 79default = [ ]; 80description = '' 81Layout configuration for wlogout, see <https://github.com/ArtsyMacaw/wlogout#config> 82for supported values. 83'' ; 84example = literalExpression '' 85[ 86{ 87label = "shutdown"; 88action = "systemctl poweroff"; 89text = "Shutdown"; 90keybind = "s"; 91} 92] 93'' ; 94}; 95 96style = mkOption { 97type = nullOr ( either path str ); 98default = null ; 99description = '' 100CSS style of the bar. 101 102See <https://github.com/ArtsyMacaw/wlogout#style> 103for the documentation. 104 105If the value is set to a path literal, then the path will be used as the css file. 106'' ; 107example = '' 108window { 109background: #16191C; 110} 111 112button { 113color: #AAB2BF; 114} 115'' ; 116}; 117}; 118 119config = let 120# Removes nulls because wlogout ignores them. 121# This is not recursive. 122removeTopLevelNulls = filterAttrs ( _ :v :v != null ); 123cleanJSON = foo :toJSON ( removeTopLevelNulls foo ); 124 125# wlogout doesn't want a JSON array, it just wants a list of JSON objects 126layoutJsons = map cleanJSON cfg . layout ; 127layoutContent = concatMapStrings ( l :l + "\n" ) layoutJsons ; 128 129in mkIf cfg . enable { 130assertions = [ 131( lib . hm . assertions . assertPlatform "programs.wlogout" pkgs 132lib . platforms . linux ) 133]; 134 135home . packages = [ cfg . package ]; 136 137xdg . configFile . "wlogout/layout" = mkIf ( cfg . layout != [ ]) { 138source = pkgs . writeText "wlogout/layout" layoutContent ; 139}; 140 141xdg . configFile . "wlogout/style.css" = mkIf ( cfg . style != null ) { 142source = if builtins . isPath cfg . style || isStorePath cfg . style then 143cfg . style 144else 145pkgs . writeText "wlogout/style.css" cfg . style ; 146}; 147}; 148}