1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-16 08:09:45 +01:00
home-manager/modules/services/polybar.nix

136 lines
3.7 KiB
Nix
Raw Normal View History

2017-10-05 15:55:37 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.polybar;
2020-02-02 00:39:17 +01:00
eitherStrBoolIntList = with types;
either str (either bool (either int (listOf str)));
2018-12-05 11:54:52 +01:00
toPolybarIni = generators.toINI {
mkKeyValue = key: value:
2018-08-29 21:46:11 +02:00
let
quoted = v:
2020-02-02 00:39:17 +01:00
if hasPrefix " " v || hasSuffix " " v then ''"${v}"'' else v;
value' = if isBool value then
(if value then "true" else "false")
else if (isString value && key != "include-file") then
quoted value
else
toString value;
in "${key}=${value'}";
};
2017-10-05 15:55:37 +02:00
configFile = pkgs.writeText "polybar.conf"
(toPolybarIni cfg.config + "\n" + cfg.extraConfig);
2017-10-05 15:55:37 +02:00
2020-02-02 00:39:17 +01:00
in {
2017-10-05 15:55:37 +02:00
options = {
services.polybar = {
enable = mkEnableOption "Polybar status bar";
package = mkOption {
type = types.package;
default = pkgs.polybar;
defaultText = literalExample "pkgs.polybar";
2017-10-05 15:55:37 +02:00
description = "Polybar package to install.";
2020-02-02 00:39:17 +01:00
example = literalExample ''
2017-10-05 15:55:37 +02:00
pkgs.polybar.override {
i3GapsSupport = true;
alsaSupport = true;
iwSupport = true;
githubSupport = true;
}
'';
};
config = mkOption {
2020-02-02 00:39:17 +01:00
type = types.coercedTo types.path
2017-10-05 15:55:37 +02:00
(p: { "section/base" = { include-file = "${p}"; }; })
2018-12-05 11:54:52 +01:00
(types.attrsOf (types.attrsOf eitherStrBoolIntList));
2017-10-05 15:55:37 +02:00
description = ''
2018-10-02 08:17:34 +02:00
Polybar configuration. Can be either path to a file, or set of attributes
2017-10-05 15:55:37 +02:00
that will be used to create the final configuration.
'';
2020-02-02 00:39:17 +01:00
default = { };
2017-10-05 15:55:37 +02:00
example = literalExample ''
{
"bar/top" = {
monitor = "\''${env:MONITOR:eDP1}";
width = "100%";
height = "3%";
radius = 0;
modules-center = "date";
};
"module/date" = {
type = "internal/date";
internal = 5;
date = "%d.%m.%y";
time = "%H:%M";
label = "%time% %date%";
};
}
'';
};
extraConfig = mkOption {
type = types.lines;
description = "Additional configuration to add.";
default = "";
example = ''
[module/date]
type = internal/date
interval = 5
date = "%d.%m.%y"
time = %H:%M
format-prefix-foreground = \''${colors.foreground-alt}
label = %time% %date%
'';
};
script = mkOption {
type = types.lines;
description = ''
This script will be used to start the polybars.
Set all necessary environment variables here and start all bars.
It can be assumed that <command>polybar</command> executable is in the <envar>PATH</envar>.
Note, this script must start all bars in the background and then terminate.
'';
example = "polybar bar &";
};
};
};
config = mkIf cfg.enable {
home.packages = [ cfg.package ];
xdg.configFile."polybar/config".source = configFile;
2017-10-05 15:55:37 +02:00
systemd.user.services.polybar = {
Unit = {
Description = "Polybar status bar";
After = [ "graphical-session-pre.target" ];
PartOf = [ "graphical-session.target" ];
2020-02-02 00:39:17 +01:00
X-Restart-Triggers =
[ "${config.xdg.configFile."polybar/config".source}" ];
2017-10-05 15:55:37 +02:00
};
Service = {
Type = "forking";
Environment = "PATH=${cfg.package}/bin:/run/wrappers/bin";
2019-03-21 00:39:36 +01:00
ExecStart =
2020-02-02 00:39:17 +01:00
let scriptPkg = pkgs.writeShellScriptBin "polybar-start" cfg.script;
in "${scriptPkg}/bin/polybar-start";
2019-09-03 23:51:23 +02:00
Restart = "on-failure";
2017-10-05 15:55:37 +02:00
};
2020-02-02 00:39:17 +01:00
Install = { WantedBy = [ "graphical-session.target" ]; };
2017-10-05 15:55:37 +02:00
};
};
}