nixos/brltty: use upstream units

Upstream has been providing a very thoroughly designed set of systemd units,
udev and polkit rules. With these the brltty daemon is activated
asynchronously via udev, runs as a dedicated user with runtime and state
directories set up using systemd-tmpfiles.

This is much better than the current unit, which runs a single instance
as root and pulls in systemd-udev-settle to wait for the hardware.
wip/little-gl
rnhmjoj 3 years ago
parent 13375265e4
commit da2923b4f8
No known key found for this signature in database
GPG Key ID: BFBAF4C975F76450
  1. 57
      nixos/modules/services/hardware/brltty.nix

@ -5,6 +5,19 @@ with lib;
let
cfg = config.services.brltty;
targets = [
"default.target" "multi-user.target"
"rescue.target" "emergency.target"
];
genApiKey = pkgs.writers.writeDash "generate-brlapi-key" ''
if ! test -f /etc/brlapi.key; then
echo -n generating brlapi key...
${pkgs.brltty}/bin/brltty-genkey -f /etc/brlapi.key
echo done
fi
'';
in {
options = {
@ -18,33 +31,27 @@ in {
};
config = mkIf cfg.enable {
systemd.services.brltty = {
description = "Braille Device Support";
unitConfig = {
Documentation = "http://mielke.cc/brltty/";
DefaultDependencies = "no";
RequiresMountsFor = "${pkgs.brltty}/var/lib/brltty";
};
serviceConfig = {
ExecStart = "${pkgs.brltty}/bin/brltty --no-daemon";
Type = "notify";
TimeoutStartSec = 5;
TimeoutStopSec = 10;
Restart = "always";
RestartSec = 30;
Nice = -10;
OOMScoreAdjust = -900;
ProtectHome = "read-only";
ProtectSystem = "full";
SystemCallArchitectures = "native";
};
wants = [ "systemd-udev-settle.service" ];
after = [ "local-fs.target" "systemd-udev-settle.service" ];
before = [ "sysinit.target" ];
wantedBy = [ "sysinit.target" ];
users.users.brltty = {
description = "BRLTTY daemon user";
group = "brltty";
};
users.groups = {
brltty = { };
brlapi = { };
};
systemd.services."brltty@".serviceConfig =
{ ExecStartPre = "!${genApiKey}"; };
# Install all upstream-provided files
systemd.packages = [ pkgs.brltty ];
systemd.tmpfiles.packages = [ pkgs.brltty ];
services.udev.packages = [ pkgs.brltty ];
environment.systemPackages = [ pkgs.brltty ];
# Add missing WantedBys (see issue #81138)
systemd.paths.brltty.wantedBy = targets;
systemd.paths."brltty@".wantedBy = targets;
};
}

Loading…
Cancel
Save