From 7d08e1f5efafe839cc89ff4288954acb250fc0d9 Mon Sep 17 00:00:00 2001 From: imxyy_soope_ Date: Sun, 27 Jul 2025 21:30:51 +0800 Subject: [PATCH] feat(audio): move to pipewire --- config/hosts/imxyy-nix-server/nixos.nix | 5 ++-- config/hosts/imxyy-nix-x16/home.nix | 4 +-- config/hosts/imxyy-nix-x16/nixos.nix | 30 ----------------------- config/hosts/imxyy-nix/home.nix | 4 +-- config/hosts/imxyy-nix/nixos.nix | 30 ----------------------- modules/audio.nix | 24 ++++++++++++++++++ modules/bluetooth.nix | 20 +++++++++++++++ modules/cli/media/mpd/mpd.conf | 5 ---- modules/desktop/wm/niri/config.nix | 14 ++++++----- modules/desktop/wm/niri/waybar/config.nix | 26 +++++++++----------- modules/desktop/wm/niri/waybar/style.css | 13 +++------- 11 files changed, 70 insertions(+), 105 deletions(-) create mode 100644 modules/audio.nix create mode 100644 modules/bluetooth.nix diff --git a/config/hosts/imxyy-nix-server/nixos.nix b/config/hosts/imxyy-nix-server/nixos.nix index ba14ba8..710ea78 100644 --- a/config/hosts/imxyy-nix-server/nixos.nix +++ b/config/hosts/imxyy-nix-server/nixos.nix @@ -13,15 +13,14 @@ timeout = 0; }; - hardware.bluetooth.enable = true; - hardware.bluetooth.powerOnBoot = true; - systemd.services.nix-daemon = { environment.TMPDIR = "/var/cache/nix"; serviceConfig.CacheDirectory = "nix"; }; environment.variables.NIX_REMOTE = "daemon"; + my.audio.enable = false; + sops.secrets.imxyy-nix-server-hashed-password = { sopsFile = secrets.imxyy-nix-server-hashed-password; format = "binary"; diff --git a/config/hosts/imxyy-nix-x16/home.nix b/config/hosts/imxyy-nix-x16/home.nix index 07848d2..2a87efb 100644 --- a/config/hosts/imxyy-nix-x16/home.nix +++ b/config/hosts/imxyy-nix-x16/home.nix @@ -29,8 +29,7 @@ wineWowPackages.waylandFull - pavucontrol - pamixer + pwvucontrol ]; programs.zsh = { sessionVariables = { @@ -135,7 +134,6 @@ ".config/Kingsoft" ".config/dconf" ".config/gh" - ".config/pulse" ".config/pip" ".config/libreoffice" ".config/sunshine" diff --git a/config/hosts/imxyy-nix-x16/nixos.nix b/config/hosts/imxyy-nix-x16/nixos.nix index 8ebcea6..5155bcc 100644 --- a/config/hosts/imxyy-nix-x16/nixos.nix +++ b/config/hosts/imxyy-nix-x16/nixos.nix @@ -35,36 +35,6 @@ }; environment.variables.NIX_REMOTE = "daemon"; - security.rtkit.enable = true; - services.pipewire = { - enable = true; - alsa.enable = false; - alsa.support32Bit = false; - pulse.enable = false; - audio.enable = false; - }; - services.pulseaudio = { - enable = true; - support32Bit = true; - package = pkgs.pulseaudioFull; - extraConfig = '' - load-module module-switch-on-connect - unload-module module-suspend-on-idle - ''; - }; - hardware.bluetooth = { - enable = true; - powerOnBoot = true; - settings = { - General = { - Enable = "Source,Sink,Media,Socket"; - Disable = "HeadSet"; - MultiProfile = "multiple"; - }; - }; - }; - users.extraUsers.${username}.extraGroups = [ "audio" ]; - fonts = { enableDefaultPackages = false; fontDir.enable = true; diff --git a/config/hosts/imxyy-nix/home.nix b/config/hosts/imxyy-nix/home.nix index 9a8f7ce..afd710d 100644 --- a/config/hosts/imxyy-nix/home.nix +++ b/config/hosts/imxyy-nix/home.nix @@ -30,8 +30,7 @@ wineWowPackages.waylandFull - pavucontrol - pamixer + pwvucontrol ]; programs.zsh = { shellAliases = { @@ -173,7 +172,6 @@ ".config/Kingsoft" ".config/dconf" ".config/gh" - ".config/pulse" ".config/pip" ".config/libreoffice" ".config/sunshine" diff --git a/config/hosts/imxyy-nix/nixos.nix b/config/hosts/imxyy-nix/nixos.nix index 47cb6e0..719fdb8 100644 --- a/config/hosts/imxyy-nix/nixos.nix +++ b/config/hosts/imxyy-nix/nixos.nix @@ -73,36 +73,6 @@ in }; environment.variables.NIX_REMOTE = "daemon"; - security.rtkit.enable = true; - services.pipewire = { - enable = true; - alsa.enable = false; - alsa.support32Bit = false; - pulse.enable = false; - audio.enable = false; - }; - services.pulseaudio = { - enable = true; - support32Bit = true; - package = pkgs.pulseaudioFull; - extraConfig = '' - load-module module-switch-on-connect - unload-module module-suspend-on-idle - ''; - }; - hardware.bluetooth = { - enable = true; - powerOnBoot = true; - settings = { - General = { - Enable = "Source,Sink,Media,Socket"; - Disable = "HeadSet"; - MultiProfile = "multiple"; - }; - }; - }; - users.extraUsers.${username}.extraGroups = [ "audio" ]; - fonts = { enableDefaultPackages = false; fontDir.enable = true; diff --git a/modules/audio.nix b/modules/audio.nix new file mode 100644 index 0000000..a26655f --- /dev/null +++ b/modules/audio.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + username, + ... +}: +lib.my.makeSwitch { + inherit config; + default = true; + optionName = "default audio settings"; + optionPath = [ "audio" ]; + config' = { + security.rtkit.enable = true; + services.pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + audio.enable = true; + }; + users.extraUsers.${username}.extraGroups = [ "audio" ]; + my.persist.homeDirs = [ ".local/state/wireplumber" ]; + }; +} diff --git a/modules/bluetooth.nix b/modules/bluetooth.nix new file mode 100644 index 0000000..517c664 --- /dev/null +++ b/modules/bluetooth.nix @@ -0,0 +1,20 @@ +{ config, lib, ... }: +lib.my.makeSwitch { + inherit config; + default = true; + optionName = "default bluetooth settings"; + optionPath = [ "bluetooth" ]; + config' = { + hardware.bluetooth = { + enable = true; + powerOnBoot = true; + settings = { + General = { + Enable = "Source,Sink,Media,Socket"; + Disable = "HeadSet"; + MultiProfile = "multiple"; + }; + }; + }; + }; +} diff --git a/modules/cli/media/mpd/mpd.conf b/modules/cli/media/mpd/mpd.conf index 2a81a51..5324c63 100644 --- a/modules/cli/media/mpd/mpd.conf +++ b/modules/cli/media/mpd/mpd.conf @@ -23,8 +23,3 @@ audio_output { type "pipewire" name "pipewire" } - -audio_output { - type "pulse" - name "pulseaudio" -} diff --git a/modules/desktop/wm/niri/config.nix b/modules/desktop/wm/niri/config.nix index f9aa899..d7286ca 100644 --- a/modules/desktop/wm/niri/config.nix +++ b/modules/desktop/wm/niri/config.nix @@ -151,17 +151,19 @@ "XF86AudioRaiseVolume" = { allow-when-locked = true; action.spawn = [ - "pamixer" - "-i" - "2" + "wpctl" + "set-volume" + "@DEFAULT_SINK@" + "2%+" ]; }; "XF86AudioLowerVolume" = { allow-when-locked = true; action.spawn = [ - "pamixer" - "-d" - "2" + "wpctl" + "set-volume" + "@DEFAULT_SINK@" + "2%-" ]; }; "XF86AudioMute" = { diff --git a/modules/desktop/wm/niri/waybar/config.nix b/modules/desktop/wm/niri/waybar/config.nix index 64e5db2..f05e95a 100644 --- a/modules/desktop/wm/niri/waybar/config.nix +++ b/modules/desktop/wm/niri/waybar/config.nix @@ -19,8 +19,8 @@ _: { modules-right = [ "custom/notification" "tray" - "pulseaudio" - "pulseaudio#microphone" + "wireplumber" + "wireplumber#source" ]; "niri/workspaces" = { @@ -73,7 +73,6 @@ _: { stopped = ""; }; tooltip = false; - toottip-format = "{status_icon} Musicfox {artist} - {album} - {title}"; on-scroll-up = "playerctl -p musicfox volume 0.05+"; on-scroll-down = "playerctl -p musicfox volume 0.05-"; }; @@ -81,14 +80,12 @@ _: { format = " {:%H:%M  %m.%d}"; tooltip = false; }; - pulseaudio = { + wireplumber = { format = "{icon} {volume}%"; tooltip = false; format-muted = "󰟎 Muted"; - on-click = "pamixer -t"; - on-click-middle = "pavucontrol & disown"; - on-scroll-up = "pamixer -i 5"; - on-scroll-down = "pamixer -d 5"; + on-click = "wpctl set-mute @DEFAULT_SINK@ toggle"; + on-click-middle = "pwvucontrol"; scroll-step = 5; format-icons = { headphone = "󰋋"; @@ -104,14 +101,13 @@ _: { ]; }; }; - "pulseaudio#microphone" = { - format = "{format_source}"; + "wireplumber#source" = { + node-type = "Audio/Source"; + format = "󰍬 {volume}%"; tooltip = false; - format-source = "󰍬 {volume}%"; - format-source-muted = "󰍭 Muted"; - on-click = "pamixer --default-source -t"; - on-scroll-up = "pamixer --default-source -i 5"; - on-scroll-down = "pamixer --default-source -d 5"; + format-muted = "󰍬 Muted"; + on-click = "wpctl set-mute @DEFAULT_SOURCE@ toggle"; + on-click-middle = "pwvucontrol"; scroll-step = 5; }; } diff --git a/modules/desktop/wm/niri/waybar/style.css b/modules/desktop/wm/niri/waybar/style.css index f9a49be..729589d 100644 --- a/modules/desktop/wm/niri/waybar/style.css +++ b/modules/desktop/wm/niri/waybar/style.css @@ -100,7 +100,7 @@ tooltip * { #window, #clock, #battery, -#pulseaudio, +#wireplumber, #network, #workspaces, #taskbar, @@ -219,13 +219,13 @@ window#waybar.empty #window { border-right: 0; } -#pulseaudio { +#wireplumber { color: #89b4fa; border-right: 0px; border-radius: 10px 0px 0px 10px; } -#pulseaudio.microphone { +#wireplumber.source { color: #cba6f7; margin-right: 5px; border-left: 0px; @@ -238,10 +238,3 @@ window#waybar.empty #window { margin-right: 10px; border-left: 0px; } - -#custom-weather { - border-radius: 0px 10px 10px 0px; - border-left: 0; - border-right: 0; - margin-left: 0px; -}