summary refs log tree commit diff
path: root/nixos/modules/services/misc/emby.nix
blob: b1968784af0f9ce1a9d66bb46071ff94d0151747 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{ config, pkgs, lib, mono, ... }:

with lib;

let
  cfg = config.services.emby;
  emby = pkgs.emby;
in
{
  options = {
    services.emby = {
      enable = mkEnableOption "Emby Media Server";

      user = mkOption {
        type = types.str;
        default = "emby";
        description = "User account under which Emby runs.";
      };

      group = mkOption {
        type = types.str;
        default = "emby";
        description = "Group under which emby runs.";
      };

      dataDir = mkOption {
        type = types.path;
        default = "/var/lib/emby/ProgramData-Server";
        description = "Location where Emby stores its data.";
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.services.emby = {
      description = "Emby Media Server";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      preStart = ''
        test -d ${cfg.dataDir} || {
          echo "Creating initial Emby data directory in ${cfg.dataDir}"
          mkdir -p ${cfg.dataDir}
          chown -R ${cfg.user}:${cfg.group} ${cfg.dataDir}
          }
      '';

      serviceConfig = {
        Type = "simple";
        User = cfg.user;
        Group = cfg.group;
        PermissionsStartOnly = "true";
        ExecStart = "${pkgs.emby}/bin/MediaBrowser.Server.Mono";
        Restart = "on-failure";
      };
    };

    users.users = mkIf (cfg.user == "emby") {
      emby = {
        group = cfg.group;
        uid = config.ids.uids.emby;
      };
    };

    users.groups = mkIf (cfg.group == "emby") {
      emby = {
        gid = config.ids.gids.emby;
      };
    };
  };
}