How can I override a Nix derivative without throwing `cannot coerce a set to a string`?
<p>Or, the goal: <em>How can I take a single package from Nix unstable in a declarative manner?</em></p>

<p>I'm new to NixOS and currently trying to install a newer version of Consul than the default <code>0.5.2</code> of my NixOS version (latest stable). I'm attempting this by overriding the derivative in my <code>/etc/nix/configuration.nix</code>. </p>

<p>I'd like to keep running stable, but I found unstable had the version of Consul that I wanted (<code>0.7.0</code>) already, and so I decided to use this package's attributes as a starting point to override <a href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/consul/default.nix" rel="nofollow">https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/consul/default.nix</a></p>

<p>I copied it for most part into my <code>configuration.nix</code>, here are the relevant sections:</p>

<pre><code>nixpkgs.config.packageOverrides = pkgs: rec {
  consul = pkgs.lib.overrideDerivation pkgs.consul (attrs: rec {
    version = "0.7.0";
    name = "consul-${version}";
    rev = "v${version}";

    goPackagePath = "github.com/hashicorp/consul";

    src = pkgs.fetchFromGitHub {
      owner = "hashicorp";
      repo = "consul";
      inherit rev;
      sha256 = "04h5y5vixjh9np9lsrk02ypbqwcq855h7l1jlnl1vmfq3sfqjds7";
    };

    # Keep consul.ui for backward compatability
    passthru.ui = pkgs.consul-ui;
  });
};

environment.systemPackages = with pkgs; [
  vim
  which
  telnet
  consul-ui
  consul-alerts
  consul-template
  consul
];
</code></pre>

<p>I'm running <code>nix-build (Nix) 1.11.2</code> which throws:</p>

<pre><code>$ nixos-rebuild switch
building Nix...
building the system configuration...
error: cannot coerce a set to a string, at /etc/nixos/configuration.nix:19:7
(use ‘--show-trace’ to show detailed location information)
</code></pre>

<p>When I look at line <code>19</code> it's where <code>name</code> is set to <code>"consul-${version}"</code>.</p>

<p>Why there is type-coercion going on here? Any tips will be greatly appreciated!</p>

<p>I'm also wondering if there is a better way to run just a single package in unstable, yet doing so declaratively from <code>configuration.nix</code>, rather than imperatively?</p>