fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
1.5 KiB69 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.spotifyd;
8
9  tomlFormat = pkgs.formats.toml { };
10
11  configFile = tomlFormat.generate "spotifyd.conf" cfg.settings;
12
13in {
14  options.services.spotifyd = {
15    enable = mkEnableOption "SpotifyD connect";
16
17    package = mkOption {
18      type = types.package;
19      default = pkgs.spotifyd;
20      defaultText = literalExpression "pkgs.spotifyd";
21      example =
22        literalExpression "(pkgs.spotifyd.override { withKeyring = true; })";
23      description = ''
24        The `spotifyd` package to use.
25        Can be used to specify extensions.
26      '';
27    };
28
29    settings = mkOption {
30      type = tomlFormat.type;
31      default = { };
32      description = "Configuration for spotifyd";
33      example = literalExpression ''
34        {
35          global = {
36            username = "Alex";
37            password = "foo";
38            device_name = "nix";
39          };
40        }
41      '';
42    };
43  };
44
45  config = mkIf cfg.enable {
46    assertions = [
47      (lib.hm.assertions.assertPlatform "services.spotifyd" pkgs
48        lib.platforms.linux)
49    ];
50
51    home.packages = [ cfg.package ];
52
53    systemd.user.services.spotifyd = {
54      Unit = {
55        Description = "spotify daemon";
56        Documentation = "https://github.com/Spotifyd/spotifyd";
57      };
58
59      Install.WantedBy = [ "default.target" ];
60
61      Service = {
62        ExecStart =
63          "${cfg.package}/bin/spotifyd --no-daemon --config-path ${configFile}";
64        Restart = "always";
65        RestartSec = 12;
66      };
67    };
68  };
69}