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 . programs . rofi ; 8 9mkValueString = value : 10if isBool value then 11if value then "true" else "false" 12else if isInt value then 13toString value 14else if ( value . _type or "" ) == "literal" then 15value . value 16else if isString value then 17''" ${ value } "'' 18else if isList value then 19"[ ${ strings . concatStringsSep "," ( map mkValueString value )} ]" 20else 21abort "Unhandled value type ${ builtins . typeOf value } " ; 22 23mkKeyValue = { sep ? ": " , end ? ";" } : 24name :value : 25" ${ name }${ sep }${ mkValueString value }${ end } " ; 26 27mkRasiSection = name :value : 28if isAttrs value then 29let 30toRasiKeyValue = generators . toKeyValue { mkKeyValue = mkKeyValue { }; }; 31# Remove null values so the resulting config does not have empty lines 32configStr = toRasiKeyValue ( filterAttrs ( _ :v :v != null ) value ); 33in '' 34${ name } { 35${ configStr } } 36'' 37else 38( mkKeyValue { 39sep = " " ; 40end = "" ; 41} name value ) + "\n" ; 42 43toRasi = attrs : 44concatStringsSep "\n" ( concatMap ( mapAttrsToList mkRasiSection ) [ 45( filterAttrs ( n :_ :n == "@theme" ) attrs ) 46( filterAttrs ( n :_ :n == "@import" ) attrs ) 47( removeAttrs attrs [ "@theme" "@import" ]) 48]); 49 50locationsMap = { 51center = 0 ; 52top-left = 1 ; 53top = 2 ; 54top-right = 3 ; 55right = 4 ; 56bottom-right = 5 ; 57bottom = 6 ; 58bottom-left = 7 ; 59left = 8 ; 60}; 61 62primitive = with types ; ( oneOf [ str int bool rasiLiteral ]); 63 64# Either a `section { foo: "bar"; }` or a `@import/@theme "some-text"` 65configType = with types ; 66( either ( attrsOf ( either primitive ( listOf primitive ))) str ); 67 68rasiLiteral = types . submodule { 69options = { 70_type = mkOption { 71type = types . enum [ "literal" ]; 72internal = true ; 73}; 74 75value = mkOption { 76type = types . str ; 77internal = true ; 78}; 79}; 80} // { 81description = "Rasi literal string" ; 82}; 83 84themeType = with types ; attrsOf configType ; 85 86themeName = if ( cfg . theme == null ) then 87null 88else if ( isString cfg . theme ) then 89cfg . theme 90else if ( isAttrs cfg . theme ) then 91"custom" 92else 93removeSuffix ".rasi" ( baseNameOf cfg . theme ); 94 95themePath = if ( isString cfg . theme ) then 96null 97else if ( isAttrs cfg . theme ) then 98"custom" 99else 100cfg . theme ; 101 102in { 103options . programs . rofi = { 104enable = mkEnableOption 105"Rofi: A window switcher, application launcher and dmenu replacement" ; 106 107package = mkOption { 108default = pkgs . rofi ; 109type = types . package ; 110description = '' 111Package providing the {command}`rofi` binary. 112'' ; 113example = literalExpression '' 114pkgs.rofi.override { plugins = [ pkgs.rofi-emoji ]; }; 115'' ; 116}; 117 118finalPackage = mkOption { 119type = types . package ; 120readOnly = true ; 121description = '' 122Resulting customized rofi package. 123'' ; 124}; 125 126plugins = mkOption { 127default = [ ]; 128type = types . listOf types . package ; 129description = '' 130List of rofi plugins to be installed. 131'' ; 132example = literalExpression "[ pkgs.rofi-calc ]" ; 133}; 134 135font = mkOption { 136default = null ; 137type = types . nullOr types . str ; 138example = "Droid Sans Mono 14" ; 139description = "Font to use." ; 140}; 141 142terminal = mkOption { 143default = null ; 144type = types . nullOr types . str ; 145description = '' 146Path to the terminal which will be used to run console applications 147'' ; 148example = "\${pkgs.gnome.gnome_terminal}/bin/gnome-terminal" ; 149}; 150 151cycle = mkOption { 152default = null ; 153type = types . nullOr types . bool ; 154description = "Whether to cycle through the results list." ; 155}; 156 157location = mkOption { 158default = "center" ; 159type = types . enum ( attrNames locationsMap ); 160description = "The location rofi appears on the screen." ; 161}; 162 163xoffset = mkOption { 164default = 0 ; 165type = types . int ; 166description = '' 167Offset in the x-axis in pixels relative to the chosen location. 168'' ; 169}; 170 171yoffset = mkOption { 172default = 0 ; 173type = types . int ; 174description = '' 175Offset in the y-axis in pixels relative to the chosen location. 176'' ; 177}; 178 179theme = mkOption { 180default = null ; 181type = with types ; nullOr ( oneOf [ str path themeType ]); 182example = literalExpression '' 183let 184# Use `mkLiteral` for string-like values that should show without 185# quotes, e.g.: 186# { 187# foo = "abc"; => foo: "abc"; 188# bar = mkLiteral "abc"; => bar: abc; 189# }; 190inherit (config.lib.formats.rasi) mkLiteral; 191in { 192"*" = { 193background-color = mkLiteral "#000000"; 194foreground-color = mkLiteral "rgba ( 250, 251, 252, 100 % )"; 195border-color = mkLiteral "#FFFFFF"; 196width = 512; 197}; 198 199"#inputbar" = { 200children = map mkLiteral [ "prompt" "entry" ]; 201}; 202 203"#textbox-prompt-colon" = { 204expand = false; 205str = ":"; 206margin = mkLiteral "0px 0.3em 0em 0em"; 207text-color = mkLiteral "@foreground-color"; 208}; 209} 210'' ; 211description = '' 212Name of theme or path to theme file in rasi format or attribute set with 213theme configuration. Available named themes can be viewed using the 214{command}`rofi-theme-selector` tool. 215'' ; 216}; 217 218configPath = mkOption { 219default = " ${ config . xdg . configHome } /rofi/config.rasi" ; 220defaultText = "$XDG_CONFIG_HOME/rofi/config.rasi" ; 221type = types . str ; 222description = "Path where to put generated configuration file." ; 223}; 224 225extraConfig = mkOption { 226default = { }; 227example = literalExpression '' 228{ 229modi = "drun,emoji,ssh"; 230kb-primary-paste = "Control+V,Shift+Insert"; 231kb-secondary-paste = "Control+v,Insert"; 232} 233'' ; 234type = configType ; 235description = "Additional configuration to add." ; 236}; 237 238}; 239 240imports = let 241mkRemovedOptionRofi = option : 242( mkRemovedOptionModule [ "programs" "rofi" option ] 243"Please use a Rofi theme instead." ); 244in map mkRemovedOptionRofi [ 245"width" 246"lines" 247"borderWidth" 248"rowHeight" 249"padding" 250"separator" 251"scrollbar" 252"fullscreen" 253"colors" 254]; 255 256config = mkIf cfg . enable { 257assertions = 258[ ( hm . assertions . assertPlatform "programs.rofi" pkgs platforms . linux ) ]; 259 260lib . formats . rasi . mkLiteral = value :{ 261_type = "literal" ; 262inherit value ; 263}; 264 265programs . rofi . finalPackage = let 266rofiWithPlugins = cfg . package . override 267( old :{ plugins = ( old . plugins or [ ]) ++ cfg . plugins ; }); 268in if builtins . hasAttr "override" cfg . package && cfg . plugins != [ ] then 269rofiWithPlugins 270else 271cfg . package ; 272 273home . packages = [ cfg . finalPackage ]; 274 275home . file . " ${ cfg . configPath } " . text = toRasi { 276configuration = ({ 277font = cfg . font ; 278terminal = cfg . terminal ; 279cycle = cfg . cycle ; 280location = ( getAttr cfg . location locationsMap ); 281xoffset = cfg . xoffset ; 282yoffset = cfg . yoffset ; 283} // cfg . extraConfig ); 284# @theme must go after configuration but attrs are output in alphabetical order ('@' first) 285} + ( optionalString ( themeName != null ) ( toRasi { "@theme" = themeName ; })); 286 287xdg . dataFile = mkIf ( themePath != null ) ( if themePath == "custom" then { 288"rofi/themes/ ${ themeName } .rasi" . text = toRasi cfg . theme ; 289} else { 290"rofi/themes/ ${ themeName } .rasi" . source = themePath ; 291}); 292}; 293 294meta . maintainers = with maintainers ; [ thiagokokada ]; 295}