Sergiusz Bazanski | e03c217 | 2020-02-15 01:04:38 +0100 | [diff] [blame] | 1 | def _gen_imports_impl(ctx): |
| 2 | ctx.file("BUILD", "") |
| 3 | |
| 4 | is_nixos = "NIX_PATH" in ctx.os.environ |
| 5 | bzl_file_content = """ |
| 6 | load( |
| 7 | "@io_bazel_rules_go//go:deps.bzl", |
| 8 | "go_register_toolchains", |
| 9 | "go_rules_dependencies", |
| 10 | ) |
| 11 | def load_go_sdk(): |
| 12 | go_rules_dependencies() |
| 13 | go_register_toolchains({go_version}) |
| 14 | """.format( |
| 15 | go_version = 'go_version = "host"' if is_nixos else "", |
| 16 | ) |
| 17 | |
| 18 | ctx.file("imports.bzl", bzl_file_content) |
| 19 | |
| 20 | _gen_imports = repository_rule( |
| 21 | implementation = _gen_imports_impl, |
| 22 | attrs = dict(), |
| 23 | ) |
| 24 | |
| 25 | def gen_imports(name): |
| 26 | _gen_imports( |
| 27 | name = name, |
| 28 | ) |