### Run Rust Example with Nix and Bazel Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/toolchains/rust/README.md This command executes the Rust example project using Nix to provide the environment and Bazel for building and running the application. It assumes Nix is installed and configured. ```bash nix-shell --command 'bazel run --config=nix //:hello' ``` -------------------------------- ### Complete WORKSPACE Setup with rules_nixpkgs and Multiple Toolchains Source: https://context7.com/tweag/rules_nixpkgs/llms.txt This is a comprehensive WORKSPACE file example for rules_nixpkgs, showcasing the setup for multiple toolchains. It includes importing rules_nixpkgs, pinning a Nixpkgs version, and configuring CC, Go, and Python toolchains, along with importing specific packages like zlib and openssl. ```bzl # WORKSPACE workspace(name = "my_project") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # Import rules_nixpkgs http_archive( name = "io_tweag_rules_nixpkgs", sha256 = "...", strip_prefix = "rules_nixpkgs-0.13.0", urls = ["https://github.com/tweag/rules_nixpkgs/releases/download/v0.13.0/rules_nixpkgs-0.13.0.tar.gz"], ) load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies") rules_nixpkgs_dependencies() # Pin Nixpkgs version load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_git_repository", "nixpkgs_package", "nixpkgs_cc_configure") nixpkgs_git_repository( name = "nixpkgs", revision = "24.05", sha256 = "911314b81780f26fdaf87e17174210bdbd40c86bac1795212f257cdc236a1e78", ) # Configure CC toolchain nixpkgs_cc_configure( repository = "@nixpkgs", ) # Configure Go toolchain load("@io_tweag_rules_nixpkgs//toolchains/go.bzl", "nixpkgs_go_configure") nixpkgs_go_configure(repository = "@nixpkgs") # Configure Python toolchain load("@io_tweag_rules_nixpkgs//toolchains/python.bzl", "nixpkgs_python_configure") nixpkgs_python_configure(repository = "@nixpkgs") # Import specific packages nixpkgs_package( name = "zlib", attribute_path = "zlib", repository = "@nixpkgs", ) nixpkgs_package( name = "openssl", attribute_path = "openssl", repository = "@nixpkgs", ) # .bazelrc # build --host_platform=@rules_nixpkgs_core//platforms:host # build --crosstool_top=@local_config_cc//:toolchain ``` -------------------------------- ### Running a Bazel Target Source: https://github.com/tweag/rules_nixpkgs/blob/master/guide.md Command to build and run a Bazel target. This example specifically runs the `//src:hello-world` C++ binary. It shows typical Bazel output during analysis and execution. ```shell > bazel run //src:hello-world INFO: Analyzed target //src:hello-world (0 packages loaded, 0 targets configured). INFO: Found 1 target... Target //src:hello-world up-to-date: bazel-bin/src/hello-world INFO: Elapsed time: 0.063s, Critical Path: 0.00s INFO: 1 process: 1 internal. INFO: Build completed successfully, 1 total action INFO: Build completed successfully, 1 total action Hello world! ``` -------------------------------- ### Run Bazel Java Example with Nix Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/toolchains/java/README.md This command executes the example Java project using Bazel and the Nix package manager. It ensures the Java runtime is provided by Nix for the build and execution environment. ```bash nix-shell --command 'bazel run --config=nix :hello' ``` -------------------------------- ### Run Bazel Java Example without Nix Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/toolchains/java/README.md This command executes the example Java project using Bazel without relying on the Nix package manager. It assumes a local Bazel installation and uses the default Java runtime available in the environment. ```bash bazel run :hello ``` -------------------------------- ### Running Bazel with Nix Configuration Source: https://github.com/tweag/rules_nixpkgs/blob/master/guide.md This example demonstrates how to execute a Bazel build or run command with the Nix configuration enabled. The '--config=nix' flag ensures that the Nix-specific settings defined in .bazelrc are applied to the command. ```bash bazel run //src:hello-world --config=nix ``` -------------------------------- ### Bazel Workspace Setup (WORKSPACE) Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/python-container/README.md Configures the Bazel workspace by loading necessary external repositories like rules_nixpkgs and rules_python. It also sets up the Nixpkgs repository and configures Python with Flask support. ```bazel workspace(name = "bazel-nix-python-container") load(@bazel_tools//tools/build_defs/repo:http.bzl, "http_archive") ###################### # Tweag Nix Support ###################### http_archive( name = "io_tweag_rules_nixpkgs", sha256 = "7aee35c95251c1751e765f7da09c3bb096d41e6d6dca3c72544781a5573be4aa", strip_prefix = "rules_nixpkgs-0.8.0", urls = ["https://github.com/tweag/rules_nixpkgs/archive/v0.8.0.tar.gz"], ) load(@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl, "rules_nixpkgs_dependencies") rules_nixpkgs_dependencies() # Define nixpkgs version 22.05 load(@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl, "nixpkgs_git_repository") nixpkgs_git_repository( name = "nixpkgs", revision = "22.05", sha256 = "0f8c25433a6611fa5664797cd049c80faefec91575718794c701f3b033f2db01", ) # Configure python load(@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl, "nixpkgs_python_configure") nixpkgs_python_configure( python3_attribute_path = "python39.withPackages(ps: [ ps.flask ])", repository = "@nixpkgs", ) ######### # Python ######### load(@bazel_tools//tools/build_defs/repo:http.bzl, "http_archive") http_archive( name = "rules_python", sha256 = "cdf6b84084aad8f10bf20b46b77cb48d83c319ebe6458a18e9d2cebf57807cdd", strip_prefix = "rules_python-0.8.1", url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.8.1.tar.gz", ) ``` -------------------------------- ### Simple C++ Hello World Program Source: https://github.com/tweag/rules_nixpkgs/blob/master/guide.md A basic C++ program that prints "Hello world!" to the console. This serves as a minimal example for demonstrating build system functionality. ```cpp #include int main(int argc, char** argv) { std::cout << "Hello world!" << std::endl; return 0; } ``` -------------------------------- ### Python Flask App (hello.py) Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/python-container/README.md A minimal Flask application that serves a 'Hello, World!' message. It's designed to be run within a Nix-shell environment. ```python from flask import Flask app = Flask(__name__) @app.route("/") def hello_world(): return "Hello, World!" app.run(host='0.0.0.0', port=5000) ``` -------------------------------- ### Display Nix Version Source: https://github.com/tweag/rules_nixpkgs/blob/master/guide.md This snippet demonstrates how to check the installed version of Nix. It's a simple command-line execution that outputs the Nix version, useful for verifying installation and compatibility during setup. ```bash nix --version ``` -------------------------------- ### Bazel Build File (BUILD) Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/python-container/README.md Defines a Bazel `py_binary` target named 'hello', specifying the source file and the main entry point for the Python application. ```bazel py_binary( name = "hello", srcs = ["hello.py"], main = "hello.py", ) ``` -------------------------------- ### Build Docker Image with Nix Command Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/python-container/README.md Demonstrates how to build the Docker image defined in `python39_base_image.nix` using the `nix-build` command. It shows the expected output path for the generated image. ```bash nix-build python39_base_image.nix ``` -------------------------------- ### Start NFS Server Source: https://github.com/tweag/rules_nixpkgs/blob/master/docs/remote-execution-tutorial.md Starts the NFS kernel server service on the Nix server. This command ensures that the NFS service is running and ready to serve exports. ```bash sudo systemctl start nfs-kernel-server ``` -------------------------------- ### Install NFS Client Package (VM) Source: https://github.com/tweag/rules_nixpkgs/blob/master/docs/remote-execution-tutorial.md Installs the NFS client packages on a virtual machine executor. This is required to mount the NFS share from the Nix server. ```bash sudo apt-get install nfs-common ``` -------------------------------- ### Run Docker Image with Bazel Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/python-container/README.md Runs the `hello_image` target using Bazel's `run` command, again with the `--config=nix` flag. This executes the Docker container built by Bazel. ```bash nix-shell --command 'bazel run --config=nix :hello_image' ``` -------------------------------- ### Build Docker Image with Bazel and Nix Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/python-container/README.md Builds the `hello_image` target using Bazel, with the `--config=nix` flag to enable Nix integration. This command triggers the entire build process defined in the Bazel and Nix files. ```bash nix-shell --command 'bazel build --config=nix :hello_image' ``` -------------------------------- ### Load Docker Image with Docker CLI Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/python-container/README.md Explains how to load the generated Docker image into your local Docker environment using the `docker load` command. It specifies the path to the image file obtained from the `nix-build` output. ```bash docker load -i /nix/store/gnd2dl80mwrbnzk77h43fl07cb694vcx-python38-base-image/image ``` -------------------------------- ### Install NFS Server Package (Ubuntu/Debian) Source: https://github.com/tweag/rules_nixpkgs/blob/master/docs/remote-execution-tutorial.md Installs the necessary NFS server packages on a Debian or Ubuntu system. This is a prerequisite for setting up the Nix server to share the Nix store. ```bash sudo apt-get update sudo apt-get install nfs-kernel-server nfs-common ``` -------------------------------- ### Nix Shell Configuration (shell.nix) Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/python-container/README.md Defines a Nix shell environment that includes Bazel version 5. This file ensures that Bazel is available when entering the Nix shell. ```nix { pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/refs/tags/22.05.tar.gz") {} }: pkgs.mkShellNoCC { nativeBuildInputs = [ pkgs.bazel_5 ]; } ``` -------------------------------- ### Setup rules_nixpkgs in WORKSPACE Source: https://github.com/tweag/rules_nixpkgs/blob/master/docs/README.md This snippet shows how to add rules_nixpkgs to your Bazel WORKSPACE file. It involves fetching the rules_nixpkgs archive and loading necessary dependency and rule definitions. An optional step configures the build platform for toolchain support. ```bzl load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "io_tweag_rules_nixpkgs", strip_prefix = "rules_nixpkgs-$COMMIT", urls = ["https://github.com/tweag/rules_nixpkgs/archive/$COMMIT.tar.gz"], ) load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies") rules_nixpkgs_dependencies() load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_git_repository", "nixpkgs_package", "nixpkgs_cc_configure") load("@io_tweag_rules_nixpkgs//nixpkgs:toolchains/go.bzl", "nixpkgs_go_configure") # optional # Add to .bazelrc for toolchain configuration: # build --host_platform=@rules_nixpkgs_core//platforms:host ``` -------------------------------- ### Define Nixpkgs repository and package Source: https://github.com/tweag/rules_nixpkgs/blob/master/docs/README.md This example demonstrates how to define a Nixpkgs repository using `nixpkgs_git_repository` and then use `nixpkgs_package` to make a Nix package available in Bazel. The `repositories` attribute in `nixpkgs_package` maps the Nixpkgs name to the Bazel repository. ```bzl nixpkgs_git_repository( name = "nixpkgs", revision = "17.09", # Any tag or commit hash sha256 = "" # optional sha to verify package integrity! ) nixpkgs_package( name = "hello", repositories = { "nixpkgs": "@nixpkgs//:default.nix" } ) ``` -------------------------------- ### Configure NodeJS Version in WORKSPACE Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/toolchains/nodejs/README.md This snippet shows how to configure the NodeJS version for the project by modifying the `attribute_path` parameter within the `nixpkgs_nodejs_configure` function in the `WORKSPACE` file. This allows for specifying different NodeJS versions managed by Nix. ```bazel nixpkgs_nodejs_configure( name = "nodejs_config", package = "nodejs_20_x", # Example: Specify NodeJS 20.x # attribute_path = "nodejs_20_x", # Alternative way to specify version ) ``` -------------------------------- ### Add Docker Rules to Bazel WORKSPACE Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/python-container/README.md Appends the necessary `http_archive` and `load` statements to the `WORKSPACE` file to integrate Bazel's Docker rules. This includes fetching `rules_docker` and its dependencies. ```bazel ######### # Docker ######### http_archive( name = "io_bazel_rules_docker", sha256 = "27d53c1d646fc9537a70427ad7b034734d08a9c38924cc6357cc973fed300820", strip_prefix = "rules_docker-0.24.0", urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.24.0/rules_docker-v0.24.0.tar.gz"], ) load(@io_bazel_rules_docker//repositories:repositories.bzl", container_repositories = "repositories") container_repositories() load(@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps") container_deps() load(@io_bazel_rules_docker//repositories:py_repositories.bzl", "py_deps") py_deps() load(@io_bazel_rules_docker//python3:image.bzl", py3_image_repos = "repositories") py3_image_repos() ``` -------------------------------- ### Override Default Nix Repository using Starlark Source: https://github.com/tweag/rules_nixpkgs/blob/master/design/bzlmod/README.md Illustrates how the root module can override the globally defined default 'nixpkgs' repository. This example uses the `http` function to specify a repository from a tarball URL, including a SHA256 checksum and a strip prefix for extraction. ```Starlark nix_repo = use_extension("//extensions:repository.bzl", "nix_repo") nix_repo.http( name = "nixpkgs", url = "https://github.com/NixOS/nixpkgs/archive/1eeea1f1922fb79a36008ba744310ccbf96130e2.tar.gz", sha256 = "d6759a60a91dfd03bdd4bf9c834e1acd348cf5ca80c6a6795af5838165bc7ea6", strip_prefix = "nixpkgs-1eeea1f1922fb79a36008ba744310ccbf96130e2", ) use_repo(nix_repo, "nixpkgs") ``` -------------------------------- ### Bazel RC Configuration (.bazelrc) Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/python-container/README.md Configures Bazel to use the host platform provided by rules_nixpkgs. This is essential for integrating Nix with Bazel builds. ```bazel build:nix --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host ``` -------------------------------- ### Configure HTTP Repository with Multiple URLs Source: https://github.com/tweag/rules_nixpkgs/blob/master/README.md Allows specifying a list of URLs for downloading a repository, attempting them in order until one succeeds. This provides flexibility for using local mirrors or alternative download sources. ```Nix nixpkgs_http_repository( name = "my-repo"; urls = [ "http://local-mirror/archive.zip"; "https://example.com/archive.zip"; ]; sha256 = "..."; ) ``` -------------------------------- ### Bazel Remote Execution Configuration Source: https://github.com/tweag/rules_nixpkgs/blob/master/docs/remote-execution-tutorial.md Example Bazel configuration flags for enabling remote execution. These flags specify timeouts and the address of the remote execution gRPC API. ```conf build --remote_timeout=3600 build --remote_executor=grpc://: ``` -------------------------------- ### Configure HTTP Repository with URL and Prefix Stripping Source: https://github.com/tweag/rules_nixpkgs/blob/master/README.md Sets up an HTTP repository with a specified URL and an optional directory prefix to strip from the extracted archive. This is useful for archives that contain a top-level directory with all the relevant files. ```Nix nixpkgs_http_repository( name = "my-repo"; url = "https://example.com/archive.zip"; strip_prefix = "archive-2023"; sha256 = "..."; ) ``` -------------------------------- ### Load Nixpkgs Dependencies (Starlark) Source: https://github.com/tweag/rules_nixpkgs/blob/master/guide.md Loads all necessary dependencies for rules_nixpkgs to function. This is a foundational step before using other rules_nixpkgs functionalities. It typically involves calling a function to set up the required repositories. ```starlark # load everything that rules_nixpkgs rules need to work load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies") rules_nixpkgs_dependencies() ``` -------------------------------- ### Update All Nix Flake Dependencies Source: https://github.com/tweag/rules_nixpkgs/blob/master/guide.md Command to update all dependencies defined in a Nix flake's 'flake.nix' file and lock them in 'flake.lock'. This is a convenient way to bring all project dependencies up to date. ```bash $ nix flake update ``` -------------------------------- ### Define Global Default Nix Repository using Starlark Source: https://github.com/tweag/rules_nixpkgs/blob/master/design/bzlmod/README.md Demonstrates how to use the `use_extension` function to reference a Starlark module extension for managing Nix repositories. It then configures a default 'nixpkgs' repository and makes it available using `use_repo`. This is typically done in the root module. ```Starlark nix_repo = use_extension("//extensions:repository.bzl", "nix_repo") nix_repo.default(name = "nixpkgs") use_repo(nix_repo, "nixpkgs") ``` -------------------------------- ### Conditional Go Toolchain Configuration - Starlark Source: https://github.com/tweag/rules_nixpkgs/blob/master/toolchains/go/README.md This example demonstrates how to conditionally configure the Go toolchain based on the presence of Nix. It generates an `imports.bzl` file that either sets up the Nixpkgs Go toolchain or provides a no-op for non-Nix environments. This approach is useful for projects that might be built in different environments. ```starlark # .bazel-lib/nixos-support.bzl def _has_nix(ctx): return ctx.which("nix-build") != None def _gen_imports_impl(ctx): ctx.file("BUILD", "") imports_for_nix = """ load("@io_tweag_rules_nixpkgs//nixpkgs:toolchains/go.bzl", "nixpkgs_go_configure") def fix_go(): nixpkgs_go_configure(repository = "@nixpkgs") """ imports_for_non_nix = """ def fix_go(): # if go isn't transitive you'll need to add call to go_register_toolchains here pass """ if _has_nix(ctx): ctx.file("imports.bzl", imports_for_nix) else: ctx.file("imports.bzl", imports_for_non_nix) _gen_imports = repository_rule( implementation = _gen_imports_impl, attrs = dict(), ) def gen_imports(): _gen_imports( name = "nixos_support", ) # WORKSPACE // ... http_archive(name = "io_tweag_rules_nixpkgs", ...) // ... local_repository( name = "bazel_lib", path = ".bazel-lib", ) load("@bazel_lib//:nixos-support.bzl", "gen_imports") gen_imports() load("@nixos_support//:imports.bzl", "fix_go") fix_go() ``` -------------------------------- ### Bazel Build Command with Debugging Source: https://github.com/tweag/rules_nixpkgs/blob/master/guide.md This command builds a target using Bazel and enables toolchain resolution debugging. The output helps verify that the Nixpkgs-provided CC toolchain is selected and used for compilation. ```bash > bazel build //src:hello-world --toolchain_resolution_debug '.*' ``` -------------------------------- ### Bazel Configuration for Nixpkgs Toolchain Source: https://github.com/tweag/rules_nixpkgs/blob/master/guide.md These are Bazel configuration directives to be added to the `.bazelrc` file. They instruct Bazel to use the Nix platform and the configured Nixpkgs C/C++ toolchain as the default for C/C++ compilation. ```bazelrc build --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host build --crosstool_top=@nixpkgs_config_cc//:toolchain ``` -------------------------------- ### Import Local Nix Package with Custom Expression using Starlark Source: https://github.com/tweag/rules_nixpkgs/blob/master/design/bzlmod/README.md Demonstrates importing a custom Nix package from an expression or file using an isolated extension. This allows for advanced customization, such as overriding package build inputs. Since global unification is not attempted for such packages, separate external repositories are generated for each distinct request. ```Starlark nix_pkg_isolated = use_extension("@rules_nixpkgs_core//extensions:package.bzl", "nix_pkg", isolate = True) nix_pkg_isolated.attr(attr = "jq", repo = "@nixpkgs-unstable") nix_pkg_isolated.expr( name = "awk", attr = "", expr = """ with import { config = {}; overlays = []; }; gawk-with-extensions.override { extensions = with gawkextlib; [ csv json ]; } """, repo = "@nixpkgs-unstable", ) use_repo(nix_pkg_isolated, "jq", "awk") ``` -------------------------------- ### Change Nixpkgs Version in flake.nix Source: https://github.com/tweag/rules_nixpkgs/blob/master/guide.md Demonstrates how to manually change the Nixpkgs input in a 'flake.nix' file to point to a different branch or tag. This allows for explicit control over the Nixpkgs version used by the flake. ```nix - nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; ``` -------------------------------- ### Run Python Flask App in Docker Container Source: https://github.com/tweag/rules_nixpkgs/blob/master/examples/python-container/README.md Shows how to run a Python script (`hello.py`) within the loaded Docker image. It uses `docker run` with volume mounting for the script and specifies the image name and the command to execute. ```bash docker run -v $PWD/hello.py:/hello.py:ro --rm -it python39-base-image-unwrapped:ypv5lns0sbbf0jgkkjsyxgxxlphnaaaa python /hello.py ``` -------------------------------- ### Integrate rules_nixpkgs into Bazel WORKSPACE Source: https://github.com/tweag/rules_nixpkgs/blob/master/guide.md Bazel WORKSPACE file configuration to load the 'rules_nixpkgs' ruleset. It uses the 'http_archive' rule to fetch the ruleset from a GitHub release, specifying the SHA256 checksum and a strip prefix. ```bazel # load the http_archive rule itself load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # load rules_nixpkgs http_archive( name = "io_tweag_rules_nixpkgs", sha256 = "2a555348d7f8593fca2bf3fc6ce53c5d62929de81b6c292e23f16c557c0ae45a", strip_prefix = "rules_nixpkgs-0.11.1", urls = ["https://github.com/tweag/rules_nixpkgs/releases/download/v0.11.1/rules_nixpkgs-0.11.1.tar.gz"], ) ``` -------------------------------- ### Configure HTTP Repository with Authentication Source: https://github.com/tweag/rules_nixpkgs/blob/master/README.md Defines how to configure an HTTP repository with custom authentication patterns for cloud storage providers. It uses a dictionary to map hostnames to authorization patterns, supporting login and password tokens for generating HTTP Authorization headers. ```Nix nixpkgs_http_repository( name = "my-repo"; url = "https://storage.cloudprovider.com/my-bucket/my-archive.zip"; auth = { "storage.cloudprovider.com" = "Bearer "; }; netrc = "~/.netrc"; sha256 = "..."; ) ``` -------------------------------- ### Expose Locked Nixpkgs Version for Bazel Source: https://github.com/tweag/rules_nixpkgs/blob/master/guide.md A Nix expression that reads the locked Nixpkgs version from 'flake.lock' and makes it available for use in Bazel builds. This ensures consistency between the development environment and the build environment. ```nix let lock = builtins.fromJSON (builtins.readFile ./flake.lock); spec = lock.nodes.nixpkgs.locked; nixpkgs = fetchTarball "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz"; in import nixpkgs ``` -------------------------------- ### Basic Bazel C++ Binary Rule Source: https://github.com/tweag/rules_nixpkgs/blob/master/guide.md Defines a simple C++ binary target in Bazel. It specifies the target name and the source files. This is a fundamental building block for C++ projects managed by Bazel. ```bzl cc_binary( name = "hello-world", srcs = ["hello-world.cc"], ) ``` -------------------------------- ### Configure Go Toolchain with Nixpkgs Source: https://context7.com/tweag/rules_nixpkgs/llms.txt Configure a Go toolchain from Nixpkgs, automatically registering cross-compilation toolchains for all platforms supported by rules_go. Supports basic configuration, custom Go versions, and sourcing from custom Nix expressions or files. ```bzl load("@io_tweag_rules_nixpkgs//toolchains/go.bzl", "nixpkgs_go_configure") # Basic Go configuration nixpkgs_go_configure( repository = "@nixpkgs", ) # Custom Go version nixpkgs_go_configure( sdk_name = "go_sdk", attribute_path = "go_1_21", repository = "@nixpkgs", ) # From a custom Nix expression nixpkgs_go_configure( sdk_name = "go_custom", nix_file_content = """ with import {}; buildEnv { name = "go-sdk"; paths = [ go_1_22 ]; } """, repository = "@nixpkgs", ) # With custom Nix file nixpkgs_go_configure( sdk_name = "go_patched", nix_file = "//nix:go.nix", nix_file_deps = ["//nix:patches/go-patch.patch"], repository = "@nixpkgs", ) # .bazelrc # build --host_platform=@rules_nixpkgs_core//platforms:host ```