auto-flake-update
Yorick van Pelt 10 months ago
parent e8b79f68a2
commit 7d5ff7e42c
Signed by: yorick
GPG Key ID: A36E70F9DC014A15

@ -0,0 +1,65 @@
#! /usr/bin/env nix-shell
#! nix-shell -p python3 -p python3.pkgs.dbus-python -i python
import dbus
import enum
system_bus = dbus.SystemBus()
class AmbientSoundMode(enum.Enum):
NORMAL = "normal"
VOICE = "voice"
class Headphone():
def __init__(self, path):
self.proxy = system_bus.get_object("org.mdr", path)
self.nc = dbus.Interface(self.proxy, dbus_interface="org.mdr.NoiseCancelling")
self.amb = dbus.Interface(self.proxy, dbus_interface="org.mdr.AmbientSoundMode")
self.props = dbus.Interface(self.proxy, dbus_interface="org.freedesktop.DBus.Properties")
def _p(self, tp, i, n):
return tp(self.props.Get("org.mdr."+i, n))
@property
def name(self) -> str:
return self._p(tp, "Device", "name")
@property
def volume(self) -> int:
return self._p(int, "Playback", "volume")
@volume.setter
def volume(self, n: int):
self.proxy.SetVolume(n, dbus_interface="org.mdr.Playback")
@property
def noise_cancelling(self) -> bool:
return self._p(bool, "NoiseCancelling", "enabled")
@noise_cancelling.setter
def noise_cancelling(self, val: bool) -> None:
if val:
self.nc.Enable()
else:
self.nc.Disable()
@property
def battery(self) -> int:
return self._p(int, "Battery", "level")
@property
def charging(self) -> bool:
return self._p(bool, "Battery", "charging")
@property
def ambient_sound_amount(self) -> int:
return self._p(int, "AmbientSoundMode", "amount")
@ambient_sound_amount.setter
def ambient_sound_amount(self, n: int) -> None:
return self.amb.SetAmount(n)
@property
def ambient_sound_mode(self) -> AmbientSoundMode:
return AmbientSoundMode(self._p("AmbientSoundMode", "mode"))
@ambient_sound_mode.setter
def ambient_sound_mode(self, n: AmbientSoundMode) -> None:
self.amb.SetMode(n.value)
@property
def auto_power_off_timeout(self) -> str:
return self._p(str, "AutoPowerOff", "timeout")
# todo setter
# todo eq
def power_off(self) -> None:
self.proxy.PowerOff(dbus_interface="org.mdr.PowerOff")
wh = Headphone("/org/bluez/hci0/dev_94_DB_56_79_7D_86")

@ -41,4 +41,14 @@
# docker
virtualisation.docker.enable = true;
users.users.yorick.extraGroups = [ "docker" ];
systemd.services.mdrd = {
serviceConfig = {
Type = "dbus";
ExecStart = "${pkgs.mdrd}/bin/mdrd";
BusName = "org.mdr";
};
wantedBy = [ "graphical-session.target" ];
};
services.dbus.packages = [ pkgs.mdrd ];
}

@ -5,6 +5,7 @@ in [
(import sources.nixpkgs-mozilla)
(import sources.emacs-overlay)
(import ./pkgs)
(import ./pkgs/mdr.nix)
(import ./nixos/overlay.nix)
(import ./overlay.nix)
]

@ -0,0 +1,97 @@
(self: super: {
libmdr = self.callPackage ({stdenv, fetchFromGitHub, bluez}: stdenv.mkDerivation rec {
pname = "libmdr";
version = "0.5.1";
buildInputs = [ bluez ];
src = fetchFromGitHub {
owner = "AndreasOlofsson";
repo = pname;
rev = "v${version}";
sha256 = "1asXrEwv1Bk82sgtOhU+beo2p8B8VBTHw4FP6seIPag=";
};
enableParallelBuilding = true;
installPhase = ''
install -D libmdr.a $out/lib/libmdr.a
cp -r include $out
'';
}) {};
mdrd = self.callPackage ({stdenv, fetchFromGitHub, libmdr, pkg-config, glib, bluez}: stdenv.mkDerivation rec {
pname = "mdrd";
version = "0.3";
nativeBuildInputs = [ pkg-config ];
buildInputs = [ libmdr glib bluez ];
makeFlags = "LIBMDR=${libmdr}/lib/libmdr.a --assume-old=${libmdr}/lib/libmdr.a";
src = fetchFromGitHub {
owner = "AndreasOlofsson";
repo = pname;
rev = "v${version}";
sha256 = "sha256-XAcHtOaG/na9zlPezBSH52J5gF6uhW99vP7TW+ShnzY=";
};
installPhase = ''
install -D mdrd $out/bin/mdrd
mkdir -p $out/share/dbus-1/system-services
cat > $_/org.mdr.service <<HERE
[D-Bus Service]
Name=org.mdr
Exec=$out/bin/mdrd
User=root
SystemdService=dbus-org.mdr.service
HERE
mkdir -p $out/share/dbus-1/system.d
cat > $_/org.mdr.conf <<HERE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- Only root can own the service -->
<policy user="root">
<allow own="org.mdr"/>
</policy>
<!-- Allow anyone to invoke methods on the interfaces -->
<policy context="default">
<allow send_destination="org.mdr"
send_interface="org.mdr"/>
<allow send_destination="org.mdr"
send_interface="org.mdr.NoiseCancelling"/>
<allow send_destination="org.mdr"
send_interface="org.mdr.PowerOff"/>
<allow send_destination="org.mdr"
send_interface="org.mdr.AmbientSoundMode"/>
<allow send_destination="org.mdr"
send_interface="org.mdr.Eq"/>
<allow send_destination="org.mdr"
send_interface="org.mdr.AutoPowerOff"/>
<allow send_destination="org.mdr"
send_interface="org.mdr.KeyFunctions"/>
<allow send_destination="org.mdr"
send_interface="org.mdr.Playback"/>
<allow send_destination="org.mdr"
send_interface="org.freedesktop.DBus.Introspectable"/>
<allow send_destination="org.mdr"
send_interface="org.freedesktop.DBus.Properties"/>
</policy>
</busconfig>
HERE
'';
enableParallelBuilding = true;
}) {};
mdr-manager = self.callPackage ({stdenv, fetchFromGitHub, pkg-config, glib, gtk3}: stdenv.mkDerivation rec {
pname = "mdr-manager";
version = "0.3";
nativeBuildInputs = [ pkg-config ];
buildInputs = [ glib gtk3 ];
NIX_CFLAGS_COMPILE = "-I${glib.dev}/include/gio-unix-2.0";
#makeFlags = "LIBMDR=${libmdr}/lib/libmdr.a --assume-old=${libmdr}/lib/libmdr.a";
src = fetchFromGitHub {
owner = "AndreasOlofsson";
repo = pname;
rev = "v${version}";
sha256 = "sha256-ZWXhsGsbGDQlnkZLCbL9MPi5Y7wZIltVyOrkPWImu2c=";
};
installPhase = "install -D mdr-manager $out/bin/mdr-manager";
enableParallelBuilding = true;
}) {};
})
Loading…
Cancel
Save