From 42ad65fc34f323a6cd954da26ff9f8e94ff46e7c Mon Sep 17 00:00:00 2001 From: Ricard Illa Date: Sat, 19 Aug 2023 18:36:21 +0200 Subject: [PATCH] feat: restructured snapcast --- hosts/capibara/default.nix | 1 + hosts/capibara/home-manager.nix | 2 ++ hosts/capibara/snapcast.nix | 25 ++++++++++++++++ modules/home-manager/default.nix | 2 +- modules/home-manager/extra/default.nix | 1 - modules/home-manager/snapcast/default.nix | 21 ------------- modules/home-manager/snapclient/default.nix | 33 +++++++++++++++++++++ 7 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 hosts/capibara/snapcast.nix delete mode 100644 modules/home-manager/snapcast/default.nix create mode 100644 modules/home-manager/snapclient/default.nix diff --git a/hosts/capibara/default.nix b/hosts/capibara/default.nix index 6c7330a..034a1ca 100644 --- a/hosts/capibara/default.nix +++ b/hosts/capibara/default.nix @@ -9,6 +9,7 @@ ./hardware-configuration.nix ./file-systems.nix ./home-manager.nix + ./snapcast.nix outputs.nixosModules.common outputs.nixosModules.desktop ]; diff --git a/hosts/capibara/home-manager.nix b/hosts/capibara/home-manager.nix index 667665a..64c923f 100644 --- a/hosts/capibara/home-manager.nix +++ b/hosts/capibara/home-manager.nix @@ -15,7 +15,9 @@ imports = [ outputs.homeManagerModules.common outputs.homeManagerModules.extra + outputs.homeManagerModules.snapcast ]; + snapclient.enable = true; }; }; } diff --git a/hosts/capibara/snapcast.nix b/hosts/capibara/snapcast.nix new file mode 100644 index 0000000..3bf7890 --- /dev/null +++ b/hosts/capibara/snapcast.nix @@ -0,0 +1,25 @@ +{ config, pkgs, ... }: + +{ + services.snapserver = { + enable = true; + codec = "flac"; + streams = { + pipewire = { + type = "pipe"; + location = "/run/snapserver/pipewire"; + }; + }; + }; + + systemd.user.services.snapcast-sink = { + wantedBy = [ "pipewire.service" ]; + after = [ "pipewire.service" ]; + bindsTo = [ "pipewire.service" ]; + path = with pkgs; [ gawk pulseaudio ]; + script = '' + pactl load-module module-pipe-sink file=/run/snapserver/pipewire sink_name=Snapcast format=s16le rate=48000 + ''; + }; + +} diff --git a/modules/home-manager/default.nix b/modules/home-manager/default.nix index 9b21060..045a09b 100644 --- a/modules/home-manager/default.nix +++ b/modules/home-manager/default.nix @@ -29,7 +29,7 @@ neovim = import ./neovim; pass = import ./pass; rss = import ./rss; - snapcast = import ./snapcast; + snapclient = import ./snapclient; sound = import ./sound; ssh = import ./ssh; syncthing = import ./syncthing; diff --git a/modules/home-manager/extra/default.nix b/modules/home-manager/extra/default.nix index 73891e8..39565d1 100644 --- a/modules/home-manager/extra/default.nix +++ b/modules/home-manager/extra/default.nix @@ -20,7 +20,6 @@ ../msg ../music ../rss - ../snapcast ../sound ../syncthing ../theming diff --git a/modules/home-manager/snapcast/default.nix b/modules/home-manager/snapcast/default.nix deleted file mode 100644 index ba53179..0000000 --- a/modules/home-manager/snapcast/default.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ config, pkgs, ... }: - -let snapserver_ip = "192.168.1.144"; -in -{ - home.packages = [ pkgs.snapcast ]; - - systemd.user.services.snapclient = { - Unit = { - After = [ "pipewire.service" ]; - }; - Service = { - Type = "simple"; - ExecStart = "${pkgs.snapcast}/bin/snapclient --host ${snapserver_ip}"; - }; - Install = { - WantedBy = [ "pipewire.service" ]; - }; - }; - -} diff --git a/modules/home-manager/snapclient/default.nix b/modules/home-manager/snapclient/default.nix new file mode 100644 index 0000000..24fe983 --- /dev/null +++ b/modules/home-manager/snapclient/default.nix @@ -0,0 +1,33 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.snapclient; +in +{ + options.snapclient = { + enable = lib.mkEnableOption "snapclient"; + snapserver-host = lib.mkOption { + type = lib.types.str; + default = "localhost"; + description = "host running snapserver to connect to"; + }; + package = lib.mkOption { + type = lib.types.package; + default = pkgs.snapcast; + defaultText = "pkgs.snapcast"; + description = "package for snapcast"; + }; + }; + + config = lib.mkIf cfg.enable { + systemd.user.services.snapclient = { + Service = { + Type = "simple"; + ExecStart = "${cfg.package}/bin/snapclient --host ${cfg.snapserver-host}"; + }; + Unit.After = [ "pipewire.service" ]; + Install.WantedBy = [ "pipewire.service" ]; + }; + }; + +}