nixos-config/modules/home-manager/services/plover.nix

91 lines
2.4 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
2022-03-09 13:06:27 +00:00
let
cfg = config.services.plover;
toPloverINI = with lib;
generators.toINI {
2022-11-19 03:05:31 +00:00
mkKeyValue = generators.mkKeyValueDefault
{
mkValueString = v:
if v == true then
"True"
else if v == false then
"False"
else
generators.mkValueStringDefault { } v;
} " = ";
2022-03-09 13:06:27 +00:00
};
2022-11-19 03:05:31 +00:00
ploverIniFormat = {}: {
2022-03-09 13:06:27 +00:00
type = (pkgs.formats.ini { }).type;
generate = name: value: pkgs.writeText name (toPloverINI value);
};
settingsFormat = ploverIniFormat { };
settingsFile = settingsFormat.generate "plover-config-${config.home.username}" cfg.settings;
2022-11-19 03:05:31 +00:00
in
{
2022-03-09 13:06:27 +00:00
options.services.plover = {
enable = lib.mkEnableOption "Plover stenography engine service";
package = lib.mkOption {
type = lib.types.package;
description = "The derivation containing the binaries for the service.";
2022-03-09 13:06:27 +00:00
default = pkgs.plover.dev;
defaultText = "pkgs.plover.dev";
example = lib.literalExpression "pkgs.plover.stable";
};
settings = lib.mkOption {
type = settingsFormat.type;
description = "Configuration to be used for the application.";
default = { };
defaultText = lib.literalExpression "{}";
example = {
"Output Configuration" = {
undo_levels = 100;
};
2022-03-09 13:06:27 +00:00
"Stroke Display" = {
show = true;
};
};
2022-03-09 13:06:27 +00:00
};
extraOptions = lib.mkOption {
type = with lib.types; listOf str;
description =
"Extra command-line arguments to pass to {command}`plover`";
2022-03-09 13:06:27 +00:00
default = [ ];
defaultText = lib.literalExpression "[]";
example = lib.literalExpression ''
[ "--gui none" ]
'';
};
};
config = lib.mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "services.plover" pkgs
lib.platforms.linux)
];
home.packages = [ cfg.package ];
xdg.configFile."plover/plover.cfg".source = lib.mkIf (cfg.settings != { }) settingsFile;
2022-03-09 13:06:27 +00:00
systemd.user.services.plover = {
Unit = {
Description = "Plover stenography engine";
Documentation = [ "https://github.com/openstenoproject/plover/wiki/" ];
2022-04-06 02:48:29 +00:00
PartOf = "default.target";
2022-03-09 13:06:27 +00:00
};
Service.ExecStart = "${lib.getExe' cfg.package "plover"} ${lib.concatStringsSep " " cfg.extraOptions}";
2022-03-09 13:06:27 +00:00
Install.WantedBy = [ "default.target" ];
};
};
}