1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 19:49:45 +01:00
home-manager/modules/services/dunst.nix

163 lines
4.1 KiB
Nix
Raw Normal View History

2017-01-07 19:16:26 +01:00
{ config, lib, pkgs, ... }:
with lib;
2017-10-09 11:20:12 +02:00
let
cfg = config.services.dunst;
2018-12-05 11:53:17 +01:00
2020-02-02 00:39:17 +01:00
eitherStrBoolIntList = with types;
either str (either bool (either int (listOf str)));
2018-12-05 11:53:17 +01:00
2017-10-09 11:20:12 +02:00
toDunstIni = generators.toINI {
mkKeyValue = key: value:
2020-02-02 00:39:17 +01:00
let
value' = if isBool value then
(if value then "yes" else "no")
else if isString value then
''"${value}"''
else
toString value;
in "${key}=${value'}";
2017-10-09 11:20:12 +02:00
};
themeType = types.submodule {
options = {
package = mkOption {
type = types.package;
example = literalExample "pkgs.gnome3.adwaita-icon-theme";
description = "Package providing the theme.";
};
name = mkOption {
type = types.str;
example = "Adwaita";
description = "The name of the theme within the package.";
};
size = mkOption {
type = types.str;
default = "32x32";
example = "16x16";
description = "The desired icon size.";
};
};
};
hicolorTheme = {
2020-06-06 14:52:22 +02:00
package = pkgs.hicolor-icon-theme;
name = "hicolor";
size = "32x32";
};
2020-02-02 00:39:17 +01:00
in {
meta.maintainers = [ maintainers.rycee ];
2017-01-07 19:16:26 +01:00
options = {
services.dunst = {
enable = mkEnableOption "the dunst notification daemon";
iconTheme = mkOption {
type = themeType;
default = hicolorTheme;
description = "Set the icon theme.";
};
2017-01-07 19:16:26 +01:00
settings = mkOption {
2018-12-05 11:53:17 +01:00
type = with types; attrsOf (attrsOf eitherStrBoolIntList);
2020-02-02 00:39:17 +01:00
default = { };
2017-01-07 19:16:26 +01:00
description = "Configuration written to ~/.config/dunstrc";
2017-10-09 11:20:12 +02:00
example = literalExample ''
{
global = {
geometry = "300x5-30+50";
transparency = 10;
frame_color = "#eceff1";
font = "Droid Sans 9";
};
urgency_normal = {
background = "#37474f";
foreground = "#eceff1";
timeout = 10;
};
};
'';
2017-01-07 19:16:26 +01:00
};
};
};
2020-02-02 00:39:17 +01:00
config = mkIf cfg.enable (mkMerge [
{
2020-03-22 21:08:45 +01:00
home.packages = [ (getOutput "man" pkgs.dunst) ];
2020-02-02 00:39:17 +01:00
xdg.dataFile."dbus-1/services/org.knopwob.dunst.service".source =
"${pkgs.dunst}/share/dbus-1/services/org.knopwob.dunst.service";
services.dunst.settings.global.icon_path = let
useCustomTheme = cfg.iconTheme.package != hicolorTheme.package
|| cfg.iconTheme.name != hicolorTheme.name || cfg.iconTheme.size
!= hicolorTheme.size;
basePaths = [
"/run/current-system/sw"
config.home.profileDirectory
cfg.iconTheme.package
] ++ optional useCustomTheme hicolorTheme.package;
themes = [ cfg.iconTheme ] ++ optional useCustomTheme
(hicolorTheme // { size = cfg.iconTheme.size; });
categories = [
"actions"
"animations"
"apps"
"categories"
"devices"
"emblems"
"emotes"
"filesystem"
"intl"
2020-12-18 19:41:39 +01:00
"legacy"
2020-02-02 00:39:17 +01:00
"mimetypes"
"places"
"status"
"stock"
];
in concatStringsSep ":" (concatMap (theme:
concatMap (basePath:
map (category:
"${basePath}/share/icons/${theme.name}/${theme.size}/${category}")
categories) basePaths) themes);
systemd.user.services.dunst = {
Unit = {
Description = "Dunst notification daemon";
After = [ "graphical-session-pre.target" ];
PartOf = [ "graphical-session.target" ];
2017-10-09 11:20:12 +02:00
};
2020-02-02 00:39:17 +01:00
Service = {
Type = "dbus";
BusName = "org.freedesktop.Notifications";
ExecStart = "${pkgs.dunst}/bin/dunst";
};
2020-02-02 00:39:17 +01:00
};
}
(mkIf (cfg.settings != { }) {
xdg.configFile."dunst/dunstrc" = {
text = toDunstIni cfg.settings;
onChange = ''
pkillVerbose=""
if [[ -v VERBOSE ]]; then
pkillVerbose="-e"
fi
$DRY_RUN_CMD ${pkgs.procps}/bin/pkill -u $USER $pkillVerbose dunst || true
unset pkillVerbose
'';
};
})
]);
2017-01-07 19:16:26 +01:00
}