synix/modules/nixos/ollama/default.nix
sid ecf5132cbb
Some checks failed
Build tests / build-hosts (pull_request) Failing after 3s
Flake check / flake-check (pull_request) Failing after 13s
enforce new flake schema. formatting.
2026-05-31 18:50:41 +02:00

47 lines
1.1 KiB
Nix

{ config, lib, ... }:
let
cfg = config.services.ollama;
inherit (config.networking) domain;
inherit (cfg.reverseProxy) subdomain;
fqdn = if (cfg.reverseProxy.enable && subdomain != "") then "${subdomain}.${domain}" else domain;
inherit (lib)
mkDefault
mkForce
mkIf
;
inherit (lib.utils)
mkReverseProxyOption
mkVirtualHost
;
in
{
options.services.ollama = {
reverseProxy = mkReverseProxyOption "Ollama" "ollama";
};
config = mkIf cfg.enable {
services.ollama = {
host = mkDefault (if cfg.reverseProxy.enable then "127.0.0.1" else "0.0.0.0");
user = mkDefault "ollama";
group = mkDefault "ollama";
};
services.nginx.virtualHosts = mkIf cfg.reverseProxy.enable {
"${fqdn}" = mkVirtualHost {
inherit (cfg) port;
ssl = cfg.reverseProxy.forceSSL;
recommendedProxySettings = mkForce false;
extraConfig = ''
proxy_set_header Host ${cfg.host}:${toString cfg.port};
'';
};
};
systemd.tmpfiles.rules = [
"d ${cfg.home} 0755 ${cfg.user} ${cfg.group} -"
];
};
}