Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

yabar: add module

To make the configuration of `yabar` more pleasant and easier to
validate, a NixOS module will be quite helpful.

An example config could look like this:

```
{
programs.yabar = {
enable = true;
bars.top.indicators.exec = "YA_DATE";
};
}
```

The module adds a user-controlled systemd service which runs `yabar` after
starting up X.

+176
+1
nixos/modules/module-list.nix
··· 110 ./programs/wireshark.nix 111 ./programs/xfs_quota.nix 112 ./programs/xonsh.nix 113 ./programs/zsh/oh-my-zsh.nix 114 ./programs/zsh/zsh.nix 115 ./programs/zsh/zsh-syntax-highlighting.nix
··· 110 ./programs/wireshark.nix 111 ./programs/xfs_quota.nix 112 ./programs/xonsh.nix 113 + ./programs/yabar.nix 114 ./programs/zsh/oh-my-zsh.nix 115 ./programs/zsh/zsh.nix 116 ./programs/zsh/zsh-syntax-highlighting.nix
+149
nixos/modules/programs/yabar.nix
···
··· 1 + { lib, pkgs, config, ... }: 2 + 3 + with lib; 4 + 5 + let 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 + ''; 41 + in 42 + { 43 + options.programs.yabar = { 44 + enable = mkEnableOption "yabar"; 45 + 46 + package = mkOption { 47 + default = pkgs.yabar; 48 + example = literalExample "pkgs.yabar-unstable"; 49 + type = types.package; 50 + 51 + description = '' 52 + The package which contains the `yabar` binary. 53 + 54 + Nixpkgs provides the `yabar` and `yabar-unstable` 55 + derivations since 18.03, so it's possible to choose. 56 + ''; 57 + }; 58 + 59 + bars = mkOption { 60 + default = {}; 61 + type = types.attrsOf(types.submodule { 62 + options = { 63 + font = mkOption { 64 + default = "sans bold 9"; 65 + example = "Droid Sans, FontAwesome Bold 9"; 66 + type = types.string; 67 + 68 + description = '' 69 + The font that will be used to draw the status bar. 70 + ''; 71 + }; 72 + 73 + position = mkOption { 74 + default = "top"; 75 + example = "bottom"; 76 + type = types.enum [ "top" "bottom" ]; 77 + 78 + description = '' 79 + The position where the bar will be rendered. 80 + ''; 81 + }; 82 + 83 + extra = mkOption { 84 + default = {}; 85 + type = types.attrsOf types.string; 86 + 87 + description = '' 88 + An attribute set which contains further attributes of a bar. 89 + ''; 90 + }; 91 + 92 + indicators = mkOption { 93 + default = {}; 94 + type = types.attrsOf(types.submodule { 95 + options.exec = mkOption { 96 + example = "YABAR_DATE"; 97 + type = types.string; 98 + description = '' 99 + The type of the indicator to be executed. 100 + ''; 101 + }; 102 + 103 + options.align = mkOption { 104 + default = "left"; 105 + example = "right"; 106 + type = types.enum [ "left" "center" "right" ]; 107 + 108 + description = '' 109 + Whether to align the indicator at the left or right of the bar. 110 + ''; 111 + }; 112 + 113 + options.extra = mkOption { 114 + default = {}; 115 + type = types.attrsOf (types.either types.string types.int); 116 + 117 + description = '' 118 + An attribute set which contains further attributes of a indicator. 119 + ''; 120 + }; 121 + }); 122 + 123 + description = '' 124 + Indicators that should be rendered by yabar. 125 + ''; 126 + }; 127 + }; 128 + }); 129 + 130 + description = '' 131 + List of bars that should be rendered by yabar. 132 + ''; 133 + }; 134 + }; 135 + 136 + config = mkIf cfg.enable { 137 + systemd.user.services.yabar = { 138 + description = "yabar service"; 139 + wantedBy = [ "graphical-session.target" ]; 140 + partOf = [ "graphical-session.target" ]; 141 + 142 + script = '' 143 + ${cfg.package}/bin/yabar -c ${configFile} 144 + ''; 145 + 146 + serviceConfig.Restart = "always"; 147 + }; 148 + }; 149 + }
+1
nixos/release.nix
··· 356 tests.wordpress = callTest tests/wordpress.nix {}; 357 tests.xfce = callTest tests/xfce.nix {}; 358 tests.xmonad = callTest tests/xmonad.nix {}; 359 tests.zookeeper = callTest tests/zookeeper.nix {}; 360 361 /* Build a bunch of typical closures so that Hydra can keep track of
··· 356 tests.wordpress = callTest tests/wordpress.nix {}; 357 tests.xfce = callTest tests/xfce.nix {}; 358 tests.xmonad = callTest tests/xmonad.nix {}; 359 + tests.yabar = callTest tests/yabar.nix {}; 360 tests.zookeeper = callTest tests/zookeeper.nix {}; 361 362 /* Build a bunch of typical closures so that Hydra can keep track of
+25
nixos/tests/yabar.nix
···
··· 1 + import ./make-test.nix ({ pkgs, lib }: 2 + 3 + with lib; 4 + 5 + { 6 + name = "yabar"; 7 + meta = with pkgs.stdenv.lib.maintainers; { 8 + maintainers = [ ma27 ]; 9 + }; 10 + 11 + nodes.yabar = { 12 + imports = [ ./common/x11.nix ./common/user-account.nix ]; 13 + 14 + services.xserver.displayManager.auto.user = "bob"; 15 + 16 + programs.yabar.enable = true; 17 + }; 18 + 19 + testScript = '' 20 + $yabar->start; 21 + $yabar->waitForX; 22 + 23 + $yabar->waitForUnit("yabar.service", "bob"); 24 + ''; 25 + })