added toggleaudiosink pkg
This commit is contained in:
parent
95e23247b0
commit
4b17075968
3 changed files with 140 additions and 106 deletions
|
|
@ -113,6 +113,9 @@
|
|||
};
|
||||
workstationOverlay = final: prev: {
|
||||
plasticity = nixpkgs.legacyPackages."x86_64-linux".callPackage ./packages/plasticity.nix { };
|
||||
toggleaudiosink =
|
||||
nixpkgs.legacyPackages."x86_64-linux".callPackage ./packages/toggleaudiosink.nix
|
||||
{ };
|
||||
};
|
||||
serverOverlay = final: prev: {
|
||||
};
|
||||
|
|
|
|||
|
|
@ -43,23 +43,7 @@
|
|||
})
|
||||
|
||||
# Workstation specific configuration
|
||||
(lib.mkIf hostType.isWorkstation (
|
||||
let
|
||||
kwrite = pkgs.symlinkJoin {
|
||||
name = "kwrite";
|
||||
paths = [ pkgs.kdePackages.kate ];
|
||||
postBuild = ''
|
||||
rm -rf $out/bin/kate \
|
||||
$out/bin/.kate-wrapped \
|
||||
$out/share/applications/org.kde.kate.desktop \
|
||||
$out/share/man \
|
||||
$out/share/icons/hicolor/*/apps/kate.png \
|
||||
$out/share/icons/hicolor/scalable/apps/kate.svg \
|
||||
$out/share/appdata/org.kde.kate.appdata.xml
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
(lib.mkIf hostType.isWorkstation ({
|
||||
environment.systemPackages = with pkgs; [
|
||||
### Dev Tools ###
|
||||
bat
|
||||
|
|
@ -82,7 +66,6 @@
|
|||
aspellDicts.en
|
||||
aspellDicts.en-computers
|
||||
aspellDicts.pt_BR
|
||||
kwrite
|
||||
libreoffice-qt
|
||||
obsidian
|
||||
(octaveFull.withPackages (octavePackages: with octavePackages; [ signal ]))
|
||||
|
|
@ -114,6 +97,7 @@
|
|||
quickgui
|
||||
rustdesk
|
||||
steam-run
|
||||
toggleaudiosink
|
||||
unrar
|
||||
### Media ###
|
||||
mpv
|
||||
|
|
@ -149,7 +133,6 @@
|
|||
roboto
|
||||
];
|
||||
};
|
||||
}
|
||||
))
|
||||
}))
|
||||
];
|
||||
}
|
||||
|
|
|
|||
48
packages/toggleaudiosink.nix
Normal file
48
packages/toggleaudiosink.nix
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
}:
|
||||
|
||||
pkgs.writeShellScriptBin "toggleaudiosink" ''
|
||||
#!/usr/bin/env bash
|
||||
|
||||
sound_server="pipewire"
|
||||
|
||||
# Grab a count of how many audio sinks we have
|
||||
sink_count=$(${pkgs.pulseaudio}/bin/pactl list sinks | grep -c "Sink #[[:digit:]]")
|
||||
# Create an array of the actual sink IDs
|
||||
sinks=()
|
||||
mapfile -t sinks < <(${pkgs.pulseaudio}/bin/pactl list sinks | grep 'Sink #[[:digit:]]' | sed -n -e 's/.*Sink #\([[:digit:]]\)/\1/p')
|
||||
# Get the ID of the active sink
|
||||
active_sink_name=$(${pkgs.pulseaudio}/bin/pactl info | grep 'Default Sink:' | sed -n -e 's/.*Default Sink:[[:space:]]\+\(.*\)/\1/p')
|
||||
active_sink=$(${pkgs.pulseaudio}/bin/pactl list sinks | grep -B 2 "$active_sink_name" | sed -n -e 's/Sink #\([[:digit:]]\)/\1/p' | head -n 1)
|
||||
|
||||
# Get the ID of the last sink in the array
|
||||
final_sink=''${sinks[$((sink_count - 1))]}
|
||||
|
||||
# Find the index of the active sink
|
||||
for index in "''${!sinks[@]}"; do
|
||||
if [[ "''${sinks[$index]}" == "$active_sink" ]]; then
|
||||
active_sink_index=$index
|
||||
fi
|
||||
done
|
||||
|
||||
# Default to the first sink in the list
|
||||
next_sink=''${sinks[0]}
|
||||
next_sink_index=0
|
||||
|
||||
# If we're not at the end of the list, move up the list
|
||||
if [[ $active_sink -ne $final_sink ]]; then
|
||||
next_sink_index=$((active_sink_index + 1))
|
||||
next_sink=''${sinks[$next_sink_index]}
|
||||
fi
|
||||
|
||||
# Change the default sink
|
||||
# Get the name of the next sink
|
||||
next_sink_name=$(${pkgs.pulseaudio}/bin/pactl list sinks | grep -C 2 "Sink #$next_sink" | sed -n -e 's/.*Name:[[:space:]]\+\(.*\)/\1/p' | head -n 1)
|
||||
${pkgs.pulseaudio}/bin/pactl set-default-sink "$next_sink_name"
|
||||
|
||||
# Move all inputs to the new sink
|
||||
for app in $(${pkgs.pulseaudio}/bin/pactl list sink-inputs | sed -n -e 's/.*Sink Input #\([[:digit:]]\)/\1/p'); do
|
||||
${pkgs.pulseaudio}/bin/pactl "move-sink-input $app $next_sink"
|
||||
done
|
||||
''
|
||||
Loading…
Add table
Add a link
Reference in a new issue