What am I doing wrong in this override?

I wanted to add a library in package zoom-us, so I tried to use overrideAttrs to edit the package’s config. However, nixos-rebuild keeps showing this error message:

error: cannot coerce a set to a string

       at /etc/nixos/configuration.nix:302:11:

          301|         (zoom-us.overrideAttrs (old: {
          302|           srcs = {
             |           ^
          303|             version = "5.8.4.210";
(use '--show-trace' to show detailed location information)

This is the part of my configuration.nix which has this issue.

  environment = {
    systemPackages = with pkgs;
      with qt5;
      with libsForQt5;
      with gnome; [
        ####other packages####

        (zoom-us.overrideAttrs (old: {
          srcs = {
            version = "5.8.4.210";
            x86_64-linux = fetchurl {
              url = "https://zoom.us/client/${version}/zoom_x86_64.pkg.tar.xz";
              sha256 = "1qjr35wg1jk6a6c958s0hbgqqczq789iim77s02yqpy5kyjbnn1n";
            };
            kimelib = fetchurl {
              url =
                "https://github.com/Riey/kime/releases/download/v2.5.6/libkime-qt-5.12.8.so";
              sha256 =
                "c7b9661272e58b1e47005ce7524ba42ba5e9da14ca027e775347af148c503ddd";
            };
          };

          installPhase = ''
            runHook preInstall
            mkdir $out
            tar -C $out -xf $src
            mv $out/usr/* $out/
            install -Dm755 $libkime $out/opt/zoom/platforminputcontexts/libkimeplatforminputcontextplugin.so
            runHook postInstall
          '';
        }))
      ];
  };

I know I did it wrong, but how?

1 Like

From the Nixpkgs manual

The function overrideAttrs allows overriding the attribute set passed to a stdenv.mkDerivation call, producing a new derivation based on the original one.

The attributes other than the special ones are passed to builtins.derivations. Those attributes are then passed as environment variables to the builder as follows^1:

  • Strings and numbers are just passed verbatim.
  • A path (e.g., …/foo/sources.tar) causes the referenced file to be copied to the store; its location in the store is put in the environment variable. The idea is that all sources should reside in the Nix store, since all inputs to a derivation should reside in the Nix store.
  • A derivation causes that derivation to be built prior to the present derivation; its default output path is put in the environment variable.
  • Lists of the previous types are also allowed. They are simply concatenated, separated by spaces.
  • true is passed as the string 1, false and null are passed as an empty string.

Note that it is not possible to pass an attribute set as an environment variable to the builder, which is the source of the error you are getting:


The variable you are trying to override, srcs, is in a let expression.
It is an internal variable that is used to get the correct src value for the current platform using this expression:

src = srcs.${stdenv.hostPlatform.system};

Since it is a variable in a let expression instead of an attribute passed to mkDerivation, it can’t be modified with overrideAttrs. You would get the same error if you used any other name instead of srcs inside the overrideAttrs.

Instead, you can do something like this:

let
  kimelib = fetchurl {
    url =
      "https://github.com/Riey/kime/releases/download/v2.5.6/libkime-qt-5.12.8.so";
    sha256 =
      "c7b9661272e58b1e47005ce7524ba42ba5e9da14ca027e775347af148c503ddd";
  };
in
zoom-us.overrideAttrs(old: {
  postInstall = ''
    install -Dm755 ${kimelib} $out/opt/zoom/platforminputcontexts/libkimeplatforminputcontextplugin.so
  '';
})
1 Like

Now it shows this even though I added fetchurl in {}::

error: attribute 'fetchurl' missing

       at /nix/store/icr4jifdyw5nvs5226a28v72iq2yl04z-source/lib/modules.nix:360:28:

          359|         builtins.addErrorContext (context name)
          360|           (args.${name} or config._module.args.${name})
             |                            ^
          361|       ) (lib.functionArgs f);
(use '--show-trace' to show detailed location information)

Could you tell me pricisely where I should put your code block?

1 Like

Something like

# configuration.nix
{
  pkgs,
  ...
}:

let
  inherit (pkgs)
    fetchurl
  ;

  kimelib = fetchurl {
    url = "https://github.com/Riey/kime/releases/download/v2.5.6/libkime-qt-5.12.8.so";
    sha256 = "c7b9661272e58b1e47005ce7524ba42ba5e9da14ca027e775347af148c503ddd";
  };
in
{
  environment = {
    systemPackages = with pkgs; [
      zoom-us.overrideAttrs(old: {
        postInstall = ''
          install -Dm755 ${kimelib} $out/opt/zoom/platforminputcontexts/libkimeplatforminputcontextplugin.so
        '';
      })
    ];
  };
}
2 Likes

Thank you so much for the answer.