2020-04-24 23:36:52 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.hardware.openrazer;
|
|
|
|
kernelPackages = config.boot.kernelPackages;
|
|
|
|
|
|
|
|
toPyBoolStr = b: if b then "True" else "False";
|
|
|
|
|
|
|
|
daemonExe = "${pkgs.openrazer-daemon}/bin/openrazer-daemon --config ${daemonConfFile}";
|
|
|
|
|
|
|
|
daemonConfFile = pkgs.writeTextFile {
|
|
|
|
name = "razer.conf";
|
|
|
|
text = ''
|
|
|
|
[General]
|
|
|
|
verbose_logging = ${toPyBoolStr cfg.verboseLogging}
|
|
|
|
|
|
|
|
[Startup]
|
|
|
|
sync_effects_enabled = ${toPyBoolStr cfg.syncEffectsEnabled}
|
|
|
|
devices_off_on_screensaver = ${toPyBoolStr cfg.devicesOffOnScreensaver}
|
2024-05-15 15:35:15 +00:00
|
|
|
battery_notifier = ${toPyBoolStr cfg.batteryNotifier.enable}
|
|
|
|
battery_notifier_freq = ${builtins.toString cfg.batteryNotifier.frequency}
|
|
|
|
battery_notifier_percent = ${builtins.toString cfg.batteryNotifier.percentage}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
[Statistics]
|
|
|
|
key_statistics = ${toPyBoolStr cfg.keyStatistics}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dbusServiceFile = pkgs.writeTextFile rec {
|
|
|
|
name = "org.razer.service";
|
|
|
|
destination = "/share/dbus-1/services/${name}";
|
|
|
|
text = ''
|
|
|
|
[D-BUS Service]
|
|
|
|
Name=org.razer
|
|
|
|
Exec=${daemonExe}
|
|
|
|
SystemdService=openrazer-daemon.service
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
drivers = [
|
|
|
|
"razerkbd"
|
|
|
|
"razermouse"
|
|
|
|
"razerfirefly"
|
|
|
|
"razerkraken"
|
|
|
|
"razermug"
|
|
|
|
"razercore"
|
|
|
|
];
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
hardware.openrazer = {
|
2024-09-19 14:19:46 +00:00
|
|
|
enable = lib.mkEnableOption ''
|
2023-11-16 04:20:00 +00:00
|
|
|
OpenRazer drivers and userspace daemon
|
2024-04-21 15:54:59 +00:00
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
verboseLogging = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Whether to enable verbose logging. Logs debug messages.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
syncEffectsEnabled = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Set the sync effects flag to true so any assignment of
|
|
|
|
effects will work across devices.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
devicesOffOnScreensaver = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = true;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Turn off the devices when the systems screensaver kicks in.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
batteryNotifier = lib.mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2024-05-15 15:35:15 +00:00
|
|
|
Settings for device battery notifications.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
2024-05-15 15:35:15 +00:00
|
|
|
default = {};
|
2024-09-19 14:19:46 +00:00
|
|
|
type = lib.types.submodule {
|
2024-05-15 15:35:15 +00:00
|
|
|
options = {
|
2024-09-19 14:19:46 +00:00
|
|
|
enable = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2024-05-15 15:35:15 +00:00
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Mouse battery notifier.
|
|
|
|
'';
|
|
|
|
};
|
2024-09-19 14:19:46 +00:00
|
|
|
frequency = lib.mkOption {
|
|
|
|
type = lib.types.int;
|
2024-05-15 15:35:15 +00:00
|
|
|
default = 600;
|
|
|
|
description = ''
|
|
|
|
How often battery notifications should be shown (in seconds).
|
|
|
|
A value of 0 disables notifications.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
percentage = lib.mkOption {
|
|
|
|
type = lib.types.int;
|
2024-05-15 15:35:15 +00:00
|
|
|
default = 33;
|
|
|
|
description = ''
|
|
|
|
At what battery percentage the device should reach before
|
|
|
|
sending notifications.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
keyStatistics = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Collects number of keypresses per hour per key used to
|
|
|
|
generate a heatmap.
|
|
|
|
'';
|
|
|
|
};
|
2021-08-08 23:34:03 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
users = lib.mkOption {
|
|
|
|
type = with lib.types; listOf str;
|
2021-08-08 23:34:03 +00:00
|
|
|
default = [];
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2021-08-08 23:34:03 +00:00
|
|
|
Usernames to be added to the "openrazer" group, so that they
|
|
|
|
can start and interact with the OpenRazer userspace daemon.
|
|
|
|
'';
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
imports = [
|
2024-09-19 14:19:46 +00:00
|
|
|
(lib.mkRenamedOptionModule [ "hardware" "openrazer" "mouseBatteryNotifier" ] [ "hardware" "openrazer" "batteryNotifier" "enable" ])
|
2024-05-15 15:35:15 +00:00
|
|
|
];
|
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2020-04-24 23:36:52 +00:00
|
|
|
boot.extraModulePackages = [ kernelPackages.openrazer ];
|
|
|
|
boot.kernelModules = drivers;
|
|
|
|
|
2022-12-28 21:21:41 +00:00
|
|
|
# Makes the man pages available so you can successfully run
|
2020-04-24 23:36:52 +00:00
|
|
|
# > systemctl --user help openrazer-daemon
|
|
|
|
environment.systemPackages = [ pkgs.python3Packages.openrazer-daemon.man ];
|
|
|
|
|
|
|
|
services.udev.packages = [ kernelPackages.openrazer ];
|
|
|
|
services.dbus.packages = [ dbusServiceFile ];
|
|
|
|
|
2021-08-08 23:34:03 +00:00
|
|
|
# A user must be a member of the openrazer group in order to start
|
|
|
|
# the openrazer-daemon. Therefore we make sure that the group
|
|
|
|
# exists.
|
|
|
|
users.groups.openrazer = {
|
|
|
|
members = cfg.users;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
systemd.user.services.openrazer-daemon = {
|
|
|
|
description = "Daemon to manage razer devices in userspace";
|
|
|
|
unitConfig.Documentation = "man:openrazer-daemon(8)";
|
2024-05-15 15:35:15 +00:00
|
|
|
# Requires a graphical session so the daemon knows when the screensaver
|
|
|
|
# starts. See the 'devicesOffOnScreensaver' option.
|
|
|
|
wantedBy = [ "graphical-session.target" ];
|
|
|
|
partOf = [ "graphical-session.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "dbus";
|
|
|
|
BusName = "org.razer";
|
|
|
|
ExecStart = "${daemonExe} --foreground";
|
|
|
|
Restart = "always";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
maintainers = with lib.maintainers; [ roelvandijk ];
|
|
|
|
};
|
|
|
|
}
|