Skip to content

Code

Pre-requisites

You will need to have the following installed:

Important

We use a Flake-based workflow. You can certainly develop for nixos-facter without Flakes and leverage much of what is listed below, but it is left up to the reader to determine how to make that work.

Formatting

We use treefmt and treefmt-nix to format the repository by running nix fmt from the root directory.

nix/formatter.nix
{ pkgs, inputs, ... }:
let
  hasNixFmt = pkgs.lib.meta.availableOn pkgs.stdenv.buildPlatform pkgs.nixfmt-rfc-style.compiler;
in
inputs.treefmt-nix.lib.evalModule pkgs {
  projectRootFile = ".git/config";

  programs = {
    nixfmt.enable = hasNixFmt;
    nixfmt.package = pkgs.nixfmt-rfc-style;

    deadnix.enable = true;
    prettier.enable = true;
    statix.enable = true;
  };

  settings = {
    global.excludes = [
      "LICENSE"
      "*.narHash"
      # unsupported extensions
      "*.{gif,png,svg,tape,mts,lock,mod,sum,toml,env,envrc,gitignore}"
    ];

    formatter = {
      deadnix = {
        priority = 1;
      };

      statix = {
        priority = 2;
      };

      nixfmt = pkgs.lib.mkIf hasNixFmt { priority = 3; };

      prettier = {
        options = [
          "--tab-width"
          "4"
        ];
        includes = [ "*.{css,html,js,json,jsx,md,mdx,scss,ts,yaml}" ];
      };
    };
  };
}

Checks

Running nix flake check will build all the devshells and Nix packages, as well as check the formatting with treefmt and any other Flake checks that have been configured.

Documentation

When making changes, it is important to add or update any relevant sections in the documentation within the same pull request.

For more information see the next section.