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

4 Likes

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

Hi, I’m trying to get the latest version of devpod using the above overlay, but I’m running into issues

in my home.nix:

  nixpkgs.overlays = [
    (final: prev: {
      devpod = prev.callPackage "${prev.path}/pkgs/development/tools/devpod" {
        buildGoModule = args: prev.buildGoModule (args // {
          version = "0.6.8";
          pname = "devpod";
          meta = with lib; {
            description = "Codespaces but open-source, client-only and unopinionated: Works with any IDE and lets you use any cloud, kubernetes or just localhost docker";
            mainProgram = "devpod";
            homepage = "https://devpod.sh";
            license = licenses.mpl20;
            maintainers = with maintainers; [ maxbrunet ];
          };
          src = prev.fetchFromGitHub {
            owner = "loft-sh";
            repo = "devpod";
            rev = "v0.6.8";
            sha256 = prev.lib.fakeHash;
          };
        });
      };
    })
  ];

when i run home-manager switch --flake . i get the following error

warning: Git tree '/opt/repos/nix-config' is dirty
warning: Git tree '/opt/repos/nix-config' is dirty
warning: Git tree '/opt/repos/nix-config' is dirty
warning: Git tree '/opt/repos/nix-config' is dirty
error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:34:12:
           33|
           34|   strict = derivationStrict drvAttrs;
             |            ^
           35|

       … while evaluating derivation 'home-manager-generation'
         whose name attribute is located at /nix/store/khbvilmsrv4l69nwd52h27j1mp44a0xi-source/pkgs/stdenv/generic/make-derivation.nix:375:7

       … while evaluating attribute 'buildCommand' of derivation 'home-manager-generation'
         at /nix/store/khbvilmsrv4l69nwd52h27j1mp44a0xi-source/pkgs/build-support/trivial-builders/default.nix:59:17:
           58|         enableParallelBuilding = true;
           59|         inherit buildCommand name;
             |                 ^
           60|         passAsFile = [ "buildCommand" ]

       … while evaluating the option `home.activation.installPackages.data':

       … while evaluating definitions from `/nix/store/khpgnlyxlq96qf1qibrw8b3f74vnqxgn-source/modules/home-environment.nix':

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: A definition for option `home.packages."[definition 1-entry 6]"' is not of type `package'. Definition values:
       - In `/nix/store/rdy61m3cmwlhk5ayqpfv4gw4iw644k9n-source/home-manager/home.nix':
           {
             devpod = <derivation devpod-0.6.8>;
             devpod-desktop = <derivation devpod-desktop-0.5.20>;
             override = <function, args: {buildGoModule, copyDesktopItems, darwin, desktopToDarwinBundle, fetchFromGitHub, fetchYarnDeps, gtk3, installShellFiles, jq, lib, libayatana-appindicator, libsoup_2_4, makeDesktopItem, mkYarnPackage, openssl, pkg-config, rust, rustPlatform, stdenv, testers, webkitgtk_4_0}>;
             overrideDerivation = <function>;

any suggestions would be helpful please