1{ config, pkgs, lib, mono, ... }:
2
3with lib;
4
5let
6 cfg = config.services.emby;
7 emby = pkgs.emby;
8in
9{
10 options = {
11 services.emby = {
12 enable = mkEnableOption "Emby Media Server";
13
14 user = mkOption {
15 type = types.str;
16 default = "emby";
17 description = "User account under which Emby runs.";
18 };
19
20 group = mkOption {
21 type = types.str;
22 default = "emby";
23 description = "Group under which emby runs.";
24 };
25 };
26 };
27
28 config = mkIf cfg.enable {
29 systemd.services.emby = {
30 description = "Emby Media Server";
31 after = [ "network.target" ];
32 wantedBy = [ "multi-user.target" ];
33 preStart = ''
34 test -d /var/lib/emby/ProgramData-Server || {
35 echo "Creating initial Emby data directory in /var/lib/emby/ProgramData-Server"
36 mkdir -p /var/lib/emby/ProgramData-Server
37 chown -R ${cfg.user}:${cfg.group} /var/lib/emby/ProgramData-Server
38 }
39 '';
40
41 serviceConfig = {
42 Type = "simple";
43 User = cfg.user;
44 Group = cfg.group;
45 PermissionsStartOnly = "true";
46 ExecStart = "${pkgs.mono}/bin/mono ${pkgs.emby}/bin/MediaBrowser.Server.Mono.exe";
47 Restart = "on-failure";
48 };
49 };
50
51 users.extraUsers = mkIf (cfg.user == "emby") {
52 emby = {
53 group = cfg.group;
54 uid = config.ids.uids.emby;
55 };
56 };
57
58 users.extraGroups = mkIf (cfg.group == "emby") {
59 emby = {
60 gid = config.ids.gids.emby;
61 };
62 };
63 };
64}