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.
This commit is contained in:
rnhmjoj 2021-03-01 12:11:22 +01:00
parent 13375265e4
commit da2923b4f8
No known key found for this signature in database
GPG Key ID: BFBAF4C975F76450

@ -5,6 +5,19 @@ with lib;
let let
cfg = config.services.brltty; 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 { in {
options = { options = {
@ -18,33 +31,27 @@ in {
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
users.users.brltty = {
systemd.services.brltty = { description = "BRLTTY daemon user";
description = "Braille Device Support"; group = "brltty";
unitConfig = { };
Documentation = "http://mielke.cc/brltty/"; users.groups = {
DefaultDependencies = "no"; brltty = { };
RequiresMountsFor = "${pkgs.brltty}/var/lib/brltty"; brlapi = { };
};
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" ];
}; };
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;
}; };
} }