Skip to content

Commit

Permalink
nixos/plex: add systemd hardening configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
xyven1 committed May 12, 2024
1 parent 707376c commit 201a5ff
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions nixos/modules/services/misc/plex.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ in
'';
};

accelerationDevices = mkOption {
type = types.listOf types.str;
default = ["*"];
example = [ "/dev/dri/renderD128" ];
description = ''
A list of device paths to hardware acceleration devices that Plex should
have access to. This is useful when transcoding media files.
The special value `"*"` will allow all devices.
'';
};

package = mkPackageOption pkgs "plex" {
extraDescription = ''
Plex subscribers may wish to use their own package here,
Expand Down Expand Up @@ -133,6 +144,24 @@ in
KillSignal = "SIGQUIT";
PIDFile = "${cfg.dataDir}/Plex Media Server/plexmediaserver.pid";
Restart = "on-failure";

# Hardening
NoNewPrivileges = true;
PrivateTmp = true;
PrivateDevices = cfg.accelerationDevices == [];
DeviceAllow = mkIf (cfg.accelerationDevices != [] && !lib.elem "*" cfg.accelerationDevices) cfg.accelerationDevices;
ProtectSystem = true;
ProtectHome = true;
ProtectControlGroups = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
RestrictAddressFamilies = ["AF_UNIX" "AF_INET" "AF_INET6" "AF_NETLINK"];
# This could be made to work if the namespaces needed were known
# RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
MemoryDenyWriteExecute = true;
LockPersonality = true;
};

environment = {
Expand Down

0 comments on commit 201a5ff

Please sign in to comment.