Commit da47ba87768e

Vincent Demeester <vincent@sbr.pm>
2018-10-24 19:28:37
modules: introduce modules (folder) and add shairport-sync modules…
… also adding it to shikoku. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 240c852
modules/services/shairport-sync.nix
@@ -0,0 +1,72 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+
+  cfg = config.services.shairport-sync;
+
+in
+
+{
+
+  ###### interface
+
+  options = {
+
+    services.shairport-sync = {
+
+      enable = mkOption {
+        default = false;
+        description = ''
+          Enable the shairport-sync daemon.
+
+          Running with a local system-wide or remote pulseaudio server
+          is recommended.
+        '';
+      };
+
+      arguments = mkOption {
+        default = "-v -j -o pa";
+        description = ''
+          Arguments to pass to the daemon. Defaults to a local pulseaudio
+          server.
+        '';
+      };
+
+    };
+
+  };
+
+
+  ###### implementation
+
+  config = mkIf config.services.shairport-sync.enable {
+
+    /*
+    Requires the following in NixOS (or elsewhere).
+
+    services.avahi.enable = true;
+    services.avahi.publish.enable = true;
+    services.avahi.publish.userServices = true;
+    networking.firewall.allowedUDPPortRanges = [ { from = 6001; to = 6101; } ];
+    networking.firewall.allowedTCPPorts = [ 5000 ];
+    */
+
+    systemd.user.services.shairport-sync = {
+      Unit = {
+        After = [ "network.target" "sound.target" ];
+        Description = "Airplay audio player";
+      };
+      Install = {
+        WantedBy = [ "default.target" ];
+      };
+      Service = {
+        Environment = "PATH=${config.home.profileDirectory}/bin";
+        ExecStart = "${pkgs.shairport-sync}/bin/shairport-sync ${cfg.arguments}";
+        ExecStop = "${pkgs.procps}/bin/pkill shairport-sync";
+        Type = "forking";
+      };
+    };
+  };
+}
modules/module-list.nix
@@ -0,0 +1,7 @@
+{ pkgs, lib, ... }:
+
+{
+  imports = [
+    ./services/shairport-sync.nix
+  ];
+}
base.nix
@@ -3,7 +3,7 @@
 let home_directory = builtins.getEnv "HOME"; in
 
 rec {
-
+imports = [ modules/module-list.nix ];
   programs = {
     home-manager = {
       enable = true;
shikoku.nix
@@ -28,4 +28,5 @@
     virtmanager
     zoom-us
   ];
+  services.shairport-sync.enable = true;
 }