mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-10 16:45:51 +03:00
nixos/keyd: add support for multi-file configuration
Add `keyboards` option to define different configurations for different IDs. This creates the appropriate files in `/etc/keyd` instead of just `default.conf` as before. Add `23.11` release note entry. Add `mkRemovedOptionModule` for the old API with a note on how to revert the old behavior.
This commit is contained in:
parent
4a729ce4b1
commit
2d3bf20086
@ -60,6 +60,8 @@
|
||||
|
||||
- `util-linux` is now supported on Darwin and is no longer an alias to `unixtools`. Use the `unixtools.util-linux` package for access to the Apple variants of the utilities.
|
||||
|
||||
- `services.keyd` changed API. Now you can create multiple configuration files.
|
||||
|
||||
- `services.ddclient` has been removed on the request of the upstream maintainer because it is unmaintained and has bugs. Please switch to a different software like `inadyn` or `knsupdate`.
|
||||
|
||||
- The `vlock` program from the `kbd` package has been moved into its own package output and should now be referenced explicitly as `kbd.vlock` or replaced with an alternative such as the standalone `vlock` package or `physlock`.
|
||||
|
@ -3,12 +3,9 @@ with lib;
|
||||
let
|
||||
cfg = config.services.keyd;
|
||||
settingsFormat = pkgs.formats.ini { };
|
||||
in
|
||||
{
|
||||
options = {
|
||||
services.keyd = {
|
||||
enable = mkEnableOption (lib.mdDoc "keyd, a key remapping daemon");
|
||||
|
||||
keyboardOptions = { ... }: {
|
||||
options = {
|
||||
ids = mkOption {
|
||||
type = types.listOf types.string;
|
||||
default = [ "*" ];
|
||||
@ -35,24 +32,71 @@ in
|
||||
};
|
||||
};
|
||||
description = lib.mdDoc ''
|
||||
Configuration, except `ids` section, that is written to {file}`/etc/keyd/default.conf`.
|
||||
Configuration, except `ids` section, that is written to {file}`/etc/keyd/<keyboard>.conf`.
|
||||
Appropriate names can be used to write non-alpha keys, for example "equal" instead of "=" sign (see <https://github.com/NixOS/nixpkgs/issues/236622>).
|
||||
See <https://github.com/rvaiya/keyd> how to configure.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
(mkRemovedOptionModule [ "services" "keyd" "ids" ]
|
||||
''Use keyboards.<filename>.ids instead. If you don't need a multi-file configuration, just add keyboards.default before the ids. See https://github.com/NixOS/nixpkgs/pull/243271.'')
|
||||
(mkRemovedOptionModule [ "services" "keyd" "settings" ]
|
||||
''Use keyboards.<filename>.settings instead. If you don't need a multi-file configuration, just add keyboards.default before the settings. See https://github.com/NixOS/nixpkgs/pull/243271.'')
|
||||
];
|
||||
|
||||
options.services.keyd = {
|
||||
enable = mkEnableOption (lib.mdDoc "keyd, a key remapping daemon");
|
||||
|
||||
keyboards = mkOption {
|
||||
type = types.attrsOf (types.submodule keyboardOptions);
|
||||
default = { };
|
||||
example = literalExpression ''
|
||||
{
|
||||
default = {
|
||||
ids = [ "*" ];
|
||||
settings = {
|
||||
main = {
|
||||
capslock = "overload(control, esc)";
|
||||
};
|
||||
};
|
||||
};
|
||||
externalKeyboard = {
|
||||
ids = [ "1ea7:0907" ];
|
||||
settings = {
|
||||
main = {
|
||||
esc = capslock;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
'';
|
||||
description = mdDoc ''
|
||||
Configuration for one or more device IDs. Corresponding files in the /etc/keyd/ directory are created according to the name of the keys (like `default` or `externalKeyboard`).
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
environment.etc."keyd/default.conf".source = pkgs.runCommand "default.conf"
|
||||
{
|
||||
ids = ''
|
||||
[ids]
|
||||
${concatStringsSep "\n" cfg.ids}
|
||||
'';
|
||||
passAsFile = [ "ids" ];
|
||||
} ''
|
||||
cat $idsPath <(echo) ${settingsFormat.generate "keyd-main.conf" cfg.settings} >$out
|
||||
'';
|
||||
# Creates separate files in the `/etc/keyd/` directory for each key in the dictionary
|
||||
environment.etc = mapAttrs'
|
||||
(name: options:
|
||||
nameValuePair "keyd/${name}.conf" {
|
||||
source = pkgs.runCommand "${name}.conf"
|
||||
{
|
||||
ids = ''
|
||||
[ids]
|
||||
${concatStringsSep "\n" options.ids}
|
||||
'';
|
||||
passAsFile = [ "ids" ];
|
||||
} ''
|
||||
cat $idsPath <(echo) ${settingsFormat.generate "keyd-${name}.conf" options.settings} >$out
|
||||
'';
|
||||
})
|
||||
cfg.keyboards;
|
||||
|
||||
hardware.uinput.enable = lib.mkDefault true;
|
||||
|
||||
@ -62,9 +106,11 @@ in
|
||||
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
restartTriggers = [
|
||||
config.environment.etc."keyd/default.conf".source
|
||||
];
|
||||
restartTriggers = mapAttrsToList
|
||||
(name: options:
|
||||
config.environment.etc."keyd/${name}.conf".source
|
||||
)
|
||||
cfg.keyboards;
|
||||
|
||||
# this is configurable in 2.4.2, later versions seem to remove this option.
|
||||
# post-2.4.2 may need to set makeFlags in the derivation:
|
||||
|
@ -32,7 +32,7 @@ let
|
||||
nodes.machine = {
|
||||
services.keyd = {
|
||||
enable = true;
|
||||
inherit settings;
|
||||
keyboards.default = { inherit settings; };
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user