How to handle "error: string '...' has context with the output 'out' from derivation '/nix/store/...-cherami-0.0.0.drv', but the string is not the right placeholder for this derivation output. It should be '/nix/store/...-cherami-0.0.0'"?

I have a flake.nix:

{
  inputs = {
    utils.url = "github:numtide/flake-utils";
    naersk.url = "github:nix-community/naersk";
  };

  outputs = { self, naersk, nixpkgs, utils }:
    utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { };
        naersk-lib = pkgs.callPackage naersk { };
        cherami-build = naersk-lib.buildPackage { src = ./cherami; };
      in with pkgs; {
        packages.cherami = pkgs.lib.getExe' cherami-build "cherami";
      });
}

But I’m getting an error:

root@b62e2017d34d:/workspaces/bitbop# nix build .#cherami
warning: Git tree '/workspaces/bitbop' is dirty
error:
       … while evaluating the flake output attribute 'packages.aarch64-linux.cherami'

       error: string '/nix/store/ij52j1xp7w2cm0a8f8qp7w3ymlgkarjb-cherami-0.0.0/bin/cherami' has context with the output 'out' from derivation '/nix/store/sdmq12gxhhnbc79899iykm3la8y8ycjb-cherami-0.0.0.drv', but the string is not the right placeholder for this derivation output. It should be '/nix/store/ij52j1xp7w2cm0a8f8qp7w3ymlgkarjb-cherami-0.0.0'
root@b62e2017d34d:/workspaces/bitbop# 

but I have verified that the file /nix/store/<hash>-cherami-0.0.0/bin/cherami exists.

What does this error mean? Why am I getting it?

My current hypothesis is that lib.getExe' is evaluating to a string instead of a package, but this is not at all clear from the error message IMHO.

Is there an alternative to lib.getExe' that builds a derivation instead of returning a string?

Yes, I think that is the issue – Flake packages should be derivations.

There is an issue about the unclear error message: Bad error message for `nix build` of a string · Issue #9700 · NixOS/nix · GitHub

What are you trying to achieve? The purpose of lib.getExe' is to get path to a specified program within a derivation.

Why not just use packages.cherami = cherami-build;?

1 Like

There is an issue about the unclear error message: Bad error message for nix build of a string · Issue #9700 · NixOS/nix · GitHub

Thanks @jtojnar !

Why not just use packages.cherami = cherami-build;?

Yes, this is what I landed on. I was originally hoping get a derivation that had just the binary (or symlink to it) that I was looking for, but this is not a high priority for me.