Getting `cannot coerce a function to a string' when overriding `hy'

Hello!

As in the title; in attempting to bring the current hy version to the latest, I am encountering the error in the title. This is my overlay:

final: prev: { python310 = prev.python310.override (super: {
    packageOverrides = lib.composeExtensions (super.packageOverrides or (_: _: {})) (new: old: {
        hy = prev.python310.pkgs.hy.overridePythonAttrs (old: with final.Python3.pkgs; rec {
            version = "0.24.0";
            HY_VERSION = version;
            src = final.fetchFromGitHub {
                owner = "hylang";
                repo = old.pname;
                rev = version;
                sha256 = "1s458ymd9g3s8k2ccc300jr4w66c7q3vhmhs9z3d3a4qg0xdhs9y";
            };
            postPatch = ''substituteInPlace setup.py --replace "\"funcparserlib ~= 1.0\"," ""'' + (old.postPatch or "");
            disabledTestPaths = [ "tests/test_bin.py" ] ++ (old.disabledTestPaths or []);
            passthru = (old.passthru or {}) // {
                tests.version = testers.testVersion {
                    package = hy;
                    command = "hy -v";
                };
                withPackages = python-packages: (toPythonApplication hy).override {
                    hyDefinedPythonPackages = python-packages;
                };
            };
        });
    });
}); }

And this is the trace:

error: cannot coerce a function to a string

       at /nix/store/gadw1hblrqm0rs7gs69vkpa8lsyhrcym-source/flake.nix:926:37:

          925|                                 withPackages = python-packages: (toPythonApplication hy).override {
          926|                                     hyDefinedPythonPackages = python-packages;
             |                                     ^
          927|                                 };

       … while evaluating the attribute 'hyDefinedPythonPackages' of the derivation 'python3.10-hy-0.24.0'

       at /nix/store/i6928nc3i36yaqkbrrv8bz8hgvpx7lqp-defaultPatches/pkgs/stdenv/generic/make-derivation.nix:278:7:

          277|     // (lib.optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) {
          278|       name =
             |       ^
          279|         let

What confuses me is that hyDefinedPythonPackages is meant to be a function, and without withPackages, I cannot create a Hy package / app for a flake, used by nix run.

Thank you kindly for the help!

You could use lib.debug.traceVal to see what those values actually are :slight_smile:

That said, your definition appears to be the default already: https://github.com/NixOS/nixpkgs/blob/97d5a1a5919c7124fc22405cf43098e3cfa8ea45/pkgs/development/python-modules/hy/default.nix#L65. Why do you need to override it?

The hy used there is defined elsewhere, too, I think: https://github.com/NixOS/nixpkgs/blob/97d5a1a5919c7124fc22405cf43098e3cfa8ea45/pkgs/development/python-modules/hy/default.nix#L7. Perhaps using prev.hy will be more successful?

While I’m at it, the use of rec and with makes it hard to know which hy is actually being used in this case. I’d recommend being a bit more careful with your scopes.

1 Like

The hy being used used is the final version, and it’s being applied appropriately; if it wasn’t overridden, the interpreter version isn’t the same as the package version, which kind ruins it. :sweat_smile: Also, I used trace to see that hyDefinedPackages is actually receiving a function, like it is supposed to, but I don’t know why it isn’t accepting a function in this case. Can traceVal help with that?

traceVal is just a trace that traces and returns its first argument.

Shame these errors are so hard to debug. Does --show-trace help?

1 Like

That last bit of my post was the trace! :sob:

Basically, I think this leaves me with two options:

  1. Override hy’s propagatedBuildInputs directly in place of withPackages, or
  2. Patch nixpkgs using applyPatch

That last bit of my post was the trace! :sob:

Heh, sorry, my bad. I’d expect at least 10 pages’ worth of trace output, rather than just the final bit, so my brain for some reason parsed that as the normal error message. Is that the full trace? I suspected the error isn’t actually that assignment to hyDefinedPythonPackages, but rather in something else, but if it isn’t I’m lost too.

1 Like

Yeah, I’m crying because that was the full trace. :joy_cat: I guess we’re both lost then, here! I’d try posting to the nixpkgs repo itself, but the wait times are something else.

You know what? Never mind. I went with my first alternative and did this:

withPackages = python-packages: (toPythonApplication final.python310.pkgs.hy).overrideAttrs (old: {
    propagatedBuildInputs = python-packages final.python310.pkgs ++ (old.propagatedBuildInputs or []);
});

It works! :joy_cat:

1 Like