services-flake/nix/nginx/nginx_test.nix
2024-05-09 21:56:38 +05:30

44 lines
1.1 KiB
Nix

{ pkgs, config, ... }: {
services.nginx."nginx1" = {
enable = true;
httpConfig = ''
server {
listen 8888;
include ../../importedconfig.conf;
}
'';
};
settings.processes =
{
init = {
command = pkgs.writeShellApplication {
runtimeInputs = [ pkgs.coreutils ];
text = ''
cat >importedconfig.conf <<EOL
location / {
add_header Content-Type text/plain;
return 200 'Looks good';
}
EOL
'';
name = "init";
};
};
test =
let
cfg = config.services.nginx."nginx1";
in
{
command = pkgs.writeShellApplication {
runtimeInputs = [ cfg.package pkgs.gnugrep pkgs.curl ];
text = ''
curl -s -H "Accept: text/plain" http://127.0.0.1:8888 | grep -q "Looks good"
'';
name = "nginx-test";
};
depends_on."nginx1".condition = "process_healthy";
};
} // { "nginx1".depends_on."init".condition = "process_completed"; };
}