Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mrVanDalo/nixos-healthchecks

Write health checks as NixOS options to quickly verify if your services are properly running.
https://github.com/mrVanDalo/nixos-healthchecks

flake-parts healthchecks nixos

Last synced: 5 days ago
JSON representation

Write health checks as NixOS options to quickly verify if your services are properly running.

Awesome Lists containing this project

README

        

# NixOS health checks

NixOS flake to write health checks as options, intended to be written right next
to the service definitions to verify right after deployment or whenever you like
if your services are running correctly.

![](example.gif)

## How to define checks

You can define checks using the (newly introduced) `healthchecks`
[NixOS Option](https://search.nixos.org/options).

### Check the http responses

```nix
healthchecks.http.nextcloud = {
url = "https://example.com/login";
expectedContent = "Login";
};
```

### check if a port is actually closed

```nix
healthchecks.closed.public.host = "example.com";
healthchecks.closed.public.ports.opentelemetry = [ 4317 ];
```

### custom command

```nix
healthchecks.localCommand.bashTest = pkgs.writers.writeBash "test" ''
echo "this is a bash test"
'';
healthchecks.localCommand.pythonTest = pkgs.writers.writePython "test" {} ''
print("this is a python test")
'';
```

**Failure** or **Success** is decided on **exit code** of the script. The output
of the command will only be printed if the **exit code** is not 0.

## How to set up with flake parts

You have to import the `healthchecks.flakeModule` and the
`healthchecks.nixosModules.default`.

```nix
{

inputs = {
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
flake-parts.url = "github:hercules-ci/flake-parts";
healthchecks.inputs.nixpkgs.follows = "nixpkgs";
healthchecks.url = "github:mrvandalo/nixos-healthchecks";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};

outputs =
inputs@{
flake-parts,
healthchecks,
nixpkgs,
self,
}:

flake-parts.lib.mkFlake { inherit inputs; } (
{ }:
{
systems = [ "x86_64-linux" ]; # feel free to use other systems

# 1. import healthchecks flakeModule
imports = [ healthchecks.flakeModule ];

flake = {
nixosConfigurations.example = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration.nix

# 2. import healthchecks nixosModule
healthchecks.nixosModules.default
];
};
};
}
);
}
```