Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ jobs:
read -a ${1} <<< $(echo ${!p//$2})
}

pushd examples/cc-template
echo
echo "::group::Running $(head -n1 README.md) with Nix, WORKSPACE"
nix develop --command bazel run --noenable_bzlmod //src:hello-world
popd

pushd examples/cc-template
echo
echo "::group::Running $(head -n1 README.md) with Nix, bzlmod"
Expand Down Expand Up @@ -144,20 +138,16 @@ jobs:
popd

- name: Build bazel-nix-python-container with Nix
uses: tweag/run-nix-shell@v0
if: ${{ runner.os == 'Linux' }}
with:
pure: false
working-directory: examples/python-container
run: bazel build :hello_image
working-directory: examples/python-container
run: |
nix-shell --pure --run "bazel build :hello_image"

- name: Run bazel-nix-flakes-example with Nix
uses: tweag/run-nix-shell@v0
if: ${{ runner.os == 'Linux' }}
with:
pure: false
working-directory: examples/flakes
run: bazel run --crosstool_top=@nixpkgs_config_cc//:toolchain :hello
working-directory: examples/flakes
run: |
nix-shell --pure --run "bazel run :hello"

all_ci_tests:
runs-on: ubuntu-latest
Expand Down
35 changes: 17 additions & 18 deletions examples/cc-template/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
module(name = "rules_nixpkgs_guide")

bazel_dep(name = "rules_nixpkgs_core")
# Remove to use rules_nixpkgs_core from the BCR
local_path_override(
module_name = "rules_nixpkgs_core",
path = "../../core",
)

bazel_dep(name = "rules_nixpkgs_cc")
local_path_override(
module_name = "rules_nixpkgs_cc",
path = "../../toolchains/cc",
)

bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "rules_cc", version = "0.2.14")

nix_repo = use_extension("@rules_nixpkgs_core//extensions:repository.bzl", "nix_repo")
nix_repo.file(
name = "nixpkgs",
Expand All @@ -15,22 +23,13 @@ nix_repo.file(
)
use_repo(nix_repo, "nixpkgs")

bazel_dep(name = "rules_nixpkgs_cc")
# Replace by archive_override to download a rules_nixpkgs_cc revision.
# (rules_nixpkgs_cc is not available on the BCR, yet.)
#
# archive_override(
# module_name = "rules_nixpkgs_cc",
# urls = ["https://github.com/tweag/rules_nixpkgs/releases/download/v0.11.1/rules_nixpkgs-0.11.1.tar.gz"],
# integrity = "sha256-KlVTSNf4WT/KK/P8bOU8XWKSnegbbCkuI/FsVXwK5Fo=",
# strip_prefix = "rules_nixpkgs-0.11.1/toolchains/cc",
# )
local_path_override(
module_name = "rules_nixpkgs_cc",
path = "../../toolchains/cc",
)
# Toolchains
#

cc_configure = use_extension("//:extension.bzl", "cc_configure")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we absolutely have to define our own module extension to use cc toolchains ?
I feel like that extensions pertains to rules_nixpkgs_cc itself, with tags for the config. But maybe it is not implemented yet ?

use_repo(cc_configure, "nixpkgs_config_cc")
use_repo(cc_configure, "nixpkgs_config_cc_toolchains")
use_repo(cc_configure, "nixpkgs_config_cc_info")

# TODO remove transitive rules_nixpkgs_cc dependencies.
# Once there is a module extension for the cc toolchain.
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "rules_cc", version = "0.0.9")
register_toolchains("@nixpkgs_config_cc_toolchains//:all")
53 changes: 0 additions & 53 deletions examples/cc-template/WORKSPACE

This file was deleted.

7 changes: 0 additions & 7 deletions examples/cc-template/WORKSPACE.bzlmod

This file was deleted.

12 changes: 12 additions & 0 deletions examples/cc-template/extension.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@rules_nixpkgs_cc//:cc.bzl", "nixpkgs_cc_configure")

def _cc_configure_impl(module_ctx):
nixpkgs_cc_configure(
name = "nixpkgs_config_cc",
repository = "@nixpkgs",
register = False,
)

cc_configure = module_extension(
implementation = _cc_configure_impl,
)
6 changes: 3 additions & 3 deletions examples/cc-template/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/flakes/.bazelrc
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
import %workspace%/../../.bazelrc.remote-cache

build --host_platform=@rules_nixpkgs_core//platforms:host
build --crosstool_top=@nixpkgs_config_cc//:toolchain
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having crosstool_top used seems weird. Should it not be selected by default by the toolchain selection engine ?

Or is this intended as a demo on how to force a specific toolchain ?
I feel like crosstool_top is on the verge of deprecation.

35 changes: 35 additions & 0 deletions examples/flakes/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module(name = "rules_nixpkgs_flakes_example")

bazel_dep(name = "rules_nixpkgs_core")
local_path_override(
module_name = "rules_nixpkgs_core",
path = "../../core",
)

bazel_dep(name = "rules_nixpkgs_cc")
local_path_override(
module_name = "rules_nixpkgs_cc",
path = "../../toolchains/cc",
)

bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "rules_cc", version = "0.2.14")

nix_repo = use_extension("@rules_nixpkgs_core//extensions:repository.bzl", "nix_repo")
nix_repo.flake(
name = "nixpkgs",
lock_file = "//:flake.lock",
file_deps = ["//:flake.lock"],
)
use_repo(nix_repo, "nixpkgs")

#
# Toolchains
#

cc_configure = use_extension("//:extension.bzl", "cc_configure")
use_repo(cc_configure, "nixpkgs_config_cc")
use_repo(cc_configure, "nixpkgs_config_cc_toolchains")
use_repo(cc_configure, "nixpkgs_config_cc_info")

register_toolchains("@nixpkgs_config_cc_toolchains//:all")
4 changes: 1 addition & 3 deletions examples/flakes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ The nix package manager should be installed with flakes support enabled.

## Running the example

The local nixpkgs repository can be used by explicitly specifying the generated toolchain.

``bash
nix-shell --run "bazel run --crosstool_top=@nixpkgs_config_cc//:toolchain :hello"
nix-shell --run "bazel run :hello"
```
47 changes: 0 additions & 47 deletions examples/flakes/WORKSPACE

This file was deleted.

13 changes: 13 additions & 0 deletions examples/flakes/extension.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@rules_nixpkgs_cc//:cc.bzl", "nixpkgs_cc_configure")

def _cc_configure_impl(module_ctx):
nixpkgs_cc_configure(
name = "nixpkgs_config_cc",
repository = "@nixpkgs",
attribute_path = "clang_16",
register = False,
)

cc_configure = module_extension(
implementation = _cc_configure_impl,
)
38 changes: 28 additions & 10 deletions examples/flakes/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/flakes/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "C++ environment using Nix flakes";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
Expand All @@ -19,7 +19,7 @@
{
devShells.default = with pkgs; mkShell {
name = "flake-example-shell";
packages = [ gcc gnumake bazel_6 ];
packages = [ gcc nix bazel_7 ];
};
});
}
1 change: 0 additions & 1 deletion examples/python-container/.bazeliskrc

This file was deleted.

1 change: 1 addition & 0 deletions examples/python-container/.bazeliskrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
USE_BAZEL_VERSION=7.x
Loading
Loading