query
On this page

addCheck

lib.types.addCheck

Docs pulled from | This Revision | 31 minutes ago


Nixpkgs manual

Augment the given type with an additional type check function.

This function has some broken behavior see: #396021 Fixing is not trivial, we appreciate any help!

Adding a type check

{
  byte = mkOption {
    description = "An integer between 0 and 255.";
    type = types.addCheck types.int (x: x >= 0 && x <= 255);
  };
}

Noogle detected

Implementation

The following is the current implementation of this function.

addCheck =
    elemType: check:
    if elemType.merge ? v2 then
      elemType
      // {
        check = {
          __functor = _self: x: elemType.check x && check x;
          isV2MergeCoherent = true;
        };
        merge = {
          __functor =
            self: loc: defs:
            (self.v2 { inherit loc defs; }).value;
          v2 =
            { loc, defs }@args:
            let
              orig = checkV2MergeCoherence loc elemType (elemType.merge.v2 args);
              headError' = if orig.headError != null then orig.headError else checkDefsForError check loc defs;
            in
            orig
            // {
              headError = headError';
            };
        };
      }
    else
      elemType
      // {
        check = x: elemType.check x && check x;
      };