0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-19 08:31:01 +03:00
nixpkgs/nixos/modules/services/misc/languagetool.nix
Silvan Mosberger d9d87c5196 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \
      --argstr baseRev 0128fbb0a5
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:29:24 +01:00

104 lines
3 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.languagetool;
settingsFormat = pkgs.formats.javaProperties { };
in
{
options.services.languagetool = {
enable = lib.mkEnableOption "the LanguageTool server, a multilingual spelling, style, and grammar checker that helps correct or paraphrase texts";
package = lib.mkPackageOption pkgs "languagetool" { };
port = lib.mkOption {
type = lib.types.port;
default = 8081;
example = 8081;
description = ''
Port on which LanguageTool listens.
'';
};
public = lib.mkEnableOption "access from anywhere (rather than just localhost)";
allowOrigin = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "https://my-website.org";
description = ''
Set the Access-Control-Allow-Origin header in the HTTP response,
used for direct (non-proxy) JavaScript-based access from browsers.
`null` to allow access from all sites.
'';
};
settings = lib.mkOption {
type = lib.types.submodule {
freeformType = settingsFormat.type;
options.cacheSize = lib.mkOption {
type = lib.types.ints.unsigned;
default = 1000;
apply = toString;
description = "Number of sentences cached.";
};
};
default = { };
description = ''
Configuration file options for LanguageTool, see
'languagetool-http-server --help'
for supported settings.
'';
};
jrePackage = lib.mkPackageOption pkgs "jre" { };
jvmOptions = lib.mkOption {
description = ''
Extra command line options for the JVM running languagetool.
More information can be found here: https://docs.oracle.com/en/java/javase/19/docs/specs/man/java.html#standard-options-for-java
'';
default = [ ];
type = lib.types.listOf lib.types.str;
example = [
"-Xmx512m"
];
};
};
config = lib.mkIf cfg.enable {
systemd.services.languagetool = {
description = "LanguageTool HTTP server";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
DynamicUser = true;
User = "languagetool";
Group = "languagetool";
CapabilityBoundingSet = [ "" ];
RestrictNamespaces = [ "" ];
SystemCallFilter = [
"@system-service"
"~ @privileged"
];
ProtectHome = "yes";
Restart = "on-failure";
ExecStart = ''
${cfg.jrePackage}/bin/java \
-cp ${cfg.package}/share/languagetool-server.jar \
${toString cfg.jvmOptions} \
org.languagetool.server.HTTPServer \
--port ${toString cfg.port} \
${lib.optionalString cfg.public "--public"} \
${lib.optionalString (cfg.allowOrigin != null) "--allow-origin ${cfg.allowOrigin}"} \
"--config" ${settingsFormat.generate "languagetool.conf" cfg.settings}
'';
};
};
};
}