From 537806174f58a1ca5b5f6044772d1772b5fb2296 Mon Sep 17 00:00:00 2001 From: Caroline Larimore Date: Tue, 30 Dec 2025 17:45:15 -0800 Subject: feat: nixos module --- module.nix | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 module.nix (limited to 'module.nix') 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; + }; + }; +} -- cgit v1.2.3