Skip to content

Commit

Permalink
feat(aquaskk): add new Home Manager module
Browse files Browse the repository at this point in the history
  • Loading branch information
midchildan committed Nov 9, 2023
1 parent d030959 commit 0887862
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 18 deletions.
1 change: 1 addition & 0 deletions nix/home/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
imports = [
./profiles
./news.nix
./modules/aquaskk.nix
./modules/gnupg
./modules/emacs.nix
./modules/firefox.nix
Expand Down
109 changes: 109 additions & 0 deletions nix/home/modules/aquaskk.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{ config, lib, pkgs, dotfiles, ... }:

let
cfg = config.dotfiles.aquaskk;
dictTypes = [ "euc-jp" "online" "skkserv" "kotoeri" "program" "utf-8" ];

dictionarySet = lib.mapAttrsToList
(name: config: {
inherit (config) active location;
type =
let
index = dotfiles.lib.indexOf config.type dictTypes;
option = "dotfiles.aquaskk.dictionaries.${name}";
value = config.type;
in
if index >= 0 then index
else throw "Option '${option}' has unknown value '${value}'.";
})
cfg.dictionaries;
in
{
options.dotfiles.aquaskk = {
enable = lib.mkEnableOption "AquaSKK";

config = lib.mkOption {
type = with lib.types; attrsOf anything;
default = { };
description = ''
Configuration for AquaSKK. See the list of available options
[here](https://github.com/codefirst/aquaskk/blob/master/platform/mac/plist/UserDefaults.plist).
'';
};

dictionaries = lib.mkOption {
type = with lib.types; attrsOf (submodule ({ name, ... }: {
options = {
active = lib.mkOption {
type = bool;
default = true;
description = "Whether to enable the dictionary \"${name}\".";
};
location = lib.mkOption {
type = str;
default = name;
description = "Location of the dictionary \"${name}\".";
};
type = lib.mkOption {
type = enum dictTypes;
description = "Type of the dictionary \"${name}\".";
};
};
}));

default = {
"SKK-JISYO.L" = {
location = "${pkgs.skk-dicts}/share/SKK-JISYO.L";
type = "utf-8";
};
};

example = {
"~/.skk-jisyo".type = "euc-jp";
"SKK-JISYO.L".type = "online";
};

description = ''
Dictionaries to use for SKK conversion.
Dictionaries of type `online` will be fetched from
{option}`dotfiles.aquaskk.config.openlab_host`. The list of available
dictionaries can be seen at <https://skk-dev.github.io/dict/>.
::: {.warning}
Setting this option to a non-empty value will make the dictionary
settings immutable. Because of this, you won't be able to add or remove
dictionaries from the graphical UI.
:::
::: {.warning}
As of 4.7.5, [AquaSKK downloads dictionaries of the `online` type over
unverified HTTP connections][httpdict]. This means that the dictionaries
can be tampered with in transit. The consequences can range from messed
up SKK conversions to attempted attacks on any potential weaknesses in
the dictionary parsing code.
Prefer local dictionaries if malicious network operators are a concern.
:::
[httpdict]: https://github.com/codefirst/aquaskk/blob/4.7.5/src/engine/dictionary/SKKHttpDictionaryLoader.cpp#L59
'';
};
};

config = lib.mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "dotfiles.aquaskk" pkgs
lib.platforms.darwin)
];

targets.darwin.defaults = {
"jp.sourceforge.inputmethod.aquaskk.plist" = cfg.config;
};

home.file."Library/Application Support/AquaSKK/DictionarySet.plist" =
lib.mkIf (cfg.dictionaries != { }) {
text = lib.generators.toPlist { } dictionarySet;
};
};
}
6 changes: 6 additions & 0 deletions nix/home/news.nix
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,11 @@
macOS support for the syncthing module was upstreamed to Home Manager.
'';
}
{
time = "2023-11-08T19:00:56+00:00";
message = ''
A new module is available: 'dotfiles.aquaskk'
'';
}
];
}
11 changes: 11 additions & 0 deletions nix/home/profiles/macos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,16 @@ in
"^w" = mkDefault "deleteWordBackward:";
};
};

dotfiles.aquaskk = {
enable = mkDefault true;
config = {
beep_on_registration = mkDefault false;
enable_annotation = mkDefault true;
enable_dynamic_completion = mkDefault true;
enable_extended_completion = mkDefault true;
show_input_mode_icon = mkDefault true;
};
};
};
}
48 changes: 30 additions & 18 deletions nix/lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

let
inherit (inputs) self flake-utils home darwin nixpkgs nixos;
inherit (nixpkgs) lib;
inherit (home.lib) homeManagerConfiguration;
inherit (darwin.lib) darwinSystem;
inherit (nixpkgs.lib) importTOML mkDefault recursiveUpdate;
inherit (nixos.lib) nixosSystem;

nixpkgsArgs = {
Expand All @@ -13,7 +13,7 @@ let
};
in
rec {
config = importTOML ../config.toml;
config = lib.importTOML ../config.toml;

supportedPlatforms = [
"aarch64-darwin"
Expand Down Expand Up @@ -163,7 +163,7 @@ rec {
# Sets hardening options for systemd services.
#
hardenSystemdService = args:
recursiveUpdate args {
lib.recursiveUpdate args {
serviceConfig = {
# this enables the following options:
# - PrivateTmp = true
Expand All @@ -172,22 +172,34 @@ rec {
# - RestrictSUIDSGID = true
# - ProtectSystem = strict
# - ProtectHome = read-only
DynamicUser = mkDefault true;
DynamicUser = lib.mkDefault true;

PrivateDevices = mkDefault true;
PrivateUsers = mkDefault true;
ProtectHostname = mkDefault true;
ProtectClock = mkDefault true;
ProtectProc = mkDefault "invisible";
ProtectKernelTunables = mkDefault true;
ProtectKernelModules = mkDefault true;
ProtectKernelLogs = mkDefault true;
ProtectControlGroups = mkDefault true;
RestrictNamespaces = mkDefault true;
LockPersonality = mkDefault true;
MemoryDenyWriteExecute = mkDefault true;
RestrictRealtime = mkDefault true;
SystemCallFilter = mkDefault [ "@system-service" "~@mount" ];
PrivateDevices = lib.mkDefault true;
PrivateUsers = lib.mkDefault true;
ProtectHostname = lib.mkDefault true;
ProtectClock = lib.mkDefault true;
ProtectProc = lib.mkDefault "invisible";
ProtectKernelTunables = lib.mkDefault true;
ProtectKernelModules = lib.mkDefault true;
ProtectKernelLogs = lib.mkDefault true;
ProtectControlGroups = lib.mkDefault true;
RestrictNamespaces = lib.mkDefault true;
LockPersonality = lib.mkDefault true;
MemoryDenyWriteExecute = lib.mkDefault true;
RestrictRealtime = lib.mkDefault true;
SystemCallFilter = lib.mkDefault [ "@system-service" "~@mount" ];
};
};

indexOf = target: lib.foldl'
(index: el:
if index < 0 then
if el == target then
- index - 1
else
index - 1
else
index
)
(-1);
}

0 comments on commit 0887862

Please sign in to comment.