summaryrefslogtreecommitdiff
path: root/module.nix
diff options
context:
space:
mode:
authorCaroline Larimore <caroline@larimo.re>2025-12-30 17:45:15 -0800
committerCaroline Larimore <caroline@larimo.re>2025-12-30 17:45:15 -0800
commit537806174f58a1ca5b5f6044772d1772b5fb2296 (patch)
tree1cc4a428348341e83920c63cfbf9b17d57e3d29e /module.nix
parent54dbcdd211e5da854675655fea1942aae36c52f7 (diff)
feat: nixos module
Diffstat (limited to 'module.nix')
-rw-r--r--module.nix41
1 files changed, 41 insertions, 0 deletions
diff --git a/module.nix b/module.nix
new file mode 100644
index 0000000..a50b62a
--- /dev/null
+++ b/module.nix
@@ -0,0 +1,41 @@
+inputs: { options, config, lib, pkgs, ... }:
+
+with lib; let
+ inherit (pkgs.stdenv.hostPlatform) system;
+ cfg = config.services.k95aux;
+ isEmpty = attr: length (attrNames attr) == 0;
+in {
+ options.services.k95aux = with types; {
+ enable = mkEnableOption "Auxillary Corsair K95 keys";
+ package = mkOption {
+ type = package;
+ default = inputs.self.packages.${system}.k95aux;
+ };
+ mapping = mkOption {
+ type = attrsOf types.ints.u8;
+ default = {};
+ };
+ };
+
+ config = let
+ mapping = strings.concatMapAttrsStringSep "\n" (key: code: "${key} ${toString code}") cfg.mapping;
+ in mkIf cfg.enable {
+ systemd.services.k95aux = {
+ description = "Auxillary Corsair K95 keys service";
+ wantedBy = [ "multi-user.target" ];
+
+ serviceConfig = {
+ ExecStart = "${cfg.package}/bin/k95aux";
+ Restart = "on-failure";
+ };
+
+ restartTriggers = [
+ mapping
+ ];
+ };
+
+ environment.etc = mkIf (!isEmpty cfg.mapping) {
+ "k95aux/mapping".text = mapping;
+ };
+ };
+}