1
0
Fork 0
nix-configuration/modules/nixos/services/languagetool/default.nix

73 lines
2 KiB
Nix
Raw Normal View History

2024-09-28 20:39:57 +00:00
{
pkgs,
config,
lib,
2024-12-06 16:46:10 +00:00
namespace,
2024-09-28 20:39:57 +00:00
...
}:
let
2024-12-06 16:46:10 +00:00
cfg = config.${namespace}.services.languagetool;
2024-09-28 20:39:57 +00:00
in
{
options = {
2024-12-06 16:46:10 +00:00
${namespace}.services.languagetool = {
2024-09-28 20:39:57 +00:00
enable = lib.mkEnableOption (lib.mdDoc "Enables LanguageTool server.");
auth = {
password = lib.mkOption {
default = "";
type = lib.types.str;
description = "The password to use for basic authentication for LanguageTool.";
example = "MySuperSecurePassword123";
};
user = lib.mkOption {
default = "ltuser";
type = lib.types.str;
description = "The username to use for basic auth.";
};
};
ngrams.enable = lib.mkEnableOption (
lib.mdDoc "Enables n-gram data set. See https://dev.languagetool.org/finding-errors-using-n-gram-data.html"
);
port = lib.mkOption {
default = 8080;
type = lib.types.int;
description = "The port to run LanguageTool on.";
example = 8080;
};
url = lib.mkOption {
default = "";
type = lib.types.str;
description = "The complete URL where LanguageTool is hosted.";
example = "https://languagetool.example.com";
};
};
};
config = lib.mkIf cfg.enable {
services = {
languagetool = lib.mkIf cfg.enable {
enable = true;
2024-09-28 21:15:39 +00:00
port = cfg.port;
2024-09-28 20:39:57 +00:00
public = true;
allowOrigin = "*";
# Enable Ngrams
2024-12-06 16:16:58 +00:00
settings.languageModel = lib.mkIf cfg.ngrams.enable "${pkgs.Sapana.languagetool-ngrams}/share/languagetool/ngrams";
2024-09-28 20:39:57 +00:00
};
# Create Nginx virtualhost
nginx.virtualHosts."${cfg.url}" = {
2024-12-06 16:16:58 +00:00
useACMEHost = lib.Sapana.getDomainFromURI cfg.url;
2024-09-28 20:39:57 +00:00
forceSSL = true;
basicAuth = {
"${cfg.auth.user}" = cfg.auth.password;
};
locations."/" = {
2024-09-28 21:15:39 +00:00
proxyPass = "http://127.0.0.1:${builtins.toString cfg.port}";
2024-09-28 20:39:57 +00:00
extraConfig = "proxy_ssl_server_name on;";
};
};
};
systemd.services.nginx.wants = [ config.systemd.services.languagetool.name ];
};
}