devenv icon indicating copy to clipboard operation
devenv copied to clipboard

ability to specifiy a go language version

Open john-fwss opened this issue 1 year ago • 9 comments

CONTEXT

Other languages have the ability to specify a specific version of the language to be used in the devenv.nix file.

Example: languages.python.version = "3.11.3"; works great, love it.

Go does not, and it is frustrating (and not best practice according to support channel in discord) to try and pin specific commit hashes of older versions.

Go has the package language option (which is great that its there) here: https://devenv.sh/reference/options/#languagesgopackage

but no examples of what a properly formatted input looks like. seems to be happy with pkgs.go_1_22 and pkgs.go_1_21 (after a lot of trial and error) but no others.

REQUEST

make golang compatible with specific pinned language versions, just like many other languages already supported are.

john-fwss avatar May 02 '24 03:05 john-fwss

Someone needs to create nixpkgs-go with all the versions packaged :)

domenkozar avatar May 17 '24 08:05 domenkozar

To find the version of go is not an issue. You can refer to this: https://lazamar.co.uk/nix-versions/?channel=nixpkgs-unstable&package=ffmpeg @domenkozar

However, devenv can not deal with it. It says it can't find buildGoModule with version 1.20.14 :cry:

JeffLabonte avatar Jun 08 '24 03:06 JeffLabonte

When versions are available for a language (and I can see them with devenv search, how do I figure out what the actual package name is for the package with version?

gregwebs avatar Jun 28 '24 17:06 gregwebs

Please upvote this issue if it's important to you and we'll get it done.

Package name should be in the output of devenv search, you can see it prefixed with pkgs..

domenkozar avatar Jul 01 '24 13:07 domenkozar

Package name should be in the output of devenv search, you can see it prefixed with pkgs..

But how do I specify the version that I see there? For example, there is

| pkgs.go                                                               | 1.22.3                                   | Go Programming language                                                          |

How do I know that this is specified with underscores this way?

  languages.go.package = pkgs.go_1_22;

When I try to do this to set languages.cue.package I don't know what the exact format is.

gregwebs avatar Jul 01 '24 13:07 gregwebs

There's:

+------------------------------------------------+---------+----------------------------------------------------------------------------------+
| pkgs.go_1_22                                   | 1.22.3  | Go Programming language                                                          |
+------------------------------------------------+---------+----------------------------------------------------------------------------------+

So languages.go.package = pkgs.go_1_22; should work.

Same goes for cue, if the version is available.

domenkozar avatar Jul 03 '24 12:07 domenkozar

| pkgs.cue                                    | 0.9.2                      | Data constraint language which aims to simplify tasks involving defining and usi |

Maybe its a problem with zeros- I tried some different variations for languages.cue.package and none worked.

gregwebs avatar Jul 03 '24 13:07 gregwebs

I haven't tried devbox, but they have clear documentation on how to specify package versions: https://www.jetify.com/devbox/docs/guides/pinning_packages/

gregwebs avatar Jul 03 '24 13:07 gregwebs

The issue I have with this approach is that you'll get also an outdated closure, possibly with security issues in the closure like openssl.

If someone is interested to sponsor nixpkgs-go creation I could do that in similar style like https://github.com/cachix/nixpkgs-python that auto-updates each hour.

domenkozar avatar Jul 11 '24 12:07 domenkozar

Looks like @purpleclay started some of this in https://github.com/purpleclay/go-overlay

domenkozar avatar Nov 24 '25 12:11 domenkozar

Looks like @purpleclay started some of this in https://github.com/purpleclay/go-overlay

I have finally got something up and running. If this helps anyone, then great!

purpleclay avatar Dec 10 '25 16:12 purpleclay

Thanks @purpleclay, I've integrated your overlay at https://github.com/cachix/devenv/pull/2340

domenkozar avatar Dec 11 '25 11:12 domenkozar

I'm getting:

error: at «github:cachix/devenv-nixpkgs/dcf61356c3ab25f1362b4a4428a6d871e84f1d1d»/pkgs/build-support/go/module.nix:225:47:
          224|
          225|         CGO_ENABLED = args.env.CGO_ENABLED or go.CGO_ENABLED;
             |                                               ^
          226|       };

       error: attribute 'CGO_ENABLED' missing

Using go 1.23.0, maybe too new/old nixpkgs?

domenkozar avatar Dec 11 '25 11:12 domenkozar

Just saw this. I can take a look.

purpleclay avatar Dec 13 '25 15:12 purpleclay

Here's what Claude is saying:

● Here's the mk-go-toolchain.nix from go-overlay. The fix needed is to add the missing attributes. The derivation should include:

inherit (stdenv.targetPlatform.go) GOOS GOARCH; CGO_ENABLED = if stdenv.targetPlatform.isWasi || (stdenv.targetPlatform.isPower64 && stdenv.targetPlatform.isBigEndian) then 0 else 1;

Options:

  1. Fix in go-overlay (recommended) - Add these attributes to mk-go-toolchain.nix. This makes go-overlay packages compatible with nixpkgs' buildGoModule. I can draft a PR.
  2. Fix in nixpkgs - Make buildGoModule provide defaults when go.CGO_ENABLED is missing. However, this is a workaround for an external overlay, which might not be accepted upstream.

Which would you prefer? I can help draft a PR for go-overlay.

On Sat, Dec 13, 2025 at 4:28 PM Purple Clay @.***> wrote:

purpleclay left a comment (cachix/devenv#1179) https://github.com/cachix/devenv/issues/1179#issuecomment-3649541468

Just saw this. I can take a look.

— Reply to this email directly, view it on GitHub https://github.com/cachix/devenv/issues/1179#issuecomment-3649541468, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA63A7YVTCETLRJ7V5EU6L4BQWDVAVCNFSM6AAAAACNAW72KWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTMNBZGU2DCNBWHA . You are receiving this because you were mentioned.Message ID: @.***>

domenkozar avatar Dec 13 '25 15:12 domenkozar

Raised: https://github.com/purpleclay/go-overlay/issues/38 will fix it now

purpleclay avatar Dec 13 '25 15:12 purpleclay

Fix has been merged in. Let me know if that addresses your issue @domenkozar

purpleclay avatar Dec 13 '25 15:12 purpleclay

Thanks!!

domenkozar avatar Dec 13 '25 16:12 domenkozar