Files
Jovian-NixOS/modules/decky-loader.nix

117 lines
3.1 KiB
Nix
Raw Permalink Normal View History

2023-07-16 20:06:56 -06:00
{ config, lib, pkgs, ... }:
let
inherit (lib)
mkIf
mkOption
types
;
cfg = config.jovian.decky-loader;
2024-06-27 12:24:50 +03:00
package = cfg.package.overridePythonAttrs(old: {
dependencies = old.dependencies ++ (cfg.extraPythonPackages old.passthru.python.pkgs);
2024-06-27 12:24:50 +03:00
});
2023-07-16 20:06:56 -06:00
in
{
options = {
jovian = {
decky-loader = {
enable = mkOption {
type = types.bool;
default = false;
2024-04-17 08:52:14 +03:00
description = ''
2023-07-16 20:06:56 -06:00
Whether to enable the Steam Deck Plugin Loader.
'';
};
package = mkOption {
type = types.package;
default = pkgs.decky-loader;
defaultText = lib.literalExpression "pkgs.decky-loader";
2024-04-17 08:52:14 +03:00
description = ''
The loader package to use.
'';
};
2023-07-16 20:06:56 -06:00
extraPackages = mkOption {
type = types.listOf types.package;
example = lib.literalExpression "[ pkgs.curl pkgs.unzip ]";
default = [];
2024-04-17 08:52:14 +03:00
description = ''
2023-07-16 20:06:56 -06:00
Extra packages to add to the service PATH.
'';
};
extraPythonPackages = mkOption {
type = types.functionTo (types.listOf types.package);
example = lib.literalExpression "pythonPackages: with pythonPackages; [ hid ]";
default = _: [];
defaultText = lib.literalExpression "pythonPackages: []";
2024-04-17 08:52:14 +03:00
description = ''
Extra Python packages to add to the PYTHONPATH of the loader.
'';
};
2023-07-16 20:06:56 -06:00
stateDir = mkOption {
type = types.path;
default = "/var/lib/decky-loader";
2024-04-17 08:52:14 +03:00
description = ''
2023-07-16 20:06:56 -06:00
Directory to store plugins and data.
'';
};
user = mkOption {
type = types.str;
default = "decky";
2024-04-17 08:52:14 +03:00
description = ''
2023-07-16 20:06:56 -06:00
The user Decky Loader should run plugins as.
'';
};
};
};
};
config = mkIf cfg.enable (lib.mkMerge [
(lib.mkIf (cfg.user == "decky") {
users.users.decky = {
group = "decky";
home = cfg.stateDir;
isSystemUser = true;
};
users.groups.decky = {};
})
{
# As of 2023/07/16, the Decky Loader needs to run as root, even if you never
# use plugins that require it. It setuid's to the unprivileged user to
# run plugins. Running as non-root is unsupported and currently breaks:
#
# <https://github.com/SteamDeckHomebrew/decky-loader/issues/446#issuecomment-1637177368>
systemd.services.decky-loader = {
description = "Steam Deck Plugin Loader";
wantedBy = [ "multi-user.target" ];
2024-06-27 12:24:50 +03:00
after = [ "network.target" ];
2023-07-16 20:06:56 -06:00
2024-06-27 12:24:50 +03:00
environment = {
2023-07-16 20:06:56 -06:00
UNPRIVILEGED_USER = cfg.user;
UNPRIVILEGED_PATH = cfg.stateDir;
PLUGIN_PATH = "${cfg.stateDir}/plugins";
};
2024-06-27 12:24:50 +03:00
path = cfg.extraPackages;
2023-07-16 20:06:56 -06:00
preStart = ''
mkdir -p "${cfg.stateDir}"
chown -R "${cfg.user}:" "${cfg.stateDir}"
'';
serviceConfig = {
2024-06-27 12:24:50 +03:00
ExecStart = "${package}/bin/decky-loader";
KillMode = "process";
TimeoutStopSec = 45;
2023-07-16 20:06:56 -06:00
};
};
}
]);
}