fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
1.8 KiB70 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  jsonFormat = pkgs.formats.json { };
8  cfg = config.services.plex-mpv-shim;
9
10in {
11  meta.maintainers = [ maintainers.starcraft66 ];
12
13  options = {
14    services.plex-mpv-shim = {
15      enable = mkEnableOption "Plex mpv shim";
16
17      package = mkOption {
18        type = types.package;
19        default = pkgs.plex-mpv-shim;
20        defaultText = literalExpression "pkgs.plex-mpv-shim";
21        description = "The package to use for the Plex mpv shim.";
22      };
23
24      settings = mkOption {
25        type = jsonFormat.type;
26        default = { };
27        example = literalExpression ''
28          {
29            adaptive_transcode = false;
30            allow_http = false;
31            always_transcode = false;
32            audio_ac3passthrough = false;
33            audio_dtspassthrough = false;
34            auto_play = true;
35            auto_transcode = true;
36          }
37        '';
38        description = ''
39          Configuration written to
40          {file}`$XDG_CONFIG_HOME/plex-mpv-shim/config.json`. See
41          <https://github.com/iwalton3/plex-mpv-shim/blob/master/README.md>
42          for the configuration documentation.
43        '';
44      };
45    };
46  };
47
48  config = mkIf cfg.enable {
49    assertions = [
50      (lib.hm.assertions.assertPlatform "services.plex-mpv-shim" pkgs
51        lib.platforms.linux)
52    ];
53
54    xdg.configFile."plex-mpv-shim/conf.json" = mkIf (cfg.settings != { }) {
55      source = jsonFormat.generate "conf.json" cfg.settings;
56    };
57
58    systemd.user.services.plex-mpv-shim = {
59      Unit = {
60        Description = "Plex mpv shim";
61        After = [ "graphical-session-pre.target" ];
62        PartOf = [ "graphical-session.target" ];
63      };
64
65      Service = { ExecStart = "${cfg.package}/bin/plex-mpv-shim"; };
66
67      Install = { WantedBy = [ "graphical-session.target" ]; };
68    };
69  };
70}