at 25.11-pre 5.3 kB view raw
1{ 2 lib, 3 pkgs, 4 config, 5 ... 6}: 7 8let 9 cfg = config.programs.yabar; 10 11 mapExtra = 12 v: 13 lib.concatStringsSep "\n" ( 14 lib.mapAttrsToList ( 15 key: val: 16 "${key} = ${if (builtins.isString val) then "\"${val}\"" else "${builtins.toString val}"};" 17 ) v 18 ); 19 20 listKeys = r: builtins.concatStringsSep "," (builtins.map (n: "\"${n}\"") (builtins.attrNames r)); 21 22 configFile = 23 let 24 bars = lib.mapAttrsToList (name: cfg: '' 25 ${name}: { 26 font: "${cfg.font}"; 27 position: "${cfg.position}"; 28 29 ${mapExtra cfg.extra} 30 31 block-list: [${listKeys cfg.indicators}] 32 33 ${builtins.concatStringsSep "\n" ( 34 lib.mapAttrsToList (name: cfg: '' 35 ${name}: { 36 exec: "${cfg.exec}"; 37 align: "${cfg.align}"; 38 ${mapExtra cfg.extra} 39 }; 40 '') cfg.indicators 41 )} 42 }; 43 '') cfg.bars; 44 in 45 pkgs.writeText "yabar.conf" '' 46 bar-list = [${listKeys cfg.bars}]; 47 ${builtins.concatStringsSep "\n" bars} 48 ''; 49in 50{ 51 options.programs.yabar = { 52 enable = lib.mkEnableOption "yabar, a status bar for X window managers"; 53 54 package = lib.mkOption { 55 default = pkgs.yabar-unstable; 56 defaultText = lib.literalExpression "pkgs.yabar-unstable"; 57 example = lib.literalExpression "pkgs.yabar"; 58 type = lib.types.package; 59 60 # `yabar-stable` segfaults under certain conditions. 61 # remember to update yabar.passthru.tests if nixos switches back to it! 62 apply = 63 x: 64 if x == pkgs.yabar-unstable then 65 x 66 else 67 lib.flip lib.warn x '' 68 It's not recommended to use `yabar' with `programs.yabar', the (old) stable release 69 tends to segfault under certain circumstances: 70 71 * https://github.com/geommer/yabar/issues/86 72 * https://github.com/geommer/yabar/issues/68 73 * https://github.com/geommer/yabar/issues/143 74 75 Most of them don't occur on master anymore, until a new release is published, it's recommended 76 to use `yabar-unstable'. 77 ''; 78 79 description = '' 80 The package which contains the `yabar` binary. 81 82 Nixpkgs offers both a stable (`yabar`) and unstable (`yabar-unstable`) version of Yabar. 83 ''; 84 }; 85 86 bars = lib.mkOption { 87 default = { }; 88 type = lib.types.attrsOf ( 89 lib.types.submodule { 90 options = { 91 font = lib.mkOption { 92 default = "sans bold 9"; 93 example = "Droid Sans, FontAwesome Bold 9"; 94 type = lib.types.str; 95 96 description = '' 97 The font that will be used to draw the status bar. 98 ''; 99 }; 100 101 position = lib.mkOption { 102 default = "top"; 103 example = "bottom"; 104 type = lib.types.enum [ 105 "top" 106 "bottom" 107 ]; 108 109 description = '' 110 The position where the bar will be rendered. 111 ''; 112 }; 113 114 extra = lib.mkOption { 115 default = { }; 116 type = lib.types.attrsOf lib.types.str; 117 118 description = '' 119 An attribute set which contains further attributes of a bar. 120 ''; 121 }; 122 123 indicators = lib.mkOption { 124 default = { }; 125 type = lib.types.attrsOf ( 126 lib.types.submodule { 127 options.exec = lib.mkOption { 128 example = "YABAR_DATE"; 129 type = lib.types.str; 130 description = '' 131 The type of the indicator to be executed. 132 ''; 133 }; 134 135 options.align = lib.mkOption { 136 default = "left"; 137 example = "right"; 138 type = lib.types.enum [ 139 "left" 140 "center" 141 "right" 142 ]; 143 144 description = '' 145 Whether to align the indicator at the left or right of the bar. 146 ''; 147 }; 148 149 options.extra = lib.mkOption { 150 default = { }; 151 type = lib.types.attrsOf (lib.types.either lib.types.str lib.types.int); 152 153 description = '' 154 An attribute set which contains further attributes of a indicator. 155 ''; 156 }; 157 } 158 ); 159 160 description = '' 161 Indicators that should be rendered by yabar. 162 ''; 163 }; 164 }; 165 } 166 ); 167 168 description = '' 169 List of bars that should be rendered by yabar. 170 ''; 171 }; 172 }; 173 174 config = lib.mkIf cfg.enable { 175 systemd.user.services.yabar = { 176 description = "yabar service"; 177 wantedBy = [ "graphical-session.target" ]; 178 partOf = [ "graphical-session.target" ]; 179 180 script = '' 181 ${cfg.package}/bin/yabar -c ${configFile} 182 ''; 183 184 serviceConfig.Restart = "always"; 185 }; 186 }; 187}