6 releases

0.3.0 Apr 5, 2024
0.2.3 Oct 17, 2023
0.2.1 Sep 27, 2023
0.1.0 Sep 6, 2023

#290 in Filesystem

Download history 43/week @ 2024-02-12 13/week @ 2024-02-26 3/week @ 2024-03-11 102/week @ 2024-04-01 24/week @ 2024-04-08

126 downloads per month

Apache-2.0

34KB
734 lines


slug: /health

Nix Health

nix-health[^1] is a program that checks the health of your Nix install. Furthermore, individual projects can configure their own health checks in their flake.nix. For example, the nammayatri project checks that the cachix cache is in use.

[^1]: nix-health originally began as a script https://github.com/srid/nix-health which is now deprecated.

Checks performed

Check Configurable in flake.nix?
Flakes are enabled -
Nix version is not too old Yes
Nix runs natively (no rosetta)[^2] Yes
Builds use multiple cores (max-jobs) Yes
Nix Caches in use Yes
$USER is in trusted-users -
Direnv: installed and activated Yes
Min RAM / Disk space Yes

[^2]: This check is only performed on macOS with Apple Silicon.

Note that some checks are considered non-essential. For eg., the disk space check looks for 1TB+ disk space, but if the user is on a laptop with 256GB SSD, the check will report a warning instead of failing. This can also be configured in per-project basis from flake.nix (see below).

Usage

nix-health is still in development. To run the development version,

nix run "github:juspay/nix-health"

To run nix-health along with health check configuration specified in a project flake, pass that flake as an argument. For eg., to run nix-health with additional checks from the nammayatri project, run:

# The argument can be any flake URL (including a local path)
nix run "github:juspay/nix-health" github:nammayatri/nammayatri

Configuring in flake.nix {#conf}

To add project specific health checks or configure health checks, add the following flake output:

{
  outputs = inputs: {
    nix-health.default = {
      # Add configuration here
      caches.required = [ "https://ourproject.cachix.org" ];
    };
  };
}

To see all available configuration options, run nix-health --dump-schema. This will dump the schema of the configuration in JSON format. Convert that to a Nix attrset to see what can be added under the nix-health.default attrset of your flake.

$ nix-health --dump-schema > schema.json
$ nix eval --impure --expr 'builtins.fromJSON (builtins.readFile ./schema.json)' | nix run nixpkgs#alejandra -- --quiet
{
  caches = {required = ["https://cache.nixos.org/"];};
  direnv = {
    enable = true;
    required = false;
  };
  flake-enabled = {};
  max-jobs = {};
  nix-version = {min-required = "2.13.0";};
  rosetta = {
    enable = true;
    required = true;
  };
  system = {
    enable = true;
    min_disk_space = "1024.0 GB";
    min_ram = null;
    required = false;
  };
  trusted-users = {};
}

Dependencies

~15–31MB
~476K SLoC