rules_nixpkgs icon indicating copy to clipboard operation
rules_nixpkgs copied to clipboard

Updating to latest rules_go is incompatible with rules_nixpkgs provided go.

Open jtszalay opened this issue 6 months ago • 1 comments

Describe the bug

missing value for mandatory attribute 'pack' in 'go_toolchain' rule

To Reproduce

bazel_dep(name = "rules_go", version = "0.57.0")

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.host()

Expected behavior Expect it to work.

Environment

  • OS name + version: Ubuntu 24.04
  • Version of the code: rules_nixpkgs-0.13.0

Additional context github.com/bazel-contrib/rules_go/pull/4425

jtszalay avatar Sep 11 '25 13:09 jtszalay

I don't know if this is ideal, but I think it is probably possible to drop explicit rules_nixpkgs support for rules_go...

Others have pointed out that the upstream Go toolchain runs on Nix.

Further, if you use something like devenv/Nix to setup your build environment and you want to use the same toolchain inside of bazel and outside, you can probably do soemthing like this:

WORKSPACE.bazel

    nixpkgs_package(
        name = "nix_go",
        repository = "@nixpkgs-unstable",
        nix_file = "@//bazel/go:go.nix",
    )

go_wrap_sdk(
    name = "go_sdk",
    experiments = ["greenteagc"],
    root_file = "@nix_go//:ROOT",
)

go.nix

let
  pkgs = import <nixpkgs> {};
  go = pkgs.go_1_25;
in
  pkgs.buildEnv {
    name = "bazel-go-toolchain";
    paths = [go];
    postBuild = ''
      touch $out/ROOT
      ln -s $out/share/go/{api,doc,lib,misc,pkg,src,go.env} $out/
    '';
  }
  // {
    version = go.version;
  }

This is good because you use fully upstream code and you don't have to plumb things into rules_nixpkgs like goexperiments...

DolceTriade avatar Sep 30 '25 05:09 DolceTriade