mirror of
https://github.com/nix-community/home-manager
synced 2024-11-30 15:09:46 +01:00
5f433eb164
Before, loading a module would be guarded by an optional platform condition. This made it possible to avoid loading and evaluating a module if it did not support the host platform. Unfortunately, this made it impossible to share a single configuration between GNU/Linux and Darwin hosts, which some wish to do. This removes the conditional load and instead inserts host platform assertions in the modules that are platform specific. Fixes #1906
47 lines
1.5 KiB
Nix
47 lines
1.5 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.targets.darwin;
|
|
homeDir = config.home.homeDirectory;
|
|
confFile = pkgs.writeText "DefaultKeybinding.dict"
|
|
(lib.generators.toPlist { } cfg.keybindings);
|
|
in {
|
|
options.targets.darwin.keybindings = mkOption {
|
|
type = with types; attrsOf anything;
|
|
default = { };
|
|
example = {
|
|
"^u" = "deleteToBeginningOfLine:";
|
|
"^w" = "deleteWordBackward:";
|
|
};
|
|
description = ''
|
|
This will configure the default keybindings for text fields in macOS
|
|
applications. See
|
|
<link xlink:href="https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html">Apple's documentation</link>
|
|
for more details.
|
|
|
|
<warning>
|
|
<para>
|
|
Existing keybinding configuration will be wiped when using this
|
|
option.
|
|
</para>
|
|
</warning>
|
|
'';
|
|
};
|
|
|
|
config = mkIf (cfg.keybindings != { }) {
|
|
assertions = [
|
|
(hm.assertions.assertPlatform "targets.darwin.keybindings" pkgs
|
|
platforms.darwin)
|
|
];
|
|
|
|
# NOTE: just copy the files because symlinks won't be recognized by macOS
|
|
home.activation.setCocoaKeybindings =
|
|
hm.dag.entryAfter [ "writeBoundary" ] ''
|
|
$VERBOSE_ECHO "Configuring keybindings for the Cocoa Text System"
|
|
$DRY_RUN_CMD install -Dm644 $VERBOSE_ARG \
|
|
"${confFile}" "${homeDir}/Library/KeyBindings/DefaultKeyBinding.dict"
|
|
'';
|
|
};
|
|
}
|