home-manager/gui: Add spotifyd, swaync

This commit is contained in:
Jack O'Sullivan 2023-02-12 15:20:19 +00:00
parent b423afb2bb
commit ccdbf0d506
5 changed files with 161 additions and 9 deletions

View File

@ -3,5 +3,6 @@
common = ./common.nix;
gui = ./gui;
deploy-rs = ./deploy-rs.nix;
swaync = ./swaync.nix;
};
}

View File

@ -113,7 +113,10 @@ in
packages = with pkgs; [
wtype
wl-clipboard
wev
pavucontrol
libsecret
playerctl
];
pointerCursor = {
@ -149,8 +152,6 @@ in
let
cfg = config.wayland.windowManager.sway.config;
mod = cfg.modifier;
mkSpotifyCmd = cmd: "exec ${pkgs.dbus}/bin/dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.${cmd}";
in
lib.mkOptionDefault {
"${mod}+d" = null;
@ -164,9 +165,10 @@ in
"XF86AudioRaiseVolume" = "exec ${pkgs.pamixer}/bin/pamixer -i 5";
"XF86AudioLowerVolume" = "exec ${pkgs.pamixer}/bin/pamixer -d 5";
"XF86AudioPlay" = mkSpotifyCmd "PlayPause";
"XF86AudioNext" = mkSpotifyCmd "Next";
"XF86AudioPrev" = mkSpotifyCmd "Prev";
"XF86AudioPlay" = "exec ${pkgs.playerctl}/bin/playerctl play-pause";
"XF86AudioPause" = "exec ${pkgs.playerctl}/bin/playerctl play-pause";
"XF86AudioNext" = "exec ${pkgs.playerctl}/bin/playerctl next";
"XF86AudioPrev" = "exec ${pkgs.playerctl}/bin/playerctl previous";
};
menu = "rofi -show run";
@ -197,6 +199,13 @@ in
};
services = {
swaync = {
enable = true;
settings = {
widgets = [ "title" "dnd" "mpris" "notifications" ];
};
};
flameshot = {
enable = true;
settings = {
@ -207,6 +216,23 @@ in
};
};
};
playerctld.enable = true;
spotifyd = {
enable = true;
package = pkgs.spotifyd.override {
withMpris = true;
withKeyring = true;
};
settings.global = {
username = "devplayer0";
use_keyring = true;
use_mpris = true;
backend = "pulseaudio";
bitrate = 320;
device_type = "computer";
};
};
};
programs = {

View File

@ -17,7 +17,7 @@ in
modules-center = [ "sway/window" ];
modules-right = [
"idle_inhibitor" "pulseaudio" "network" "cpu" "memory" "temperature" "backlight"
"keyboard-state" "sway/language" "battery" "clock" "tray"
"keyboard-state" "sway/language" "battery" "clock" "tray" "custom/notification"
];
# Modules configuration
# "sway/workspaces": {
@ -112,8 +112,8 @@ in
format-source-muted = "";
format-icons = {
headphone = "";
hands-free = "";
headset = "";
hands-free = "";
headset = "";
phone = "";
portable = "";
car = "";
@ -122,17 +122,33 @@ in
on-click = "${pkgs.pavucontrol}/bin/pavucontrol";
};
"custom/media" = {
# TODO: waybar has a built-in MPRIS module now
format = "{icon} {}";
return-type = "json";
max-length = 40;
format-icons = {
spotify = "";
default = "🎜";
default = "";
};
escape = true;
exec = ''${pkg}/bin/waybar-mediaplayer.py 2> /dev/null'';
# "exec": "$HOME/.config/waybar/mediaplayer.py --player spotify 2> /dev/null" // Filter player based on name
};
"custom/notification" = {
tooltip = false;
format = "{icon}";
format-icons = {
notification = "<span foreground='red'><sup></sup></span>";
none = "";
dnd-notification = "<span foreground='red'><sup></sup></span>";
dnd-none = "";
};
return-type = "json";
exec = "${config.services.swaync.package}/bin/swaync-client -swb";
on-click = "${config.services.swaync.package}/bin/swaync-client -t -sw";
on-click-right = "${config.services.swaync.package}/bin/swaync-client -d -sw";
escape = true;
};
};
};
style = ''

View File

@ -0,0 +1,103 @@
{ lib, pkgs, config, ... }:
let
inherit (builtins) isPath;
inherit (lib) mkIf isStorePath;
inherit (lib.options) mkOption mkEnableOption;
jsonFormat = pkgs.formats.json { };
swayncConfig = with lib.types; submodule {
freeformType = jsonFormat.type;
options = {
"$schema" = mkOption {
type = str;
default = "${cfg.package}/etc/xdg/configSchema.json";
description = ''
Path to schema for config.
'';
};
};
};
cfg = config.services.swaync;
in
{
options.services.swaync = with lib.types; {
enable = mkEnableOption "Sway Notification Center";
package = mkOption {
type = package;
default = pkgs.swaynotificationcenter;
defaultText = literalExpression "pkgs.swaynotificationcenter";
description = ''
swaync package to use. Set to <code>null</code> to use the default package.
'';
};
settings = mkOption {
type = swayncConfig;
default = { };
description = ''
Configuration for Sway Notification Center, see swaync(1) for details.
'';
};
style = mkOption {
type = nullOr (either path str);
default = null;
description = ''
CSS styling for Sway Notification Center. If set to a path literal, this will be used
instead of writing the string to a file.
'';
};
};
config =
let
configSource = jsonFormat.generate "swaync.json" cfg.settings;
styleSource = if isPath cfg.style || isStorePath cfg.style then
cfg.style
else
pkgs.writeText "swaync.css" cfg.style;
in
mkIf cfg.enable {
home.packages = [ cfg.package ];
xdg = {
# swaync _really_ wants to pull the CSS from the system config dir
systemDirs.config = [ "${cfg.package}/etc/xdg" ];
configFile = {
"swaync/config.json" = mkIf (cfg.settings != { }) {
source = configSource;
onChange = ''
${cfg.package}/bin/swaync-client --reload-config
'';
};
"swaync/style.css" = mkIf (cfg.style != null) {
source = styleSource;
onChange = ''
${cfg.package}/bin/swaync-client --reload-css
'';
};
};
};
systemd.user.services.swaync = {
Unit = {
Description = "Swaync notification daemon";
Documentation = "https://github.com/ErikReider/SwayNotificationCenter";
PartOf = [ "graphical-session.target" ];
After = [ "graphical-session.target" ];
};
Service = {
Type = "dbus";
BusName = "org.freedesktop.Notifications";
ExecStart = "${cfg.package}/bin/swaync";
ExecReload = "${cfg.package}/bin/swaync-client --reload-config ; ${cfg.package}/bin/swaync-client --reload-css";
};
Install.WantedBy = [ "graphical-session.target" ];
};
};
}

View File

@ -28,6 +28,12 @@ in
pulse.enable = true;
jack.enable = true;
};
dbus = {
packages = with pkgs; [ gcr ];
};
gnome = {
gnome-keyring.enable = true;
};
};
programs.dconf.enable = true;