1 { config, pkgs, lib, ... }:
3 cfg = config.hardware.openrazer;
4 kernelPackages = config.boot.kernelPackages;
6 toPyBoolStr = b: if b then "True" else "False";
8 daemonExe = "${pkgs.openrazer-daemon}/bin/openrazer-daemon --config ${daemonConfFile}";
10 daemonConfFile = pkgs.writeTextFile {
14 verbose_logging = ${toPyBoolStr cfg.verboseLogging}
17 sync_effects_enabled = ${toPyBoolStr cfg.syncEffectsEnabled}
18 devices_off_on_screensaver = ${toPyBoolStr cfg.devicesOffOnScreensaver}
19 battery_notifier = ${toPyBoolStr cfg.batteryNotifier.enable}
20 battery_notifier_freq = ${builtins.toString cfg.batteryNotifier.frequency}
21 battery_notifier_percent = ${builtins.toString cfg.batteryNotifier.percentage}
24 key_statistics = ${toPyBoolStr cfg.keyStatistics}
28 dbusServiceFile = pkgs.writeTextFile rec {
29 name = "org.razer.service";
30 destination = "/share/dbus-1/services/${name}";
35 SystemdService=openrazer-daemon.service
50 hardware.openrazer = {
51 enable = lib.mkEnableOption ''
52 OpenRazer drivers and userspace daemon
55 verboseLogging = lib.mkOption {
56 type = lib.types.bool;
59 Whether to enable verbose logging. Logs debug messages.
63 syncEffectsEnabled = lib.mkOption {
64 type = lib.types.bool;
67 Set the sync effects flag to true so any assignment of
68 effects will work across devices.
72 devicesOffOnScreensaver = lib.mkOption {
73 type = lib.types.bool;
76 Turn off the devices when the systems screensaver kicks in.
80 batteryNotifier = lib.mkOption {
82 Settings for device battery notifications.
85 type = lib.types.submodule {
87 enable = lib.mkOption {
88 type = lib.types.bool;
91 Mouse battery notifier.
94 frequency = lib.mkOption {
98 How often battery notifications should be shown (in seconds).
99 A value of 0 disables notifications.
103 percentage = lib.mkOption {
104 type = lib.types.int;
107 At what battery percentage the device should reach before
108 sending notifications.
115 keyStatistics = lib.mkOption {
116 type = lib.types.bool;
119 Collects number of keypresses per hour per key used to
124 users = lib.mkOption {
125 type = with lib.types; listOf str;
128 Usernames to be added to the "openrazer" group, so that they
129 can start and interact with the OpenRazer userspace daemon.
136 (lib.mkRenamedOptionModule [ "hardware" "openrazer" "mouseBatteryNotifier" ] [ "hardware" "openrazer" "batteryNotifier" "enable" ])
139 config = lib.mkIf cfg.enable {
140 boot.extraModulePackages = [ kernelPackages.openrazer ];
141 boot.kernelModules = drivers;
143 # Makes the man pages available so you can successfully run
144 # > systemctl --user help openrazer-daemon
145 environment.systemPackages = [ pkgs.python3Packages.openrazer-daemon.man ];
147 services.udev.packages = [ kernelPackages.openrazer ];
148 services.dbus.packages = [ dbusServiceFile ];
150 # A user must be a member of the openrazer group in order to start
151 # the openrazer-daemon. Therefore we make sure that the group
153 users.groups.openrazer = {
157 systemd.user.services.openrazer-daemon = {
158 description = "Daemon to manage razer devices in userspace";
159 unitConfig.Documentation = "man:openrazer-daemon(8)";
160 # Requires a graphical session so the daemon knows when the screensaver
161 # starts. See the 'devicesOffOnScreensaver' option.
162 wantedBy = [ "graphical-session.target" ];
163 partOf = [ "graphical-session.target" ];
166 BusName = "org.razer";
167 ExecStart = "${daemonExe} --foreground";
174 maintainers = with lib.maintainers; [ roelvandijk ];