nixpkgs-suyu/nixos/modules/services/hardware/brltty.nix
rnhmjoj da2923b4f8
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.
2021-04-11 10:35:16 +02:00

57 lines
1.2 KiB
Nix

{ config, lib, pkgs, ... }:
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 = {
services.brltty.enable = mkOption {
type = types.bool;
default = false;
description = "Whether to enable the BRLTTY daemon.";
};
};
config = mkIf cfg.enable {
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;
};
}