diff options
Diffstat (limited to 'nixpkgs/pkgs/stdenv/generic/check-meta.nix')
-rw-r--r-- | nixpkgs/pkgs/stdenv/generic/check-meta.nix | 85 |
1 files changed, 38 insertions, 47 deletions
diff --git a/nixpkgs/pkgs/stdenv/generic/check-meta.nix b/nixpkgs/pkgs/stdenv/generic/check-meta.nix index 62a6cd8ef02e..63c853e3dc31 100644 --- a/nixpkgs/pkgs/stdenv/generic/check-meta.nix +++ b/nixpkgs/pkgs/stdenv/generic/check-meta.nix @@ -13,17 +13,15 @@ let findFirst isDerivation length - mapAttrsToList - mergeDefinitions + concatMap mutuallyExclusive optional optionalAttrs optionalString optionals - remove - unknownModule isAttrs isString + mapAttrs ; inherit (lib.lists) @@ -283,44 +281,37 @@ let isEnabled = findFirst (x: x == reason) null showWarnings; in if isEnabled != null then builtins.trace msg true else true; - # Deep type-checking. Note that calling `type.check` is not enough: see `lib.mkOptionType`'s documentation. - # We don't include this in lib for now because this function is flawed: it accepts things like `mkIf true 42`. - typeCheck = type: value: let - merged = mergeDefinitions [ ] type [ - { file = unknownModule; inherit value; } - ]; - eval = builtins.tryEval (builtins.deepSeq merged.mergedValue null); - in eval.success; - - # TODO make this into a proper module and use the generic option documentation generation? metaTypes = let - inherit (lib.types) - anything - attrsOf - bool - either - int - listOf - mkOptionType - str - unspecified - ; - - platforms = listOf (either str (attrsOf anything)); # see lib.meta.platformMatch + types = import ./meta-types.nix { inherit lib; }; + inherit (types) str union int attrs attrsOf any listOf bool; + platforms = listOf (union [ str (attrsOf any) ]); # see lib.meta.platformMatch in { # These keys are documented description = str; mainProgram = str; longDescription = str; branch = str; - homepage = either (listOf str) str; + homepage = union [ + (listOf str) + str + ]; downloadPage = str; - changelog = either (listOf str) str; + changelog = union [ + (listOf str) + str + ]; license = let - licenseType = either (attrsOf anything) str; # TODO disallow `str` licenses, use a module - in either licenseType (listOf licenseType); - sourceProvenance = listOf lib.types.attrs; - maintainers = listOf (attrsOf anything); # TODO use the maintainer type from lib/tests/maintainer-module.nix + # TODO disallow `str` licenses, use a module + licenseType = union [ + (attrsOf any) + str + ]; + in union [ + (listOf licenseType) + licenseType + ]; + sourceProvenance = listOf attrs; + maintainers = listOf (attrsOf any); # TODO use the maintainer type from lib/tests/maintainer-module.nix priority = int; pkgConfigModules = listOf str; inherit platforms; @@ -329,16 +320,13 @@ let unfree = bool; unsupported = bool; insecure = bool; - # TODO: refactor once something like Profpatsch's types-simple will land - # This is currently dead code due to https://github.com/NixOS/nix/issues/2532 - tests = attrsOf (mkOptionType { + tests = { name = "test"; - check = x: x == {} || ( # Accept {} for tests that are unsupported + verify = x: x == {} || ( # Accept {} for tests that are unsupported isDerivation x && x ? meta.timeout ); - merge = lib.options.mergeOneOption; - }); + }; timeout = int; # Needed for Hydra to expose channel tarballs: @@ -354,7 +342,7 @@ let executables = listOf str; outputsToInstall = listOf str; position = str; - available = unspecified; + available = any; isBuildPythonPackage = platforms; schedulingPriority = int; isFcitxEngine = bool; @@ -363,17 +351,20 @@ let badPlatforms = platforms; }; - checkMetaAttr = k: v: + checkMetaAttr = let + # Map attrs directly to the verify function for performance + metaTypes' = mapAttrs (_: t: t.verify) metaTypes; + in k: v: if metaTypes?${k} then - if typeCheck metaTypes.${k} v then - null + if metaTypes'.${k} v then + [ ] else - "key 'meta.${k}' has invalid value; expected ${metaTypes.${k}.description}, got\n ${ + [ "key 'meta.${k}' has invalid value; expected ${metaTypes.${k}.name}, got\n ${ lib.generators.toPretty { indent = " "; } v - }" + }" ] else - "key 'meta.${k}' is unrecognized; expected one of: \n [${concatMapStringsSep ", " (x: "'${x}'") (attrNames metaTypes)}]"; - checkMeta = meta: optionals config.checkMeta (remove null (mapAttrsToList checkMetaAttr meta)); + [ "key 'meta.${k}' is unrecognized; expected one of: \n [${concatMapStringsSep ", " (x: "'${x}'") (attrNames metaTypes)}]" ]; + checkMeta = meta: optionals config.checkMeta (concatMap (attr: checkMetaAttr attr meta.${attr}) (attrNames meta)); checkOutputsToInstall = attrs: let expectedOutputs = attrs.meta.outputsToInstall or []; |