Using overrideAttrs in a flake (or pinning a version some other way)

I think I got it. Thanks again for you help!

{
  description = "kustomize pinned at v4.5.5";

  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    kustomize-src = {
      url = "github:kubernetes-sigs/kustomize?tag=kustomize/v4.5.5";
      flake = false;
    };
  };
  outputs = { self, nixpkgs, flake-utils, kustomize-src }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        version = "4.5.5";
        pin-kustomize = final: prev: {
          kustomize = prev.kustomize.override {
            buildGoModule = args: prev.buildGoModule (args // {
              inherit version;
              src = kustomize-src;
              vendorSha256 = "sha256-k8Rso1bAJbJOz/zGmU2VxQJW20Khof23a86seXt9AGQ=";
              ldflags = [
                "-s"
                "-w"
                "-X sigs.k8s.io/kustomize/api/provenance.version=v${version}"
              ];
              preBuild = ''
                export GOWORK=off
              '';
            });
          };
        };

        pkgs = nixpkgs.legacyPackages.${system}.extend pin-kustomize;
      in rec
      {
        packages = {
          default = pkgs.kustomize;
        };
      });
}

Aside:

I’ve been forum hunting (this thread was useful), and using traditional search engines, and consulting GPT-3-based AI’s about this. It’s been an incremental process spanning the whole day.

GPT-4 accepts a larger query, so I just gave it the whole flake.nix, and the go build error, and it only took three or four revisions to get it right. Huge improvement.

2 Likes