Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xcompose: add module #918

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ let
(loadModule ./services/window-managers/i3.nix { })
(loadModule ./services/window-managers/xmonad.nix { })
(loadModule ./services/xcape.nix { condition = hostPlatform.isLinux; })
(loadModule ./services/xcompose.nix { })
(loadModule ./services/xembed-sni-proxy.nix { condition = hostPlatform.isLinux; })
(loadModule ./services/xscreensaver.nix { })
(loadModule ./services/xsuspender.nix { condition = hostPlatform.isLinux; })
Expand Down
49 changes: 49 additions & 0 deletions modules/services/xcompose.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{ config, lib, pkgs, ... }:

with lib;

let
xComposeType = with types; either (attrsOf xComposeType) str;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't have recursive types. Perhaps once lazyAttrsOf is available?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll wait then

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lazyAttrsOf has been merged in NixOS/nixpkgs#70138.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info


cfg = config.xsession.xCompose;

xComposeGen = (
dic: s: lib.mapAttrs
(
n: v:
if
(builtins.isString v)
then
''${s}<${n}> : "${v}"''
else
(xComposeGen v (''${s}<${n}> ''))
) dic
);

in
{
options.xsession.xCompose = {
enable = mkEnableOption "XCompose";
combinations = mkOption {
description = "Add compose key combinations";
type = xComposeType;
default = {};
example = literalExample ''
{
Multi_key = {
G = { A = "Α"; B = "Β";};
g = { a = "α"; b = "β";};
};
}'';
};

};

config = (
mkIf (cfg.enable == true) {
home.file.".XCompose".text = ''
include "%L"
${builtins.concatStringsSep "\n" (lib.collect builtins.isString (xComposeGen cfg.combinations ""))}'';
}
);
}