Override a derivation result in "cannot coerce a function to a string"

I tried to build GNOME 40 alpha dev environment, I override several packages such as gsettings-desktop-schemas (GDS). Unfortunately, some of the packages already contains old version of GDS, therefor, I want to override that as well.

      gnome-settings-daemon.overrideAttrs(old: {
        # gsettings-desktop-schemas is a new derivation
        buildInputs = [ gsettings-desktop-schemas ] ++ old.buildInputs;
      })

Doing something above, before directly passed to buildInputs, cause coercion error as the following.

at: (192:11) in file: /nix/store/2qqz0n22rcj2cwrn06213lqpb61ipqd6-nixpkgs-unstable-21.05pre269929.ff96a0fa563/nixpkgs-unstable/pkgs/stdenv/generic/make-derivation.nix

   191|         // (lib.optionalAttrs (!(attrs ? name) && attrs ? pname && attrs ? version)) {
   192|           name = "${attrs.pname}-${attrs.version}";
      |           ^
   193|         } // (lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform && !dontAddHostSuffix && (attrs ? name || (attrs ? pname && attrs ? version)))) {

cannot coerce a function to a string

What does actually happened? As I don’t see any function on the sight…

Note:
It is a different story when removing the overrideAttrs, it allows everything built but with PKG_CONFIG_PATH containing old reference and new reference. So, I don’t think my modified GSD is not resolved into a derivation (still a function hence a cause of error).

1 Like

I have a similar problem when writing a flake:

    35|         packages.abracadabra = pkgs.stdenv.mkDerivation {
    36|           name = "abracadabra";
      |           ^
    37|           src = self;

cannot coerce a function to a string
(use '--show-trace' to show detailed location information)

Curiously enough, this problem doesn’t arise until I add

setupHook = pkgs.writeText "echo XXXXXXXXXXXXXXXXXXXXXX";

later on in the same derivation. Without the setupHook, the build succeeds, but there is a crash at runtime because of an unset environment variable.

Like the OP, I’m perplexed by the mention of ‘function’ in the error message.

Your problem is likely unrelated to the OPs, you just forgot about the fact that writeText takes 2 arguments.

First a name and then the config, as you only have provided a name, but no content, a function is returned.

Oh dear.

Thank you.

I would argue that my problem is likely to be strongly related to the OP’s : the message does an excellent job of attracting attention away from the source of the error! :slight_smile:

Can you share a full example of the buildInputs please?

you will likely need to enclose all of this in another set of parenthesis

  pkgs = [
      gnome-settings-daemon.overrideAttrs (old: {
        # gsettings-desktop-schemas is a new derivation
        buildInputs = [ gsettings-desktop-schemas ] ++ old.buildInputs;
      })
  ];

is equivalent to

  pkgs = [
      (gnome-settings-daemon.overrideAttrs)
      (old: {
        # gsettings-desktop-schemas is a new derivation
        buildInputs = [ gsettings-desktop-schemas ] ++ old.buildInputs;
      })
  ];

where as you probably wanted

  pkgs = [
      (gnome-settings-daemon.overrideAttrs (old: {
        # gsettings-desktop-schemas is a new derivation
        buildInputs = [ gsettings-desktop-schemas ] ++ old.buildInputs;
      }))
  ];

generally i do something like

  let
     gnomeWithDesktopSchemas = gnome-settings-daemon.overrideAttrs (old: {
        # gsettings-desktop-schemas is a new derivation
        buildInputs = [ gsettings-desktop-schemas ] ++ old.buildInputs;
      });
  in
  pkgs = [
     gnomeWithDesktopSchemas
  ];
2 Likes

That’s unexpected of. :grin:
Therefore, I passed two functions to buildInputs instead of one package.
Thank you!


For completion, this is mutter v40.alpha buildInput, copied from Nixpkgs after correction.

    buildInputs = [
      cairo
      egl-wayland
      glib
      gnome-desktop
      (gnome-settings-daemon.overrideAttrs (old: {
        buildInputs = [ gsettings-desktop-schemas ] ++ old.buildInputs;
      }))
      gobject-introspection
      gsettings-desktop-schemas
      gtk3
      libcanberra
      libgudev
      libinput
      libstartup_notification
      libwacom
      libxkbcommon
      libxkbfile
      pango
      pipewire
      sysprof
      xkeyboard_config
      xwayland
      wayland-protocols
    ];