This commit is contained in:
Erwin Boskma 2021-11-16 00:22:18 +01:00
parent be2e1e5aa3
commit d76c245b5e
Signed by: erwin
GPG key ID: B4F4B090E4BD95A9
17 changed files with 139 additions and 96 deletions

View file

@ -13,7 +13,7 @@ in
config = mkIf (cfg.enable) {
programs.rofi = {
enable = true;
package = myPkgs.rofi-wayland;
package = pkgs.rofi-wayland;
};
};
}

View file

@ -42,32 +42,8 @@
];
};
# nixosUsers = [{
# name = "erwin";
# groups = [ "wheel" "networkmanager" "video" ];
# uid = 1000;
# shell = pkgs.fish;
# openssh.authorizedKeys.keys = [
# "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMNoTcRsAxDwpiIj6nhUXwzSQjtcgKCR0RDlzP57wi0W erwin@horusvr-ws2"
# ];
# }];
in
{
# homeManagerConfigurations = {
# erwin = user.mkHMUser {
# userConfig = {
# git.enable = true;
# ssh.enable = true;
# applications.enable = true;
# gpg.enable = true;
# fish.enable = true;
# sway.enable = true;
# };
# username = "erwin";
# };
# };
overlay = final: prev: (import ./overlays) final prev;
# overlay = final: prev: {
# unstable = import nixpkgs {
@ -84,33 +60,6 @@
(builtins.attrNames (builtins.readDir ./modules)));
nixosConfigurations = {
# vm1 = host.mkHost {
# name = "vm1";
# NICs = [ "enp1s0" ];
# kernelPackage = pkgs.linuxPackages;
# initrdMods = [ "ahci" "xhci_pci" "sr_mod" ];
# kernelMods = [ "kvm-amd" ];
# kernelParams = [ ];
# systemConfig = vm1UefiConfig;
# users = nixosUsers;
# cpuCores = 6;
# };
# vm2 = host.mkHost {
# name = "vm2";
# NICs = [ "enp1s0" ];
# kernelPackage = pkgs.linuxPackages;
# initrdMods = [ "ahci" "xhci_pci" "sr_mod" ];
# kernelMods = [ "kvm-amd" ];
# kernelParams = [ ];
# systemConfig = vm2Config;
# users = nixosUsers;
# cpuCores = 4;
# };
vm1 = defSystem "x86_64-linux" {
imports = [
(import (./machines/vm1/configuration.nix) { inherit self; })
@ -130,7 +79,7 @@
};
} //
(flake-utils.lib.eachSystem [ "x86_64-linux" ])
(flake-utils.lib.eachSystem [ "aarch64-linux" "x86_64-linux" ])
(system:
let
pkgs = import nixpkgs {

View file

@ -10,6 +10,7 @@ in
programs.rofi = {
enable = true;
package = pkgs.rofi-wayland;
theme = ./launch.rasi;
};
};

1
krops.nix Normal file
View file

@ -0,0 +1 @@
{ }

View file

@ -17,7 +17,7 @@
networking = {
hostName = "vm2";
useDHCP = false;
interfaces.enp1s.useDHCP = true;
interfaces.enp1s0.useDHCP = true;
};
# nix = {

View file

@ -7,6 +7,9 @@
enable = true;
home-manager = true;
};
nix-common = {
enable = true;
};
};
boot.loader.systemd-boot.enable = true;
@ -17,7 +20,7 @@
networking = {
hostName = "vm2";
useDHCP = false;
interfaces.enp1s.useDHCP = true;
interfaces.enp1s0.useDHCP = true;
};
# nix = {

View file

@ -41,13 +41,23 @@ in
home.packages = with pkgs; [
(nerdfonts.override { fonts = [ "CascadiaCode" "FantasqueSansMono" "FiraCode" "Iosevka" "JetBrainsMono" "Meslo" "Noto" "SourceCodePro" ]; })
(callPackage ../../pkgs/pamedia { })
];
imports = [
{
nixpkgs.overlays = [ self-overlay ];
}
../../home-manager/modules/sway
../../home-manager/modules/waybar
../../home-manager/modules/rofi
];
};
services.pipewire = {
enable = true;
pulse.enable = true;
media-session.enable = true;
};
};
}

View file

@ -0,0 +1,33 @@
{ lib, pkgs, config, ... }:
with lib;
let cfg = config.eboskma.nix-common;
in
{
options.eboskma.nix-common = {
enable = mkEnableOption "activate nix-common";
disable-cache = mkEnableOption "no not use binary cache";
};
config = mkIf cfg.enable {
nixpkgs = {
config.allowUnfree = true;
};
nix = {
package = pkgs.nixFlakes;
extraOptions = ''
experimental-features = nix-command flakes ca-references
'';
autoOptimiseStore = true;
gc = {
automatic = true;
dates = "weekly";
options = "--delete-older-than=30d";
};
allowedUsers = [ "root" ];
};
};
}

View file

