Nix example
Additional nginx module for markdown filter
{ pkgs, lib, ...}: {
name = "ngx_markdown_filter_module";
src = pkgs.fetchFromGitHub {
owner = "ukarim";
repo = "ngx_markdown_filter_module";
rev = "0.1.6";
sha256 = "sha256-c3+Z5sX+s9EXj9ZLhgVIkDqgIX58mZTwSklY8Cpvl4Q=";
postFetch = ''
# Configure to use the cmark-gfm library.
# The SSI module should run before the markdown module.
rm $out/config $out/config_gfm
cat >$out/config <<"CONFIG"
ngx_module_type=HTTP_FILTER
ngx_module_name=ngx_markdown_filter_module
ngx_module_srcs="$ngx_addon_dir/ngx_markdown_filter_module.c"
ngx_module_libs="-lcmark-gfm -lcmark-gfm-extensions"
ngx_module_order="ngx_markdown_filter_module ngx_http_ssi_filter_module"
. auto/module
ngx_addon_name=$ngx_module_name
echo "#define WITH_CMARK_GFM 1" >> $NGX_AUTO_CONFIG_H
# ngx_module_order doesn't work with static modules,
# so we must re-order filters here.
# Copied from https://github.com/google/ngx_brotli/blob/master/filter/config
if [ "$ngx_module_link" != DYNAMIC ]; then
HTTP_FILTER_MODULES=`echo $HTTP_FILTER_MODULES \
| sed "s/$ngx_module_name//" \
| sed "s/ngx_http_gzip_filter_module/ngx_http_gzip_filter_module $ngx_module_name/"`
fi
CONFIG
'';
};
inputs = [ pkgs.cmark-gfm ];
meta = with lib; {
license = with licenses; [ mit ];
maintainers = with maintainers; [ yvesf ];
};
}
Usage
services.nginx = {
additionalModules = [ (import ./ngx_markdown_module.nix { inherit pkgs lib; }) ];
virtualHosts = {
"pages.example.com" = {
forceSSL = true;
enableACME = true;
extraConfig = ''
server_tokens off;
location ~ ^/(.+(\.md))$ {
ssi on;
markdown_filter on;
markdown_unsafe on;
ssi_types *;
}
'';
};
};
};