1# to run these tests (and the others)
2# nix-build nixpkgs/lib/tests/release.nix
3{ # The pkgs used for dependencies for the testing itself
4 pkgs
5, lib
6}:
7
8let
9 inherit (lib) types;
10
11 maintainerModule = { config, ... }: {
12 options = {
13 name = lib.mkOption {
14 type = types.str;
15 };
16 email = lib.mkOption {
17 type = types.str;
18 };
19 matrix = lib.mkOption {
20 type = types.nullOr types.str;
21 default = null;
22 };
23 github = lib.mkOption {
24 type = types.nullOr types.str;
25 default = null;
26 };
27 githubId = lib.mkOption {
28 type = types.nullOr types.ints.unsigned;
29 default = null;
30 };
31 keys = lib.mkOption {
32 type = types.listOf (types.submodule {
33 options.longkeyid = lib.mkOption { type = types.str; };
34 options.fingerprint = lib.mkOption { type = types.str; };
35 });
36 default = [];
37 };
38 };
39 };
40
41 checkMaintainer = handle: uncheckedAttrs:
42 let
43 prefix = [ "lib" "maintainers" handle ];
44 checkedAttrs = (lib.modules.evalModules {
45 inherit prefix;
46 modules = [
47 maintainerModule
48 {
49 _file = toString ../../maintainers/maintainer-list.nix;
50 config = uncheckedAttrs;
51 }
52 ];
53 }).config;
54
55 checkGithubId = lib.optional (checkedAttrs.github != null && checkedAttrs.githubId == null) ''
56 echo ${lib.escapeShellArg (lib.showOption prefix)}': If `github` is specified, `githubId` must be too.'
57 # Calling this too often would hit non-authenticated API limits, but this
58 # shouldn't happen since such errors will get fixed rather quickly
59 info=$(curl -sS https://api.github.com/users/${checkedAttrs.github})
60 id=$(jq -r '.id' <<< "$info")
61 echo "The GitHub ID for GitHub user ${checkedAttrs.github} is $id:"
62 echo -e " githubId = $id;\n"
63 '';
64 in lib.deepSeq checkedAttrs checkGithubId;
65
66 missingGithubIds = lib.concatLists (lib.mapAttrsToList checkMaintainer lib.maintainers);
67
68 success = pkgs.runCommand "checked-maintainers-success" {} ">$out";
69
70 failure = pkgs.runCommand "checked-maintainers-failure" {
71 nativeBuildInputs = [ pkgs.curl pkgs.jq ];
72 outputHash = "sha256:${lib.fakeSha256}";
73 outputHAlgo = "sha256";
74 outputHashMode = "flat";
75 SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
76 } ''
77 ${lib.concatStringsSep "\n" missingGithubIds}
78 exit 1
79 '';
80in if missingGithubIds == [] then success else failure