Last active 1760316128

Revision ae3b4a7f41738043973744222ea89b4fe5fb895b

wayland-startup-sound.nix Raw
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" &''
3let
4 cfgPath = [ "wayland" "startupSound" ];
5
6 cfg = lib.getAttrFromPath cfgPath config;
7in
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