summaryrefslogtreecommitdiffstats
path: root/internal/checks.nix
blob: f1de8a505636501e0ac65615941341cd3c58e17e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{
  pkgs,
  self ? ../.,
}: let
  hjemTest =
    # The first argument to this function is the test module itself
    test:
      (pkgs.testers.runNixOSTest {
        defaults.documentation.enable = pkgs.lib.mkDefault false;
        imports = [test];
      }).config.result;

  inherit (pkgs.lib.filesystem) packagesFromDirectoryRecursive;

  prefixAttrs = prefix: pkgs.lib.mapAttrs' (name: pkgs.lib.nameValuePair "${prefix}-${name}");

  checks =
    prefixAttrs "nixos" (packagesFromDirectoryRecursive {
      callPackage = pkgs.newScope (checks
        // {
          inherit hjemTest;
          hjemModule = (import (self + "/modules/nixos")).default;
        });
      directory = ../tests/nixos;
    })
    // {
      # Formatting checks to run as a part of 'nix flake check' or manually
      # via 'nix build .#checks.<system>.formatting'.
      formatting =
        pkgs.runCommandLocal "hjem-formatting-check" {
          nativeBuildInputs = [pkgs.alejandra];
        } ''
          alejandra --check ${self}
          touch $out;
        '';
    };
in
  checks