diff --git a/modules/misc/news.nix b/modules/misc/news.nix index f8617f54a..b13a9d33d 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1549,6 +1549,18 @@ in { your physical disc (HDD/SSD). ''; } + + { + time = "2024-04-29T22:01:51+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.swaync'. + + SwayNotificationCenter is a simple notification daemon with a GTK GUI + for notifications and the control center. See + https://github.com/ErikReider/SwayNotificationCenter for more. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index b1e8b9b42..d526c3525 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -355,6 +355,7 @@ let ./services/stalonetray.nix ./services/status-notifier-watcher.nix ./services/swayidle.nix + ./services/swaync.nix ./services/swayosd.nix ./services/sxhkd.nix ./services/syncthing.nix diff --git a/modules/services/swaync.nix b/modules/services/swaync.nix new file mode 100644 index 000000000..bb1f9d57c --- /dev/null +++ b/modules/services/swaync.nix @@ -0,0 +1,113 @@ +{ pkgs, lib, config, ... }: + +let + + cfg = config.services.swaync; + + jsonFormat = pkgs.formats.json { }; + +in { + meta.maintainers = [ lib.hm.maintainers.abayomi185 ]; + + options.services.swaync = { + enable = lib.mkEnableOption "Swaync notification daemon"; + + package = lib.mkPackageOption pkgs "swaynotificationcenter" { }; + + style = lib.mkOption { + type = lib.types.nullOr (lib.types.either lib.types.path lib.types.lines); + default = null; + example = '' + .notification-row { + outline: none; + } + + .notification-row:focus, + .notification-row:hover { + background: @noti-bg-focus; + } + + .notification { + border-radius: 12px; + margin: 6px 12px; + box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.7), + 0 2px 6px 2px rgba(0, 0, 0, 0.3); + padding: 0; + } + ''; + description = '' + CSS style of the bar. See + + for the documentation. + + If the value is set to a path literal, then the path will be used as the CSS file. + ''; + }; + + settings = lib.mkOption { + type = jsonFormat.type; + default = { }; + example = lib.literalExpression '' + { + positionX = "right"; + positionY = "top"; + layer = "overlay"; + control-center-layer = "top"; + layer-shell = true; + cssPriority = "application"; + control-center-margin-top = 0; + control-center-margin-bottom = 0; + control-center-margin-right = 0; + control-center-margin-left = 0; + notification-2fa-action = true; + notification-inline-replies = false; + notification-icon-size = 64; + notification-body-image-height = 100; + notification-body-image-width = 200 + }; + ''; + description = '' + Configuration written to {file}`$XDG_CONFIG_HOME/swaync/config.json`. + See + + for the documentation. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + # at-spi2-core is to minimize journalctl noise of: + # "AT-SPI: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files" + home.packages = [ cfg.package pkgs.at-spi2-core ]; + + xdg.configFile = { + "swaync/config.json".source = + jsonFormat.generate "config.json" cfg.settings; + "swaync/style.css" = lib.mkIf (cfg.style != null) { + source = if lib.isStorePath cfg.style then + cfg.style + else + pkgs.writeText "swaync/style.css" cfg.style; + }; + }; + + systemd.user.services.swaync = { + Unit = { + Description = "Swaync notification daemon"; + Documentation = "https://github.com/ErikReider/SwayNotificationCenter"; + PartOf = [ "graphical-session.target" ]; + After = [ "graphical-session-pre.target" ]; + ConditionEnvironment = "WAYLAND_DISPLAY"; + }; + + Service = { + Type = "dbus"; + BusName = "org.freedesktop.Notifications"; + ExecStart = "${cfg.package}/bin/swaync"; + Restart = "on-failure"; + }; + + Install.WantedBy = [ "graphical-session.target" ]; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 4b7b6ebf6..15a54f08b 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -260,6 +260,7 @@ in import nmtSrc { ./modules/services/screen-locker ./modules/services/signaturepdf ./modules/services/swayidle + ./modules/services/swaync ./modules/services/swayosd ./modules/services/sxhkd ./modules/services/syncthing/linux diff --git a/tests/modules/services/swaync/default.nix b/tests/modules/services/swaync/default.nix new file mode 100644 index 000000000..d5682daa3 --- /dev/null +++ b/tests/modules/services/swaync/default.nix @@ -0,0 +1 @@ +{ swaync = ./swaync.nix; } diff --git a/tests/modules/services/swaync/swaync.nix b/tests/modules/services/swaync/swaync.nix new file mode 100644 index 000000000..ceb3bf065 --- /dev/null +++ b/tests/modules/services/swaync/swaync.nix @@ -0,0 +1,35 @@ +{ config, ... }: + +{ + services.swaync = { + enable = true; + package = config.lib.test.mkStubPackage { + name = "swaync"; + outPath = "@swaync@"; + }; + }; + + nmt.script = '' + assertFileContent \ + home-files/.config/systemd/user/swaync.service \ + ${ + builtins.toFile "swaync.service" '' + [Install] + WantedBy=graphical-session.target + + [Service] + BusName=org.freedesktop.Notifications + ExecStart=@swaync@/bin/swaync + Restart=on-failure + Type=dbus + + [Unit] + After=graphical-session-pre.target + ConditionEnvironment=WAYLAND_DISPLAY + Description=Swaync notification daemon + Documentation=https://github.com/ErikReider/SwayNotificationCenter + PartOf=graphical-session.target + '' + } + ''; +}