diff --git a/flake.lock b/flake.lock index 99dc115..431d147 100644 --- a/flake.lock +++ b/flake.lock @@ -234,11 +234,11 @@ "nix-secrets": { "flake": false, "locked": { - "lastModified": 1721656822, - "narHash": "sha256-85jL6CvmxPloZDL313Eezu8mcEeGM+YzonlYyshz3w0=", + "lastModified": 1722196383, + "narHash": "sha256-2tU2b8YFpMtHe/YKFS8SmQiJCqnZ12hvc8KKspBBXRY=", "ref": "refs/heads/main", - "rev": "5f2de4bcc3be600a26db59334186537a23c4693b", - "revCount": 54, + "rev": "39cb0b58584e4763879310c779f75e30dd0b778a", + "revCount": 55, "type": "git", "url": "file:./nix-secrets" }, diff --git a/hosts/Dimaga/default.nix b/hosts/Dimaga/default.nix index b2e4363..5ccba11 100644 --- a/hosts/Dimaga/default.nix +++ b/hosts/Dimaga/default.nix @@ -181,6 +181,13 @@ in token = config.secrets.services.forgejo.runner-token; }; }; + languagetool = { + enable = true; + ngrams.enable = true; + domain = config.secrets.networking.primaryDomain; + password = config.secrets.services.languagetool.password; + url = config.secrets.services.languagetool.url; + }; msmtp.enable = true; nginx = { enable = true; diff --git a/modules/services/languagetool.nix b/modules/services/languagetool.nix new file mode 100644 index 0000000..14eb1a5 --- /dev/null +++ b/modules/services/languagetool.nix @@ -0,0 +1,66 @@ +{ + pkgs, + config, + lib, + ... +}: +let + cfg = config.aux.system.services.languagetool; +in +{ + options = { + aux.system.services.languagetool = { + enable = lib.mkEnableOption (lib.mdDoc "Enables LanguageTool server."); + ngrams.enable = lib.mkEnableOption ( + lib.mdDoc "Enables n-gram data set. See https://dev.languagetool.org/finding-errors-using-n-gram-data.html" + ); + domain = lib.mkOption { + default = ""; + type = lib.types.str; + description = "The root domain that LanguageTool will be hosted on."; + example = "example.com"; + }; + password = lib.mkOption { + default = ""; + type = lib.types.str; + description = "The password to use for basic authentication for LanguageTool."; + example = "MySuperSecurePassword123"; + }; + 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; + port = 8090; + public = true; + allowOrigin = "*"; + # Enable Ngrams + settings.languageModel = lib.mkIf cfg.ngrams.enable "${ + (pkgs.callPackage ../../packages/languagetool-ngrams.nix { inherit pkgs lib; }) + }/ngrams"; + }; + # Create Nginx virtualhost + nginx.virtualHosts."${cfg.url}" = { + useACMEHost = cfg.domain; + forceSSL = true; + basicAuth = { + ltuser = cfg.password; + }; + locations."/" = { + proxyPass = "http://127.0.0.1:8090"; + extraConfig = "proxy_ssl_server_name on;"; + }; + }; + }; + + systemd.services.nginx.wants = [ config.systemd.services.languagetool.name ]; + }; +} diff --git a/nix-secrets b/nix-secrets index 5f2de4b..39cb0b5 160000 --- a/nix-secrets +++ b/nix-secrets @@ -1 +1 @@ -Subproject commit 5f2de4bcc3be600a26db59334186537a23c4693b +Subproject commit 39cb0b58584e4763879310c779f75e30dd0b778a