about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/misc/emby.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/nixos/modules/services/misc/emby.nix')
-rw-r--r--nixpkgs/nixos/modules/services/misc/emby.nix76
1 files changed, 76 insertions, 0 deletions
diff --git a/nixpkgs/nixos/modules/services/misc/emby.nix b/nixpkgs/nixos/modules/services/misc/emby.nix
new file mode 100644
index 000000000000..0ad4a3f7376f
--- /dev/null
+++ b/nixpkgs/nixos/modules/services/misc/emby.nix
@@ -0,0 +1,76 @@
+{ config, pkgs, lib, ... }:
+
+with lib;
+
+let
+  cfg = config.services.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 = ''
+        if [ -d ${cfg.dataDir} ]
+        then
+            for plugin in ${cfg.dataDir}/plugins/*
+            do
+                echo "Correcting permissions of plugin: $plugin"
+                chmod u+w $plugin
+            done
+        else
+            echo "Creating initial Emby data directory in ${cfg.dataDir}"
+            mkdir -p ${cfg.dataDir}
+            chown -R ${cfg.user}:${cfg.group} ${cfg.dataDir}
+        fi
+      '';
+
+      serviceConfig = {
+        Type = "simple";
+        User = cfg.user;
+        Group = cfg.group;
+        PermissionsStartOnly = "true";
+        ExecStart = "${pkgs.emby}/bin/emby -programdata ${cfg.dataDir}";
+        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;
+      };
+    };
+  };
+}