Overlay, buildGoModule, overrideAttrs, version overrides

Hi. Recently had a hard time getting going with overlays. Got some help in discord, thought I would share it back here.

Use case: Want latest version which isn’t in nixpkgs yet, or to version pin a pkg.

Example: In this case, it is a go based pkg - operator-sdk was at 1.18.1 and I want to install latest (1.22.0).

Context: using home-manager, I don’t use nix to manage any other aspect of system.

Inside ~/.config/nixpkgs/home.nix:

{ config, pkgs, ... }:

  nixpkgs.overlays = [
    (final: prev: {
      operator-sdk = prev.callPackage "${prev.path}/pkgs/development/tools/operator-sdk" {
        buildGoModule = args: prev.buildGoModule (args // {
          version = "1.22.0";

          src = prev.fetchFromGitHub {
            owner = "operator-framework";
            repo = "operator-sdk";
            rev = "v1.22.0";
            sha256 = prev.lib.fakeHash;
          vendorSha256 =  prev.lib.fakeHash;



Notice in the sha fields, using fakeHash. So when you do this, run home-manager switch and you will get an error about hash-mismatch. First error message gives sha256, run again and that will give you the vendorSha256.

There are probably a few variations on doing this, depending on the pkg. In this case the pkg is using buildGoModule. Here is another variation, to overlay asdf-vm.nix:

(final: prev: {
  asdf-vm = prev.asdf-vm.overrideAttrs (_: {
    version = "0.10.2";
    src = prev.fetchFromGitHub {
        owner = "asdf-vm";
        repo = "asdf";
        rev = "v0.10.2";
        sha256 = prev.lib.fakeHash;

Thanks to everyone in the discord who helped while I fumbled my way to asking the right questions. Here is the meat of the discussion: Discord


Thanks for posting your learnings in a searchable space. You’ve definitely helped me out.

In some cases, if you’re writing a nix.flake, I think you can get away with removing prev.lib.fakeHash from src.sha256 by instead declaring it as an input (so the hash ends up in flake.lock). vendorSha256, however, seems to be necessary.

Most of this gist is focused on a separate problem, but it shows the structure I’m referring to: > go: -mod may only be set to readonly when in workspace mode, but it is set to "vendor" · GitHub

Hosted by Flying Circus.