Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite meta-check.nix type checking logic. #37252

Closed
wants to merge 14 commits into from

Commits on Mar 19, 2018

  1. lib: add types-simple

    A simple type system to check plain nix values.
    Please see the module comments for further explanations.
    
    Will be used to correct the buggy meta-field checks and help in sanity-checking
    other parts of nixpkgs.
    Profpatsch committed Mar 19, 2018
    Configuration menu
    Copy the full SHA
    b75602d View commit details
    Browse the repository at this point in the history
  2. lib/types-simple: add productOpt and defaults

    productOpt: a product type with the possibility for optional fields
    defaults: generate (semi-arbitrary) default values for a given type
    
    In preparation for the rewrite of `check-meta.nix`.
    Profpatsch committed Mar 19, 2018
    Configuration menu
    Copy the full SHA
    0ec18b2 View commit details
    Browse the repository at this point in the history
  3. stdenv/generic/check-meta: rewrite type checking code

    The previous code used some ad-hoc attribute enumeration to check for missing
    fields and did not really type check the attributes, because it used `t.check`
    from the module system types, which only does shallow checks for nested types,
    e.g. just `builtins.isList` for (listOf strings).
    
    This new version uses `types-simple` to recursively check every attribute,
    outputting accurate information for type errors in nested fields, e.g.:
    
    Package ‘hello-2.10’ in … has an invalid meta attrset:
    maintainers.1.email should be: string
    but is: null
    
    When we set
    meta.maintainers [ eelco foobar ];
    in `hello/default.nix` and foobar is defined as
    { name = "foobar"; email = null; };
    in `maintainers-list.nix`.
    
    The path accurately pins down where the type check failed:
    In the `maintainers` field, the second element of the list (counting from 0)
    and the field email in that element.
    
    Further work: If an unsupported meta field is used, the type error will print
    the complete type of the meta product, which is quite big. The type error should
    show a diff of the problematic fields in that case.
    This is possible but not yet integrated into the type checking logic.
    Profpatsch committed Mar 19, 2018
    Configuration menu
    Copy the full SHA
    4812142 View commit details
    Browse the repository at this point in the history
  4. check-meta: unify meta.licenses attribute type

    The meta type is changed to either a string, a license or a list of licenses,
    where license is an attrset with required `fullName`, `shortName` and `free`
    fields, and two optional fields.
    
    Every package that does not conform to this union type is fixed; I noticed that
    only a few packages used `list of strings`, so I corrected them and removed the
    alternative.
    Profpatsch committed Mar 19, 2018
    Configuration menu
    Copy the full SHA
    7435fa2 View commit details
    Browse the repository at this point in the history
  5. lib/types-simple: add lots more (inline) documentation

    Especially document the inner workings of the `checkType` function.
    Profpatsch committed Mar 19, 2018
    Configuration menu
    Copy the full SHA
    8729bda View commit details
    Browse the repository at this point in the history
  6. lib/types-simple: remove defaults & small improvement

    `defaults` originally only was a crutch to make products accept optional
    attributes shallowly, but that has been replaced by `productOpt`, so we don’t
    need it anymore.
    
    Also a few other changes based on input by @aszlig.
    Profpatsch committed Mar 19, 2018
    Configuration menu
    Copy the full SHA
    eefcd09 View commit details
    Browse the repository at this point in the history
  7. lib/types-simple: add restrict

    `restrict` is able to restrict the inhabitants of a type, meaning only a subset
    of a type is allowed, the new type is “smaller”, but still gives nice type
    errors if a nested value has the wrong type.
    
    See the tests for some usage examples.
    Profpatsch committed Mar 19, 2018
    Configuration menu
    Copy the full SHA
    85f28ff View commit details
    Browse the repository at this point in the history

Commits on Mar 31, 2018

  1. lib/types-simple: enable “open” products

    Open products can have additional fields in the actual value, which always
    succeed in the type check (effectively default to `any`).
    Profpatsch committed Mar 31, 2018
    Configuration menu
    Copy the full SHA
    8fc5946 View commit details
    Browse the repository at this point in the history
  2. lib/types-simple: assert req and opt are disjunct

    When defining a `productOpt` type, `req` and `opt` must not contain the same
    fields, otherwise the type checking behaviour is undefined.
    Profpatsch committed Mar 31, 2018
    Configuration menu
    Copy the full SHA
    f3bca07 View commit details
    Browse the repository at this point in the history

Commits on Apr 1, 2018

  1. Configuration menu
    Copy the full SHA
    589d1c5 View commit details
    Browse the repository at this point in the history

Commits on Apr 25, 2018

  1. Configuration menu
    Copy the full SHA
    99ce0d4 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    c872eec View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    58a32c8 View commit details
    Browse the repository at this point in the history
  4. lib/types-simple: remove names attribute

    `names` was originally intended to be able to match on the specific instance of
    a type, but it breaks the abstraction in a way.
    Since the function that used it was removed, we can remove the name attributes
    as well.
    Profpatsch committed Apr 25, 2018
    Configuration menu
    Copy the full SHA
    b7e4e0a View commit details
    Browse the repository at this point in the history