Skip to content

Remove or clean up builtins.toXML #15745

@numinit

Description

@numinit

Is your feature request related to a problem?

toXML has some surprises:

  • let x = [ x ]; in builtins.toXML x blows the stack and crashes the interpreter fixed now 👌
  • has "unique" formatting of floats that bypasses the normal toString logic, limiting the effectiveness of libexpr: unify toString for nan and inf #15704
  • lets you introspect the function args of lambdas in pure eval: functionArg = fn: if builtins.isFunction fn then let m = builtins.match ''^.*<varpat[[:space:]]+name="([^"]+)"[[:space:]]+/>.*$'' (builtins.toXML fn); in if m == null then null else builtins.head m else null
  • let you get the name of @args variables, as well as the ellipsis flag for formal parameterized functions, which builtins.functionArgs cannot do (so we have created a weird API around that as well)
  • I'm not sure who actually uses it considering we have toJSON. I found one single usage in nixpkgs, in GRUB. That's rather unfortunate, but also could probably be adapted to not rely on it.
    • It lets you introspect Nix expressions, which may be useful, but feels more like a debug tool than something that we should be using.
    • As an example, noogle uses a C plugin for docs.

Proposed solution

Remove it completely. Some of this functionality seems like it should be used in plugins rather than being exposed to the evaluator.

Alternative solutions

Keep it and fix it, but add an eval warning for using it. Maybe even remove some of the things it can do to just allow serializing flat data, possibly so GRUB configs still work in old versions of nixpkgs.

Additional context

Checklist


Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeature request or proposal
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions