From 3139f8ae792cfba5bf3dcf81c92fd8540bc328f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Mon, 24 Apr 2023 15:14:35 +0100 Subject: [PATCH] add nginx service --- src/modules/services/nginx.nix | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/modules/services/nginx.nix diff --git a/src/modules/services/nginx.nix b/src/modules/services/nginx.nix new file mode 100644 index 000000000..42b0aa7a0 --- /dev/null +++ b/src/modules/services/nginx.nix @@ -0,0 +1,64 @@ +{ pkgs, lib, config, ... }: + +let + cfg = config.services.nginx; + configFile = pkgs.writeText "nginx.conf" '' + pid ${config.env.DEVENV_STATE}/nginx/nginx.pid; + error_log stderr debug; + daemon off; + + events { + ${cfg.eventsConfig} + } + + http { + access_log off; + client_body_temp_path ${config.env.DEVENV_STATE}/nginx/; + proxy_temp_path ${config.env.DEVENV_STATE}/nginx/; + fastcgi_temp_path ${config.env.DEVENV_STATE}/nginx/; + scgi_temp_path ${config.env.DEVENV_STATE}/nginx/; + uwsgi_temp_path ${config.env.DEVENV_STATE}/nginx/; + + ${cfg.httpConfig} + } + ''; +in +{ + options.services.nginx = { + enable = lib.mkEnableOption "nginx"; + + package = lib.mkOption { + type = lib.types.package; + default = pkgs.nginx; + defaultText = "pkgs.nginx"; + description = "The nginx package to use."; + }; + + httpConfig = lib.mkOption { + type = lib.types.lines; + default = ""; + description = "The nginx configuration."; + }; + + eventsConfig = lib.mkOption { + type = lib.types.lines; + default = ""; + description = "The nginx events configuration."; + }; + + configFile = lib.mkOption { + type = lib.types.path; + default = configFile; + internal = true; + description = "The nginx configuration file."; + }; + }; + + config = lib.mkIf cfg.enable { + processes.nginx.exec = "${cfg.package}/bin/nginx -c ${cfg.configFile} -e /dev/stderr"; + + enterShell = '' + mkdir -p ${config.env.DEVENV_STATE}/nginx + ''; + }; +}