modules/generic/meta-maintainers: init

This factors out `meta.maintainers` from NixOS `misc/meta.nix` for use in arbitrary
Module System applications.

It is useful beyond NixOS and not coupled to it, although it is currently coupled to Nixpkgs'
`lib.maintainers`.
That restriction could be lifted optionally if there's future demand.

Changed files
+101 -46
modules
generic
meta-maintainers
nixos
modules
misc
+61
modules/generic/meta-maintainers.nix
···
+
# Test:
+
# ./meta-maintainers/test.nix
+
{ lib, ... }:
+
let
+
inherit (lib)
+
mkOption
+
mkOptionType
+
types
+
;
+
+
maintainer = mkOptionType {
+
name = "maintainer";
+
check = email: lib.elem email (lib.attrValues lib.maintainers);
+
merge =
+
loc: defs:
+
lib.listToAttrs (lib.singleton (lib.nameValuePair (lib.last defs).file (lib.last defs).value));
+
};
+
+
listOfMaintainers = types.listOf maintainer // {
+
merge =
+
loc: defs:
+
lib.zipAttrs (
+
lib.flatten (
+
lib.imap1 (
+
n: def:
+
lib.imap1 (
+
m: def':
+
maintainer.merge (loc ++ [ "[${toString n}-${toString m}]" ]) [
+
{
+
inherit (def) file;
+
value = def';
+
}
+
]
+
) def.value
+
) defs
+
)
+
);
+
};
+
in
+
{
+
_class = null; # not specific to NixOS
+
options = {
+
meta = {
+
maintainers = mkOption {
+
type = listOfMaintainers;
+
default = [ ];
+
example = lib.literalExpression ''[ lib.maintainers.alice lib.maintainers.bob ]'';
+
description = ''
+
List of maintainers of each module.
+
This option should be defined at most once per module.
+
+
The option value is not a list of maintainers, but an attribute set that maps module file names to lists of maintainers.
+
'';
+
};
+
};
+
};
+
meta.maintainers = with lib.maintainers; [
+
pierron
+
roberth
+
];
+
}
+34
modules/generic/meta-maintainers/test.nix
···
+
# Run:
+
# $ nix-instantiate --eval 'modules/generic/meta-maintainers/test.nix'
+
#
+
# Expected output:
+
# { }
+
#
+
# Debugging:
+
# drop .test from the end of this file, then use nix repl on it
+
rec {
+
lib = import ../../../lib;
+
+
example = lib.evalModules {
+
modules = [
+
../meta-maintainers.nix
+
{
+
_file = "eelco.nix";
+
meta.maintainers = [ lib.maintainers.eelco ];
+
}
+
];
+
};
+
+
test =
+
assert
+
example.config.meta.maintainers == {
+
${toString ../meta-maintainers.nix} = [
+
lib.maintainers.pierron
+
lib.maintainers.roberth
+
];
+
"eelco.nix" = [ lib.maintainers.eelco ];
+
};
+
{ };
+
+
}
+
.test
+6 -46
nixos/modules/misc/meta.nix
···
{ lib, ... }:
let
-
maintainer = lib.mkOptionType {
-
name = "maintainer";
-
check = email: lib.elem email (lib.attrValues lib.maintainers);
-
merge =
-
loc: defs:
-
lib.listToAttrs (lib.singleton (lib.nameValuePair (lib.last defs).file (lib.last defs).value));
-
};
-
-
listOfMaintainers = lib.types.listOf maintainer // {
-
# Returns list of
-
# { "module-file" = [
-
# "maintainer1 <first@nixos.org>"
-
# "maintainer2 <second@nixos.org>" ];
-
# }
-
merge =
-
loc: defs:
-
lib.zipAttrs (
-
lib.flatten (
-
lib.imap1 (
-
n: def:
-
lib.imap1 (
-
m: def':
-
maintainer.merge (loc ++ [ "[${toString n}-${toString m}]" ]) [
-
{
-
inherit (def) file;
-
value = def';
-
}
-
]
-
) def.value
-
) defs
-
)
-
);
-
};
-
docFile = lib.types.path // {
# Returns tuples of
# { file = "module location"; value = <path/to/doc.xml>; }
···
in
{
+
imports = [ ../../../modules/generic/meta-maintainers.nix ];
+
options = {
meta = {
-
maintainers = lib.mkOption {
-
type = listOfMaintainers;
-
internal = true;
-
default = [ ];
-
example = lib.literalExpression ''[ lib.maintainers.alice ]'';
-
description = ''
-
List of maintainers of each module. This option should be defined at
-
most once per module.
-
'';
-
};
-
doc = lib.mkOption {
type = docFile;
internal = true;
···
};
};
-
meta.maintainers = lib.singleton lib.maintainers.pierron;
+
meta.maintainers = with lib.maintainers; [
+
pierron
+
roberth
+
];
}