commit ef1fca222621a27cedd1b949dcf9f1028d88df4c
parent 007ddaba48b6a7616e26fc141a77b0d08584039a
Author: Leah (ctucx) <leah@ctu.cx>
Date: Sun, 6 Mar 2022 20:01:20 +0100
parent 007ddaba48b6a7616e26fc141a77b0d08584039a
Author: Leah (ctucx) <leah@ctu.cx>
Date: Sun, 6 Mar 2022 20:01:20 +0100
modules/desktop-speakers: add module
6 files changed, 124 insertions(+), 106 deletions(-)
D
|
66
------------------------------------------------------------------
A
|
107
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
diff --git a/configurations/desktop-speakers.nix b/configurations/desktop-speakers.nix @@ -1,66 +0,0 @@ -{ config, pkgs, lib, ... }: - -{ - - home-manager.users.leah = { - - wayland.windowManager.sway.config.keybindings = { - "${config.home-manager.users.leah.wayland.windowManager.sway.config.modifier}+Delete" = "exec curl -d '{\"accessToken\": \"penis123\", \"type\": \"SwitchStateAction\", \"deviceName\": \"modbus-20\", \"relay\": 0, \"toggle\": true}' http://10.0.0.1:5000"; - }; - - systemd.user.services = { - speakers = { - Unit = { - Requisite = [ "graphical-session.target" ]; - - After = [ "network-online.target" ]; - Wants = [ "network-online.target" ]; - }; - - Service = { - RemainAfterExit = "yes"; - - ExecStartPre = "/usr/bin/env sh -c 'until ping -c1 10.0.0.1; do sleep 0.1; done;'"; - ExecStart = "${pkgs.curl}/bin/curl -d '{\"accessToken\": \"penis123\", \"type\": \"SwitchStateAction\", \"deviceName\": \"modbus-20\", \"relay\": 0, \"state\": true}' http://10.0.0.1:5000"; - - ExecStopPre = "/usr/bin/env sh -c 'until ping -c1 10.0.0.1; do sleep 0.1; done;'"; - ExecStop = "${pkgs.curl}/bin/curl -d '{\"accessToken\": \"penis123\", \"type\": \"SwitchStateAction\", \"deviceName\": \"modbus-20\", \"relay\": 0, \"state\": false}' http://10.0.0.1:5000"; - }; - - Install = { - WantedBy = [ "graphical-session.target" ]; - }; - }; - speakers-lock = { - Unit = { - Requisite = [ "graphical-session.target" ]; - PartOf = [ "lock.target" "sleep.target" ]; - }; - - Service = { - ExecStart = "${pkgs.systemd}/bin/systemctl --user stop speakers"; - }; - - Install = { - WantedBy = [ "lock.target" "sleep.target" ]; - }; - }; - speakers-unlock = { - Unit = { - Requisite = [ "graphical-session.target" ]; - PartOf = [ "unlock.target" ]; - }; - - Service = { - ExecStart = "${pkgs.systemd}/bin/systemctl --user start speakers"; - }; - - Install = { - WantedBy = [ "unlock.target" ]; - }; - }; - }; - - }; - -}
diff --git a/configurations/services/pipewire.nix b/configurations/services/pipewire.nix @@ -62,46 +62,9 @@ in { } { name = "libpipewire-module-zeroconf-discover"; } ]; - -# ] ++ (if config.networking.hostName == "stasicontainer" then [ -# { -# name = "libpipewire-module-pulse-tunnel"; -# args = { -# "pulse.server.address" = "tcp:10.0.0.1"; -# "tunnel.mode" = "playback"; -# }; -# } -# ] else []); }; }; }; }; - home-manager.users.leah = { - systemd.user.services = lib.mkIf (config.networking.hostName == "stasicontainer") { - pipewire-pulse-tunnel = { - Unit = { - Requires = [ "pipewire-pulse.service" ]; - After = [ "pipewire-pulse.service" "network-online.target" ]; - BindsTo = [ "pipewire-pulse.service" ]; - }; - - Service = { - Type = "oneshot"; - RemainAfterExit = true; - ExecStartPre = "/usr/bin/env sh -c 'until ping -c1 195.39.246.41; do sleep 0.1; done;'"; - ExecStart = "${pkgs.pulseaudio}/bin/pactl load-module module-tunnel-sink server=195.39.246.41"; - ExecStop = "${pkgs.pulseaudio}/bin/pactl unload-module module-tunnel-sink"; - }; - - Install = { - WantedBy = [ "pipewire-pulse.service" ]; - }; - }; - }; - - wayland.windowManager.sway.config.keybindings = { - "${config.home-manager.users.leah.wayland.windowManager.sway.config.modifier}+Insert" = "exec systemctl --user restart pipewire-pulse-tunnel.service"; - }; - }; }
diff --git a/machines/currywurst/configuration.nix b/machines/currywurst/configuration.nix @@ -10,7 +10,13 @@ ../../configurations/desktop-sway.nix ]; - hardware.cpu.intel.updateMicrocode = true; + hardware = { + cpu.intel.updateMicrocode = true; + desktop-speakers = { + power-control.enable = true; + pipewire-tunnel.enable = true; + }; + }; boot = { loader = {
diff --git a/machines/stasicontainer/configuration.nix b/machines/stasicontainer/configuration.nix @@ -9,11 +9,18 @@ ../../configurations/desktop-sway.nix ../../configurations/programs/ddcutil.nix - ../../configurations/desktop-speakers.nix ../../configurations/sdr.nix ]; - hardware.cpu.intel.updateMicrocode = true; + hardware = { + cpu.intel.updateMicrocode = true; + desktop-speakers = { + power-control.enable = true; + power-control.automaticSwitching = true; + pipewire-tunnel.enable = true; + pipewire-tunnel.automaticConnect = true; + }; + }; boot = { loader = {
diff --git a/modules/default.nix b/modules/default.nix @@ -3,6 +3,7 @@ imports = [ ./restic-backups.nix ./vnstati + ./desktop-speakers.nix ]; }
diff --git a/modules/desktop-speakers.nix b/modules/desktop-speakers.nix @@ -0,0 +1,107 @@ +{ pkgs, lib, config, ... }: + +let + secrets = import ../secrets; + cfg = config.hardware.desktop-speakers; + +in { + options.hardware.desktop-speakers = with lib; { + power-control.enable = mkEnableOption "Control power-state of speakers"; + power-control.automaticSwitching = mkEnableOption "Control power-state of speakers via lock-state"; + pipewire-tunnel.enable = mkEnableOption "Create a systend-user-service for a pipewire-tunnel to the speakers"; + pipewire-tunnel.automaticConnect = mkEnableOption "Activate pipewire-tunnel together with pipewire"; + }; + + config = { + assertions = lib.mkIf cfg.power-control.automaticSwitching [ + ({ + assertion = cfg.power-control.enable; + message = "hardware..power-control.automaticSwitching requires hardware.power-control.enable == true"; + }) + ]; + + home-manager.users.leah.wayland.windowManager.sway.config.keybindings = { + "${config.home-manager.users.leah.wayland.windowManager.sway.config.modifier}+Delete" = lib.mkIf cfg.power-control.enable "exec curl -d '{\"accessToken\": \"${secrets.hosts.lollo.smartied.accessToken}\", \"type\": \"SwitchStateAction\", \"deviceName\": \"modbus-20\", \"relay\": 0, \"toggle\": true}' http://10.0.0.1:5000"; + "${config.home-manager.users.leah.wayland.windowManager.sway.config.modifier}+Insert" = lib.mkIf cfg.pipewire-tunnel.enable "exec systemctl --user restart pipewire-pulse-tunnel.service"; + }; + + home-manager.users.leah.systemd.user.services = { + speakers = lib.mkIf cfg.power-control.enable { + Unit = { + Requisite = [ "graphical-session.target" ]; + + After = [ "network-online.target" ]; + Wants = [ "network-online.target" ]; + }; + + Service = { + RemainAfterExit = "yes"; + + ExecStartPre = "/usr/bin/env sh -c 'until ping -c1 10.0.0.1; do sleep 0.1; done;'"; + ExecStart = "${pkgs.curl}/bin/curl -d '{\"accessToken\": \"${secrets.hosts.lollo.smartied.accessToken}\", \"type\": \"SwitchStateAction\", \"deviceName\": \"modbus-20\", \"relay\": 0, \"state\": true}' http://10.0.0.1:5000"; + + ExecStopPre = "/usr/bin/env sh -c 'until ping -c1 10.0.0.1; do sleep 0.1; done;'"; + ExecStop = "${pkgs.curl}/bin/curl -d '{\"accessToken\": \"${secrets.hosts.lollo.smartied.accessToken}\", \"type\": \"SwitchStateAction\", \"deviceName\": \"modbus-20\", \"relay\": 0, \"state\": false}' http://10.0.0.1:5000"; + }; + + Install = { + WantedBy = [ "graphical-session.target" ]; + }; + }; + + speakers-lock = lib.mkIf cfg.power-control.automaticSwitching { + Unit = { + Requisite = [ "graphical-session.target" ]; + PartOf = [ "lock.target" "sleep.target" ]; + }; + + Service = { + ExecStart = "${pkgs.systemd}/bin/systemctl --user stop speakers"; + }; + + Install = { + WantedBy = [ "lock.target" "sleep.target" ]; + }; + }; + + speakers-unlock = lib.mkIf cfg.power-control.automaticSwitching { + Unit = { + Requisite = [ "graphical-session.target" ]; + PartOf = [ "unlock.target" ]; + }; + + Service = { + ExecStart = "${pkgs.systemd}/bin/systemctl --user start speakers"; + }; + + Install = { + WantedBy = [ "unlock.target" ]; + }; + }; + + + pipewire-pulse-tunnel = lib.mkIf cfg.pipewire-tunnel.enable { + Unit = { + Requires = [ "pipewire-pulse.service" ]; + After = [ "pipewire-pulse.service" "network-online.target" ]; + BindsTo = [ "pipewire-pulse.service" ]; + }; + + Service = { + Type = "oneshot"; + RemainAfterExit = true; + ExecStartPre = "/usr/bin/env sh -c 'until ping -c1 195.39.246.41; do sleep 0.1; done;'"; + ExecStart = "${pkgs.pulseaudio}/bin/pactl load-module module-tunnel-sink server=195.39.246.41"; + ExecStop = "${pkgs.pulseaudio}/bin/pactl unload-module module-tunnel-sink"; + }; + + Install = lib.mkIf cfg.pipewire-tunnel.automaticConnect { + WantedBy = [ "pipewire-pulse.service" ]; + }; + }; + + }; + + }; + +}