Add the tool "nixos-typecheck" that can check an option declaration to:

- Enforce that an option declaration has a "defaultText" if and only if the
   type of the option derives from "package", "packageSet" or "nixpkgsConfig"
   and if a "default" attribute is defined.

 - Enforce that the value of the "example" attribute is wrapped with "literalExample"
   if the type of the option derives from "package", "packageSet" or "nixpkgsConfig".

 - Warn if a "defaultText" is defined in an option declaration if the type of
   the option does not derive from "package", "packageSet" or "nixpkgsConfig".

 - Warn if no "type" is defined in an option declaration.
This commit is contained in:
Thomas Strobel
2016-02-29 01:09:00 +01:00
parent c483224c82
commit cad8957eab
24 changed files with 703 additions and 127 deletions
+1
View File
@@ -5,6 +5,7 @@ with lib;
let
maintainer = mkOptionType {
name = "maintainer";
typerep = "(maintainer)";
check = email: elem email (attrValues lib.maintainers);
merge = loc: defs: listToAttrs (singleton (nameValuePair (last defs).file (last defs).value));
};
+27 -24
View File
@@ -3,32 +3,35 @@
with lib;
let
isConfig = x:
builtins.isAttrs x || builtins.isFunction x;
optCall = f: x:
if builtins.isFunction f
then f x
else f;
mergeConfig = lhs_: rhs_:
nixpkgsConfig = pkgs:
let
lhs = optCall lhs_ { inherit pkgs; };
rhs = optCall rhs_ { inherit pkgs; };
isConfig = x:
builtins.isAttrs x || builtins.isFunction x;
optCall = f: x:
if builtins.isFunction f
then f x
else f;
mergeConfig = lhs_: rhs_:
let
lhs = optCall lhs_ { inherit pkgs; };
rhs = optCall rhs_ { inherit pkgs; };
in
lhs // rhs //
optionalAttrs (lhs ? packageOverrides) {
packageOverrides = pkgs:
optCall lhs.packageOverrides pkgs //
optCall (attrByPath ["packageOverrides"] ({}) rhs) pkgs;
};
in
lhs // rhs //
optionalAttrs (lhs ? packageOverrides) {
packageOverrides = pkgs:
optCall lhs.packageOverrides pkgs //
optCall (attrByPath ["packageOverrides"] ({}) rhs) pkgs;
mkOptionType {
name = "nixpkgs config";
typerep = "(nixpkgsConfig)";
check = lib.traceValIfNot isConfig;
merge = config: args: fold (def: mergeConfig def.value) {};
defaultValues = [{}];
};
configType = mkOptionType {
name = "nixpkgs config";
check = traceValIfNot isConfig;
merge = args: fold (def: mergeConfig def.value) {};
};
in
{
@@ -46,7 +49,7 @@ in
};
}
'';
type = configType;
type = nixpkgsConfig pkgs;
description = ''
The configuration of the Nix Packages collection. (For
details, see the Nixpkgs documentation.) It allows you to set