diff --git a/default.nix b/default.nix index 58a5ac2..fee9a0e 100644 --- a/default.nix +++ b/default.nix @@ -23,6 +23,8 @@ # add to top level because it has a binary feedvalidator = final.python312Packages.feedvalidator; + + mkNginxServer = prev.callPackage ./lib/dev-nginx {}; }) ]; } diff --git a/lib/dev-nginx/default.nix b/lib/dev-nginx/default.nix new file mode 100644 index 0000000..914670c --- /dev/null +++ b/lib/dev-nginx/default.nix @@ -0,0 +1,46 @@ +{ + writeText, + writeShellScriptBin, + + nginx, + systemd +}: + +{ siteConfig }: +let conf = writeText "nginx.conf" '' + daemon off; + events {} + pid /tmp/nginx.pid; + http { + access_log /dev/stdout; + + client_body_temp_path /tmp; + proxy_temp_path /tmp; + fastcgi_temp_path /tmp; + uwsgi_temp_path /tmp; + scgi_temp_path /tmp; + + include ${nginx}/conf/mime.types; + default_type application/octet-stream; + sendfile on; + + types_hash_max_size 4096; + types_hash_bucket_size 128; + + server { + server_name localhost; + listen 127.0.0.1:8080; + + gzip on; + gzip_min_length 256; + gzip_proxied expired no-cache no-store private auth; + gzip_types text/plain application/xml image/svg+xml text/css text/javascript; + + ${siteConfig} + } + } +''; +in + writeShellScriptBin "dev-nginx.sh" '' + exec ${systemd}/bin/systemd-run --user -t -pPrivateTmp=true --working-directory="$PWD" ${nginx}/bin/nginx -p "$PWD" -e stderr -c ${conf} + ''