Jump to
The currently recommended, cross-platform solution to compiling KMonad is to use the stack Haskell project manager.
Once you have stack
installed, you can build kmonad
thusly:
stack build # To build only the binary
stack haddock # To build the binary and the docs
If you would like stack
to automatically copy the binary to a folder on your
$PATH
, you can use:
stack install # Builds *and* copies
If you use the Nix package manager, either
because you installed it yourself or because you are using NixOS, you can build
kmonad
using the following command.
nix-build nix
Another option with nix
is to use the nix-shell
to ensure you have the
correct environment to run stack
in. You can enter the development environment
using:
nix-shell nix/shell.nix
Note: we do also have to compile a little bit of C-code, so make sure gcc
is
installed as well.
Every now and then we compile and release a static binary for Linux that should
run on any Linux regardless of the installed libraries (i.e. ldd
returns not a dynamic executable
). If, for some reason, you want to compile a static binary for the state of HEAD yourself, please copy the contents of ./nix/static
into the kmonad
project root, and then call:
$(nix-build --no-link -A fullBuildScript)
I have little experience with Haskell under windows, but I managed to compile
kmonad
under Windows10 using a Haskell platform
installation. I also needed to install
mingw to provide gcc
. With both the Haskell platform and
mingw
building kmonad
under Windows10 should as simple as stack build
.
kmonad supports macOS 10.12 to 10.15 (Sierra, High Sierra, Mojave, and Catalina). Support for macOS 11.0 (Big Sur) is in progress.
Note: under macOS, kmonad
uses a kernel
extension
(kext) to post modified key events to the OS. It is bundled with
kmonad as a submodule in c_src/mac/Karabiner-VirtualHIDDevice
.
You can either build the kext from source or you can install it as a binary that is signed by its maintainer. Building from source is difficult, and macOS won't load your kext unless you sign it with an "Apple Developer ID," so we recommend installing the kext as a signed binary.
The kext used by kmonad is maintained as part of
Karabiner-Elements.
Therefore, if you use Karabiner-Elements, you already have the kext
installed (though maybe a different version number). Run kextstat | grep Karabiner
to check the version: if
org.pqrs.driver.Karabiner.VirtualHIDDevice.v061000 (6.10.0)
is
listed, then the installed kext is compatibile with kmonad and you can
move onto installing kmonad. If another version
is listed, this may work too (but has not been tested).
If you want to attempt building and signing the kext yourself, look to the documentation for instructions. Otherwise, to install the kext as a signed binary, run:
git clone --recursive https://github.com/david-janssen/kmonad.git
cd c_src/mac/Karabiner-VirtualHIDDevice
make install
Compilation under Mac currently works with stack
. Compilation under
Mac via nix
is not tested or planned. Installation under Mac via
Hackage is not tested, but may work for the adveturous. To compile on
Mac, download the kmonad source:
git clone --recursive https://github.com/david-janssen/kmonad.git
Then build kmonad with stack
:
stack build --extra-include-dirs=c_src/mac/Karabiner-VirtualHIDDevice/dist/include
Since Mac OS X Leopard (10.5), intercepting key events
requires
root privilege. Therefore, you must run kmonad as root (using sudo
,
e.g.). In the future, privilege separation may be implemented so that
just a small part of kmonad requires root privilege to run.
Since macOS Catalina (10.15), capturing key events requires explicit
permission in System Preferences
. Enable the application(s) that you
will be using to execute kmonad in System Preferences
> Security & Privacy
> Privacy
> Input Monitoring
.
You can download binaries for Windows and Linux (64bit) from the releases page. Many thanks to these lovely people for making this possible.
Some people have gone out of their way to add kmonad
into the package-managers of various distros. If you want to add kmonad
to your distro and add a pull-request to update the documentation to reflect that, please feel free.
NOTE: These packages might be out of date.
You can install kmonad
via xbps-install
:
xbps-install -s kmonad
You can install kmonad
via the guix
package manager. you will need to copy
the udev rules into place manually.
guix install kmonad
sudo cp $(guix build kmonad)/lib/udev/rules.d/70-kmonad.rules /lib/udev/rules.d/
If you use the guix system to manage your entire machine, you will instead want
to install udev rules using something like this in your config.scm
(use-modules (gnu packages haskell-apps))
(operating-system
;; ...
(services
(modify-services %desktop-services
(udev-service-type config =>
(udev-configuration (inherit config)
(rules (cons kmonad
(udev-configuration-rules config))))))))
There is not currently a kmonad
package in nixpkgs
, however the following instructions show
how to create your own adhoc derivation, and how to configure udev rules in nixos. There is also a NixOS module included in this repository that can be used instead of a manual configuration.
Create a kmonad.nix
derivation such as this one which fetches a static binary release of kmonad and packages it in the nix-store:
let
pkgs = import <nixpkgs> { };
kmonad-bin = pkgs.fetchurl {
url = "https://github.com/david-janssen/kmonad/releases/download/0.3.0/kmonad-0.3.0-linux";
sha256 = "4545b0823dfcffe0c4f0613916a6f38a0ccead0fb828c837de54971708bafc0b";
};
in
pkgs.runCommand "kmonad" {}
''
#!${pkgs.stdenv.shell}
mkdir -p $out/bin
cp ${kmonad-bin} $out/bin/kmonad
chmod +x $out/bin/*
''
- Import
kmonad.nix
into yourconfiguration.nix
file using alet
expression:
let
kmonad = import /path/to/kmonad.nix;
in {
<your_config>
}
- Add
kmonad
toenvironment.systemPackages
:
environment.systemPackages = with pkgs; [
...
kmonad
...
];
- Create the
uinput
group and add your user touinput
andinput
:
users.groups = { uinput = {}; };
users.extraUsers.userName = {
...
extraGroups = [ ... "input" "uinput" ];
};
- Add
udev
rules:
services.udev.extraRules =
''
# KMonad user access to /dev/uinput
KERNEL=="uinput", MODE="0660", GROUP="uinput", OPTIONS+="static_node=uinput"
'';
- Rebuild system:
sudo nixos-rebuild switch
-
Clone this repository or copy the file
nix/nixos-module.nix
somewhere to your system. -
Add
nixos-module.nix
into yourconfiguration.nix
as an import:
imports =
[
/path/to/nixos-module.nix;
];
- Configure the module:
services.kmonad = {
enable = true; # disable to not run kmonad at startup
configfile = /path/to/config.kbd;
# Modify the following line if you copied nixos-module.nix elsewhere or if you want to use the derivation described above
# package = import /pack/to/kmonad.nix;
};
- If you've set
enable = true;
at the previous step, do not put asetxkbmap
line in yourconfig.kbd
. Instead, set the options like this:
services.xserver = {
xkbOptions = "compose:ralt";
layout = "us";
};
- If you want your main user to use kmonad, add it to the
uinput
andinput
groups:
users.extraUsers.userName = {
...
extraGroups = [ ... "input" "uinput" ];
};
- Rebuild system:
sudo nixos-rebuild switch