@ -1,4 +1,11 @@
self: super: {
rofi = super.pkgs.callPackage ../pkgs/rofi-wayland { };
pamedia = super.pkgs.callPackage ../pkgs/pamedia { };
final: prev: {
rofi-wayland = prev.pkgs.callPackage ../pkgs/rofi-wayland { };
pamedia = prev.pkgs.callPackage ../pkgs/pamedia {
buildPythonPackage = prev.pkgs.python3.pkgs.buildPythonPackage;
pulsectl = prev.pkgs.python39Packages.pulsectl;
pygobject3 = prev.pkgs.python39Packages.pygobject3;
gobject-introspection = prev.pkgs.gobject-introspection;
libnotify = prev.pkgs.libnotify;
lib = prev.pkgs.lib;
};
}

View file

@ -1,4 +1,10 @@
{ buildPythonPackage, lib, pulsectl }:
{ pkgs, ... }:
with pkgs;
let
buildPythonPackage = python3.pkgs.buildPythonPackage;
pulsectl = python3.pkgs.pulsectl;
pygobject3 = python3.pkgs.pygobject3;
in
buildPythonPackage rec {
pname = "pamedia";
version = "0.1.0";
@ -7,13 +13,11 @@ buildPythonPackage rec {
propagatedBuildInputs = [
pulsectl
pygobject3
gobject-introspection
libnotify
];
installPhase = ''
install -d $out/bin
install -m 0755 $src/pamedia $out/bin/pamedia
'';
meta = {
description = "Change volume of the PulseAudio default sink";
license = lib.licenses.mit;

View file

@ -4,7 +4,7 @@ import argparse
import pulsectl
import gi
gi.require_version('Notify', '0.7')
gi.require_version("Notify", "0.7")
from gi.repository import GLib
from gi.repository import Notify
@ -12,19 +12,22 @@ from gi.repository import Notify
class PAMedia:
def __init__(self, sink=None):
self.client = pulsectl.Pulse('volumectl')
self.client = pulsectl.Pulse("volumectl")
sinks = self.client.sink_list()
if sink == None:
self.sink = self.client.get_sink_by_name(
self.client.server_info().default_sink_name)
self.client.server_info().default_sink_name
)
else:
if sink > len(sinks):
notification = Notify.Notification.new(
'Volume', f'Unknown sink index \'{sink}\', using default sink')
"Volume", f"Unknown sink index '{sink}', using default sink"
)
notification.show()
self.sink = self.client.get_sink_by_name(
self.client.server_info().default_sink_name)
self.client.server_info().default_sink_name
)
self.sink = sinks[sink]
@ -45,31 +48,31 @@ class PAMedia:
def list_sinks(self):
for num, sink in enumerate(self.client.sink_list()):
print(f'[{num}] {sink.description}')
print(f"[{num}] {sink.description}")
def icon(self):
if self.sink.mute:
return 'muted'
return "muted"
elif self.sink.volume.value_flat <= 0.3:
return 'low'
return "low"
elif self.sink.volume.value_flat <= 0.7:
return 'medium'
return "medium"
else:
return 'high'
return "high"
def notify(self):
icon = f'audio-volume-{self.icon()}'
title = f'Volume'
icon = f"audio-volume-{self.icon()}"
title = f"Volume"
if self.sink.mute:
title = 'Muted'
title = "Muted"
notification = Notify.Notification.new(title, '', icon)
notification = Notify.Notification.new(title, "", icon)
if not self.sink.mute:
notification.set_hint(
'x-canonical-private-synchronous', GLib.Variant.new_string('audio'))
notification.set_hint(
'value', GLib.Variant.new_int32(round(self.volume())))
"x-canonical-private-synchronous", GLib.Variant.new_string("audio")
)
notification.set_hint("value", GLib.Variant.new_int32(round(self.volume())))
notification.show()
@ -79,33 +82,37 @@ class PAMedia:
def volume_format(self):
volume = round(self.volume())
return f'{volume}%'
return f"{volume}%"
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='PulseAudio volume control')
parser.add_argument('-s', '--sink', type=int,
help='Select output sink to control')
parser.add_argument('command', metavar='CMD', type=str,
nargs='+', help='Command, one of: mute, up, down, set, get, sinks')
def main():
parser = argparse.ArgumentParser(description="PulseAudio volume control")
parser.add_argument("-s", "--sink", type=int, help="Select output sink to control")
parser.add_argument(
"command",
metavar="CMD",
type=str,
nargs="+",
help="Command, one of: mute, up, down, set, get, sinks",
)
args = parser.parse_args()
ctl = PAMedia(sink=args.sink)
Notify.init('volumectl')
Notify.init("volumectl")
if args.command[0] == 'mute':
if args.command[0] == "mute":
ctl.toggle_mute()
elif args.command[0] == 'up':
elif args.command[0] == "up":
ctl.volume_up()
elif args.command[0] == 'down':
elif args.command[0] == "down":
ctl.volume_down()
elif args.command[0] == 'get':
print(f'Volume: {ctl.volume_format()}')
elif args.command[0] == "get":
print(f"Volume: {ctl.volume_format()}")
exit(0)
elif args.command[0] == 'set' and len(args.command) >= 2:
elif args.command[0] == "set" and len(args.command) >= 2:
ctl.volume_set(args.command[1])
elif args.command[0] == 'sinks':
elif args.command[0] == "sinks":
ctl.list_sinks()
exit(0)
else:

View file

@ -0,0 +1,5 @@
from . import main
if __name__ == '__main__':
main()

View file

@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

View file

@ -0,0 +1,15 @@
[metadata]
name = pamedia
version = 0.1.0
description = Small utility to control the volume of the default PulseAudio sink, including notifications. Also compatible with Pipewire with the PulseAudio compatibility interface
author = "Erwin Boskma <erwin@datarift.nl>"
[options]
packages = pamedia
install_requires =
pulsectl
PyGObject
[options.entry_points]
console_scripts =
pamedia = pamedia:main

View file

@ -0,0 +1,4 @@
from setuptools import setup
if __name__ == "__main__":
setup()

View file

@ -32,6 +32,7 @@ stdenv.mkDerivation rec {
xorg.libxcb
xorg.xcbutil
xorg.xcbutilwm
xcb-util-cursor
xcbutilxrm
which
wayland-protocols