Loading lib/asserts.nix +29 −0 Original line number Diff line number Diff line Loading @@ -50,4 +50,33 @@ rec { lib.generators.toPretty {} xs}, but is: ${ lib.generators.toPretty {} val}"; /* Specialized `assertMsg` for checking if every one of `vals` is one of the elements of the list `xs`. Useful for checking lists of supported attributes. Example: let sslLibraries = [ "libressl" "bearssl" ]; in assertEachOneOf "sslLibraries" sslLibraries [ "openssl" "bearssl" ] stderr> error: each element in sslLibraries must be one of [ stderr> "openssl" stderr> "bearssl" stderr> ], but is: [ stderr> "libressl" stderr> "bearssl" stderr> ] Type: assertEachOneOf :: String -> List ComparableVal -> List ComparableVal -> Bool */ assertEachOneOf = # The name of the variable the user entered `val` into, for inclusion in the error message name: # The list of values of what the user provided, to be compared against the values in `xs` vals: # The list of valid values xs: assertMsg (lib.all (val: lib.elem val xs) vals) "each element in ${name} must be one of ${ lib.generators.toPretty {} xs}, but is: ${ lib.generators.toPretty {} vals}"; } Loading
lib/asserts.nix +29 −0 Original line number Diff line number Diff line Loading @@ -50,4 +50,33 @@ rec { lib.generators.toPretty {} xs}, but is: ${ lib.generators.toPretty {} val}"; /* Specialized `assertMsg` for checking if every one of `vals` is one of the elements of the list `xs`. Useful for checking lists of supported attributes. Example: let sslLibraries = [ "libressl" "bearssl" ]; in assertEachOneOf "sslLibraries" sslLibraries [ "openssl" "bearssl" ] stderr> error: each element in sslLibraries must be one of [ stderr> "openssl" stderr> "bearssl" stderr> ], but is: [ stderr> "libressl" stderr> "bearssl" stderr> ] Type: assertEachOneOf :: String -> List ComparableVal -> List ComparableVal -> Bool */ assertEachOneOf = # The name of the variable the user entered `val` into, for inclusion in the error message name: # The list of values of what the user provided, to be compared against the values in `xs` vals: # The list of valid values xs: assertMsg (lib.all (val: lib.elem val xs) vals) "each element in ${name} must be one of ${ lib.generators.toPretty {} xs}, but is: ${ lib.generators.toPretty {} vals}"; }