wayland-startup-sound.nix
· 3.2 KiB · Nix
Raw
{ config, lib, pkgs, ... }:
# ''${lib.getExe' pkgs.pipewire "pw-cat"} --media-role Notification -p "${pkgs.kdePackages.oxygen-sounds}/share/sounds/oxygen/stereo/desktop-login-long.ogg" &''
let
cfgPath = [ "wayland" "startupSound" ];
cfg = lib.getAttrFromPath cfgPath config;
in
{
options = lib.setAttrByPath cfgPath {
enable = lib.mkEnableOption "wayland session startup sound";
sound = lib.mkOption {
type = lib.types.path;
default = /${pkgs.kdePackages.oxygen-sounds}/share/sounds/Oxygen-Sys-Log-In-Long.ogg;
defaultText = lib.literalExpression "/\${pkgs.kdePackages.oxygen-sounds}/share/sounds/Oxygen-Sys-Log-In-Long.ogg";
example = lib.literalExpression "/\${pkgs.mint-artwork}/share/sounds/linuxmint-login.wav";
description = "Path to sound to play on wayland session login.";
};
audioBackend = lib.mkOption {
type = lib.types.enum [ "ffmpeg" "pipewire" "pulseaudio" ];
default = "ffmpeg";
example = "pipewire";
description = ''
Audio backend to use to play startup audio sound.
`ffmpeg` - use ffplay
`pipewire` - use pw-cat (note that only this backend supports media roles
`pulseaudio - use pacat
'';
};
pipewireMediaRole = lib.mkOption {
type = lib.types.string;
default = "Notification";
example = "Music";
description = "Media role to use with pw-cat, check https://docs.pipewire.org/page_man_pipewire-props_7.html#node-prop__media_role for available roles.";
};
volume = lib.mkOption {
type = lib.types.float;
default = 1.00;
example = 0.70;
description = "Volume of startup sound, 0.00 - 0%, 0.56 - 56%, 1.00 - 100%.";
};
};
config = lib.mkIf cfg.enable {
systemd.user.services.wayland-startup-sound = {
Unit = {
Description = "Wayland startup sound";
WantedBy = [ config.wayland.systemd.target ];
After = [ config.wayland.systemd.target ] ++
(lib.optional (cfg.audioBackend == "pipewire") "wireplumber.service") ++
(lib.optional (cfg.audioBackend == "pulseaudio") "pulseaudio.service");
Requires =
(lib.optional (cfg.audioBackend == "pipewire") "wireplumber.service") ++
(lib.optional (cfg.audioBackend == "pulseaudio") "pulseaudio.service");
};
Service = {
Type = "oneshot";
Restart = "no";
ExecStart =
if cfg.audioBackend == "ffmpeg" then
"${lib.getExe' pkgs.ffmpeg "ffplay"} -autoexit -volume ${lib.toString (builtins.ceil (cfg.volume * 100))} ${lib.escapeShellArg (lib.toString cfg.sound)}"
else if cfg.audioBackend == "pipewire" then
"${lib.getExe' pkgs.pipewire "pw-cat"} --media-role '${cfg.pipewireMediaRole}' --volume ${toString cfg.volume} -p ${lib.escapeShellArg (lib.toString cfg.sound)}"
else if cfg.audioBackend == "pulseaudio" then
"${lib.getExe' pkgs.pulseaudio "pacat"} --volume=${lib.toString (builtins.ceil (cfg.volume * 65536))} --client-name=wayland-session-startup-sound --stream-name=wayland-session-startup-sound ${lib.escapeShellArg (lib.toString cfg.sound)}"
else throw "Not supported value ${cfg.audiobackend} in ${lib.concatStringsSep "." cfgPath} module.";
};
};
};
}
| 1 | { config, lib, pkgs, ... }: |
| 2 | # ''${lib.getExe' pkgs.pipewire "pw-cat"} --media-role Notification -p "${pkgs.kdePackages.oxygen-sounds}/share/sounds/oxygen/stereo/desktop-login-long.ogg" &'' |
| 3 | let |
| 4 | cfgPath = [ "wayland" "startupSound" ]; |
| 5 | |
| 6 | cfg = lib.getAttrFromPath cfgPath config; |
| 7 | in |
| 8 | { |
| 9 | options = lib.setAttrByPath cfgPath { |
| 10 | enable = lib.mkEnableOption "wayland session startup sound"; |
| 11 | sound = lib.mkOption { |
| 12 | type = lib.types.path; |
| 13 | |
| 14 | default = /${pkgs.kdePackages.oxygen-sounds}/share/sounds/Oxygen-Sys-Log-In-Long.ogg; |
| 15 | |
| 16 | defaultText = lib.literalExpression "/\${pkgs.kdePackages.oxygen-sounds}/share/sounds/Oxygen-Sys-Log-In-Long.ogg"; |
| 17 | example = lib.literalExpression "/\${pkgs.mint-artwork}/share/sounds/linuxmint-login.wav"; |
| 18 | |
| 19 | description = "Path to sound to play on wayland session login."; |
| 20 | }; |
| 21 | |
| 22 | audioBackend = lib.mkOption { |
| 23 | type = lib.types.enum [ "ffmpeg" "pipewire" "pulseaudio" ]; |
| 24 | |
| 25 | default = "ffmpeg"; |
| 26 | example = "pipewire"; |
| 27 | |
| 28 | description = '' |
| 29 | Audio backend to use to play startup audio sound. |
| 30 | |
| 31 | `ffmpeg` - use ffplay |
| 32 | `pipewire` - use pw-cat (note that only this backend supports media roles |
| 33 | `pulseaudio - use pacat |
| 34 | ''; |
| 35 | }; |
| 36 | |
| 37 | pipewireMediaRole = lib.mkOption { |
| 38 | type = lib.types.string; |
| 39 | |
| 40 | default = "Notification"; |
| 41 | example = "Music"; |
| 42 | |
| 43 | description = "Media role to use with pw-cat, check https://docs.pipewire.org/page_man_pipewire-props_7.html#node-prop__media_role for available roles."; |
| 44 | }; |
| 45 | |
| 46 | volume = lib.mkOption { |
| 47 | type = lib.types.float; |
| 48 | |
| 49 | default = 1.00; |
| 50 | example = 0.70; |
| 51 | |
| 52 | description = "Volume of startup sound, 0.00 - 0%, 0.56 - 56%, 1.00 - 100%."; |
| 53 | }; |
| 54 | }; |
| 55 | |
| 56 | config = lib.mkIf cfg.enable { |
| 57 | systemd.user.services.wayland-startup-sound = { |
| 58 | Unit = { |
| 59 | Description = "Wayland startup sound"; |
| 60 | WantedBy = [ config.wayland.systemd.target ]; |
| 61 | After = [ config.wayland.systemd.target ] ++ |
| 62 | (lib.optional (cfg.audioBackend == "pipewire") "wireplumber.service") ++ |
| 63 | (lib.optional (cfg.audioBackend == "pulseaudio") "pulseaudio.service"); |
| 64 | Requires = |
| 65 | (lib.optional (cfg.audioBackend == "pipewire") "wireplumber.service") ++ |
| 66 | (lib.optional (cfg.audioBackend == "pulseaudio") "pulseaudio.service"); |
| 67 | }; |
| 68 | |
| 69 | Service = { |
| 70 | Type = "oneshot"; |
| 71 | Restart = "no"; |
| 72 | ExecStart = |
| 73 | if cfg.audioBackend == "ffmpeg" then |
| 74 | "${lib.getExe' pkgs.ffmpeg "ffplay"} -autoexit -volume ${lib.toString (builtins.ceil (cfg.volume * 100))} ${lib.escapeShellArg (lib.toString cfg.sound)}" |
| 75 | else if cfg.audioBackend == "pipewire" then |
| 76 | "${lib.getExe' pkgs.pipewire "pw-cat"} --media-role '${cfg.pipewireMediaRole}' --volume ${toString cfg.volume} -p ${lib.escapeShellArg (lib.toString cfg.sound)}" |
| 77 | else if cfg.audioBackend == "pulseaudio" then |
| 78 | "${lib.getExe' pkgs.pulseaudio "pacat"} --volume=${lib.toString (builtins.ceil (cfg.volume * 65536))} --client-name=wayland-session-startup-sound --stream-name=wayland-session-startup-sound ${lib.escapeShellArg (lib.toString cfg.sound)}" |
| 79 | else throw "Not supported value ${cfg.audiobackend} in ${lib.concatStringsSep "." cfgPath} module."; |
| 80 | }; |
| 81 | }; |
| 82 | }; |
| 83 | } |
| 84 |