summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEthel Morgan <eth@ethulhu.co.uk>2020-06-24 16:01:35 +0100
committerEthel Morgan <eth@ethulhu.co.uk>2020-06-24 16:02:01 +0100
commit51170db7ce1b6560fda24c4f949ec9ed9b4b97cb (patch)
tree45f0929f2515459182f65ff4d681efded8bb03f9
parentcd73eb2b63d1049f7ddfb28fc45e2a4595f34d38 (diff)
add services.ambience, to add ambient sounds to snapserver
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/ambience.nix71
2 files changed, 72 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index dddb83d..e8e5f7f 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -4,6 +4,7 @@
./hardware/yubikey.nix
./overlays.nix
./programs/dwm.nix
+ ./services/ambience.nix
./services/catbus-actuator-wakeonlan.nix
./services/catbus-bridge-snapcast.nix
./services/catbus-observer-networkpresence.nix
diff --git a/nixos/modules/services/ambience.nix b/nixos/modules/services/ambience.nix
new file mode 100644
index 0000000..a4e03cf
--- /dev/null
+++ b/nixos/modules/services/ambience.nix
@@ -0,0 +1,71 @@
+{ config, lib, pkgs, ... }:
+with lib;
+
+let
+ cfg = config.eth.services.ambience;
+
+ mkService = name: opts: {
+ name = "ambience-${name}";
+ value = {
+ enable = opts.enable;
+ description = "Play ambient ${name} on loop";
+ wants = [ "sound.target" ];
+ after = [ "sound.target" ];
+ wantedBy = [ "multi-user.target" ];
+ partOf = [ "snapserver.service" ];
+ serviceConfig = {
+ DynamicUser = true;
+ Group = "audio";
+
+ ExecStart = "${pkgs.mpv}/bin/mpv --audio-display=no --audio-channels=stereo --audio-samplerate=48000 --audio-format=s16 --ao=pcm --ao-pcm-file=${opts.pipe} --loop=inf ${opts.file}";
+ NoNewPrivileges = true;
+ ProtectHome = true;
+ ProtectKernelTunables = true;
+ ProtectControlGroups = true;
+ ProtectKernelModules = true;
+ RestrictAddressFamilies = "";
+ RestrictNamespaces = true;
+ };
+ };
+ };
+
+in {
+ options.eth.services.ambience = {
+ enable = mkEnableOption "Play ambient sounds.";
+
+ streams = mkOption {
+ type = types.attrsOf (types.submodule {
+ options = {
+ enable = mkEnableOption "Play ambient sounds.";
+
+ file = mkOption {
+ type = types.str;
+ description = "file to play on loop";
+ default = "";
+ example = "/var/lib/ambience/rain.m4a";
+ };
+
+ pipe = mkOption {
+ type = types.str;
+ description = "pipe to play into";
+ default = "";
+ example = "/run/snapserver/rain";
+ };
+ };
+ });
+ default = {};
+ # example = { rain = { enable = true; file = "/var/lib/ambience/rain.mp3"; pipe = "/run/snapserver/rain"; }; };
+ description = "Streams to pipe to Snapserver";
+ };
+ };
+
+ config = mkIf cfg.enable {
+ assertions = [
+ {
+ assertion = config.services.snapserver.enable;
+ message = "must enable Snapserver to enable Ambience";
+ }
+ ];
+ systemd.services = listToAttrs (mapAttrsToList mkService cfg.streams);
+ };
+}