Unverified Commit e267d078 authored by jopejoe1's avatar jopejoe1 Committed by GitHub
Browse files

nixos/shairport-sync: add freeform config (#363739)

parents 849ff7bf c38c9019
Loading
Loading
Loading
Loading
+47 −4
Original line number Diff line number Diff line
@@ -5,7 +5,8 @@ with lib;
let

  cfg = config.services.shairport-sync;

  configFormat = pkgs.formats.libconfig {};
  configFile = configFormat.generate "shairport-sync.conf" cfg.settings;
in

{
@@ -29,9 +30,44 @@ in

      package = lib.options.mkPackageOption pkgs "shairport-sync" { };

      settings =  mkOption {
        type = configFormat.type;
        default = {
          general.output_backend = "pa";
          diagnostics.log_verbosity = 1;
        };
        example = {
          general = {
            name = "NixOS Shairport";
            output_backend = "pw";
          };
          metadata = {
            enabled = "yes";
            include_cover_art = "yes";
            cover_art_cache_directory = "/tmp/shairport-sync/.cache/coverart";
            pipe_name = "/tmp/shairport-sync-metadata";
            pipe_timeout = 5000;
          };
          mqtt = {
            enabled = "yes";
            hostname = "mqtt.server.domain.example";
            port = 1883;
            publish_parsed = "yes";
            publish_cover = "yes";
          };
        };
        description = ''
          Configuration options for Shairport-Sync.

          See the example [shairport-sync.conf][example-file] for possible options.

          [example-file]: https://github.com/mikebrady/shairport-sync/blob/master/scripts/shairport-sync.conf
        '';
      };

      arguments = mkOption {
        type = types.str;
        default = "-v -o pa";
        default = "";
        description = ''
          Arguments to pass to the daemon. Defaults to a local pulseaudio
          server.
@@ -77,6 +113,11 @@ in
    services.avahi.publish.enable = true;
    services.avahi.publish.userServices = true;

    services.shairport-sync.settings = {
      general.output_backend = lib.mkDefault "pa";
      diagnostics.log_verbosity = lib.mkDefault 1;
    };

    users = {
      users.${cfg.user} = {
        description = "Shairport user";
@@ -108,8 +149,10 @@ in
        };
      };

    environment.systemPackages = [ cfg.package ];

    environment =  {
      systemPackages = [ cfg.package ];
      etc."shairport-sync.conf".source = configFile;
    };
  };

}