Skip to content

Undocumented / impossible: override go modules #86349

@doronbehar

Description

@doronbehar

Describe the bug

I'm trying to write an overlay that will override attributes of a package that is built with buildGoModule and I'm having trouble overriding the modules derivation of it.

It seems the author's intention was that I'd use overrideModAttrs as an argument to buildGoModule? But I guess this doesn't work with overlays? Whatever I do, I get either an evaluation error or a build error because the old go-modules is used. Here are a few examples I tried:

overridedPackage = super.original.overrideAttrs(oldAttrs: rec {
  src = ....;
  modSha256 = "0000000000000000000000000000000000000000000000000000";

But the build still took the old go modules derivation.

I also tried instead:

  overrideModAttrs = (_oldAttrs : {
    modSha256 = "0r062nka72ah2nb2gf8dfrrj4sxadkykcqjzkp4c9vwk93mhw41k";
  });

Which failed with:

error: cannot coerce a function to a string, at ...

And I even went as far as:

  configurePhase = (let
    go-modules = self.pistol.go-modules.overrideAttrs(oldAttrs: {
      modSha256 = "0000000000000000000000000000000000000000000000000000";
    });
  in
    ''
      echo checking I override configure phase
      runHook preConfigure
  
      export GOCACHE=$TMPDIR/go-cache
      export GOPATH="$TMPDIR/go"
      export GOSUMDB=off
      export GOPROXY=file://${go-modules}
  
      cd "$modRoot"
  
      runHook postConfigure
    ''
  );
});

But that also failed because the build used the old go-modules. I can confirm though, that it did override the configurePhase which is the only place ${go-modules} is evaluated.

Expected behavior

It shouldn't be that difficult to override a go modules derivation.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context

I'm trying to override a package I maintain which it's update is stale (#85452), due to an unresolved issue with the version build flags :(.

Notify maintainers

@kalbasit ? As the author of buildGoModule according to git blame...

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bugSomething is broken6.topic: golangGo is a high-level general purpose programming language that is statically typed and compiled.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions