about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorLin Jian <me@linj.tech>2024-05-24 02:53:42 +0800
committerGitHub <noreply@github.com>2024-05-24 02:53:42 +0800
commit4be6150a4c875ae6f9768a102d95174b33d99729 (patch)
treef40ef190b354473664b66e450cf60364fe140ab3 /nixos
parentd836a3e678084140b951392a4e2d76f92cd97ff1 (diff)
parentd679ddfcab7ffe85f66f81d70ffd64e6e0951b1e (diff)
Merge pull request #313822 from linj-fork/pr/kanata-config-file
nixos/kanata: add a configFile option
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/services/hardware/kanata.nix23
1 files changed, 21 insertions, 2 deletions
diff --git a/nixos/modules/services/hardware/kanata.nix b/nixos/modules/services/hardware/kanata.nix
index 46af3e36b9859..60fb33881f256 100644
--- a/nixos/modules/services/hardware/kanata.nix
+++ b/nixos/modules/services/hardware/kanata.nix
@@ -7,7 +7,7 @@ let
 
   upstreamDoc = "See [the upstream documentation](https://github.com/jtroo/kanata/blob/main/docs/config.adoc) and [example config files](https://github.com/jtroo/kanata/tree/main/cfg_samples) for more information.";
 
-  keyboard = {
+  keyboard = { name, config, ... }: {
     options = {
       devices = mkOption {
         type = types.listOf types.str;
@@ -48,6 +48,21 @@ let
           ${upstreamDoc}
         '';
       };
+      configFile = mkOption {
+        type = types.path;
+        default = mkConfig name config;
+        defaultText =
+          "A config file generated by values from other kanata module options.";
+        description = ''
+          The config file.
+
+          By default, it is generated by values from other kanata
+          module options.
+
+          You can also set it to your own full config file which
+          overrides all other kanata module options.  ${upstreamDoc}
+        '';
+      };
       extraArgs = mkOption {
         type = types.listOf types.str;
         default = [ ];
@@ -85,6 +100,10 @@ let
 
       ${keyboard.config}
     '';
+    # Only the config file generated by this module is checked.  A
+    # user-provided one is not checked because it may not be available
+    # at build time.  I think this is a good balance between module
+    # complexity and functionality.
     checkPhase = ''
       ${getExe cfg.package} --cfg "$target" --check --debug
     '';
@@ -96,7 +115,7 @@ let
       Type = "notify";
       ExecStart = ''
         ${getExe cfg.package} \
-          --cfg ${mkConfig name keyboard} \
+          --cfg ${keyboard.configFile} \
           --symlink-path ''${RUNTIME_DIRECTORY}/${name} \
           ${optionalString (keyboard.port != null) "--port ${toString keyboard.port}"} \
           ${utils.escapeSystemdExecArgs keyboard.extraArgs}