2024-05-15 15:35:15 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.programs.ydotool;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
meta = {
|
|
|
|
maintainers = with lib.maintainers; [ quantenzitrone ];
|
|
|
|
};
|
|
|
|
|
|
|
|
options.programs.ydotool = {
|
|
|
|
enable = lib.mkEnableOption ''
|
2024-06-20 14:57:18 +00:00
|
|
|
ydotoold system service and {command}`ydotool` for members of
|
|
|
|
{option}`programs.ydotool.group`.
|
2024-05-15 15:35:15 +00:00
|
|
|
'';
|
2024-06-20 14:57:18 +00:00
|
|
|
group = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "ydotool";
|
|
|
|
description = ''
|
|
|
|
Group which users must be in to use {command}`ydotool`.
|
|
|
|
'';
|
|
|
|
};
|
2024-05-15 15:35:15 +00:00
|
|
|
};
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
config = let
|
|
|
|
runtimeDirectory = "ydotoold";
|
|
|
|
in lib.mkIf cfg.enable {
|
|
|
|
users.groups."${config.programs.ydotool.group}" = { };
|
2024-05-15 15:35:15 +00:00
|
|
|
|
|
|
|
systemd.services.ydotoold = {
|
|
|
|
description = "ydotoold - backend for ydotool";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
partOf = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
2024-06-20 14:57:18 +00:00
|
|
|
Group = config.programs.ydotool.group;
|
|
|
|
RuntimeDirectory = runtimeDirectory;
|
2024-05-15 15:35:15 +00:00
|
|
|
RuntimeDirectoryMode = "0750";
|
2024-06-20 14:57:18 +00:00
|
|
|
ExecStart = "${lib.getExe' pkgs.ydotool "ydotoold"} --socket-path=${config.environment.variables.YDOTOOL_SOCKET} --socket-perm=0660";
|
2024-05-15 15:35:15 +00:00
|
|
|
|
|
|
|
# hardening
|
|
|
|
|
|
|
|
## allow access to uinput
|
|
|
|
DeviceAllow = [ "/dev/uinput" ];
|
|
|
|
DevicePolicy = "closed";
|
|
|
|
|
|
|
|
## allow creation of unix sockets
|
|
|
|
RestrictAddressFamilies = [ "AF_UNIX" ];
|
|
|
|
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
IPAddressDeny = "any";
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateNetwork = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProcSubset = "pid";
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
|
|
|
"~@privileged"
|
|
|
|
"~@resources"
|
|
|
|
];
|
|
|
|
UMask = "0077";
|
|
|
|
|
|
|
|
# -> systemd-analyze security score 0.7 SAFE 😀
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.variables = {
|
2024-06-20 14:57:18 +00:00
|
|
|
YDOTOOL_SOCKET = "/run/${runtimeDirectory}/socket";
|
2024-05-15 15:35:15 +00:00
|
|
|
};
|
|
|
|
environment.systemPackages = with pkgs; [ ydotool ];
|
|
|
|
};
|
|
|
|
}
|