Skip to content

Commit

Permalink
lib/maintainer-list: Implement validity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
infinisil committed Apr 13, 2020
1 parent a90d8de commit f579564
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
75 changes: 75 additions & 0 deletions lib/tests/maintainers.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# to run these tests:
# nix-build nixpkgs/lib/tests/maintainers.nix
# If nothing is output, all tests passed
{ pkgs ? import ../.. {} }:

let
inherit (pkgs) lib;
inherit (lib) types;

maintainerModule = { config, ... }: {
options = {
name = lib.mkOption {
type = types.str;
};
email = lib.mkOption {
type = types.str;
};
github = lib.mkOption {
type = types.nullOr types.str;
default = null;
};
githubId = lib.mkOption {
type = types.nullOr types.ints.unsigned;
default = null;
};
keys = lib.mkOption {
type = types.listOf (types.submodule {
options.longkeyid = lib.mkOption { type = types.str; };
options.fingerprint = lib.mkOption { type = types.str; };
});
default = [];
};
};
};

checkMaintainer = handle: uncheckedAttrs:
let
prefix = [ "lib" "maintainers" handle ];
checkedAttrs = (lib.modules.evalModules {
inherit prefix;
modules = [
maintainerModule
{
_file = toString ../../maintainers/maintainer-list.nix;
config = uncheckedAttrs;
}
];
}).config;

checkGithubId = lib.optional (checkedAttrs.github != null && checkedAttrs.githubId == null) ''
echo ${lib.escapeShellArg (lib.showOption prefix)}': If `github` is specified, `githubId` must be too.'
# Calling this too often would hit non-authenticated API limits, but this
# shouldn't happen since such errors will get fixed rather quickly
info=$(curl -sS https://api.github.com/users/${checkedAttrs.github})
id=$(jq -r '.id' <<< "$info")
echo "The GitHub ID for GitHub user ${checkedAttrs.github} is $id:"
echo -e " githubId = $id;\n"
'';
in lib.deepSeq checkedAttrs checkGithubId;

missingGithubIds = lib.concatLists (lib.mapAttrsToList checkMaintainer lib.maintainers);

success = pkgs.runCommandNoCC "checked-maintainers-success" {} ">$out";

failure = pkgs.runCommandNoCC "checked-maintainers-failure" {
nativeBuildInputs = [ pkgs.curl pkgs.jq ];
outputHash = "sha256:${lib.fakeSha256}";
outputHAlgo = "sha256";
outputHashMode = "flat";
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
} ''
${lib.concatStringsSep "\n" missingGithubIds}
exit 1
'';
in if missingGithubIds == [] then success else failure
2 changes: 1 addition & 1 deletion lib/tests/release.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ pkgs ? import ../.. {} }:

pkgs.runCommandNoCC "nixpkgs-lib-tests" {
buildInputs = [ pkgs.nix (import ./check-eval.nix) ];
buildInputs = [ pkgs.nix (import ./check-eval.nix) (import ./maintainers.nix { inherit pkgs; }) ];
NIX_PATH = "nixpkgs=${toString pkgs.path}";
} ''
datadir="${pkgs.nix}/share"
Expand Down

0 comments on commit f579564

Please sign in to comment.