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