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
1 change: 0 additions & 1 deletion examples/toolchains/python/.bazeliskrc

This file was deleted.

1 change: 1 addition & 0 deletions examples/toolchains/python/.bazeliskrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
USE_BAZEL_VERSION=7.x
3 changes: 2 additions & 1 deletion examples/toolchains/python/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import %workspace%/../../../.bazelrc.remote-cache

build:nix --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host
build:nix --host_platform=@rules_nixpkgs_core//platforms:host
build:nix --crosstool_top=@nixpkgs_config_cc//:toolchain
1 change: 1 addition & 0 deletions examples/toolchains/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MODULE.bazel.lock
2 changes: 2 additions & 0 deletions examples/toolchains/python/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@rules_python//python:py_binary.bzl", "py_binary")

py_binary(
name = "hello",
srcs = ["hello.py"],
Expand Down
54 changes: 54 additions & 0 deletions examples/toolchains/python/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module(
name = "hello_world_python",
version = "0.0.0",
)

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 = "rules_nixpkgs_python")
local_path_override(
module_name = "rules_nixpkgs_python",
path = "../../../toolchains/python",
)

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

#
# Nixpkgs
#

nix_repo = use_extension("@rules_nixpkgs_core//extensions:repository.bzl", "nix_repo")
nix_repo.file(
name = "nixpkgs",
file = "//:nixpkgs.nix",
file_deps = [
"//:nixpkgs.json",
],
)
use_repo(nix_repo, "nixpkgs")

#
# Toolchains
#

extension_configure = use_extension("//:extension.bzl", "extension_configure")
use_repo(extension_configure, "nixpkgs_config_cc")
use_repo(extension_configure, "nixpkgs_config_cc_toolchains")
use_repo(extension_configure, "nixpkgs_config_cc_info")
use_repo(extension_configure, "nixpkgs_python_toolchain")
use_repo(extension_configure, "nixpkgs_python_toolchain_python3")

register_toolchains("@nixpkgs_config_cc_toolchains//:all")
register_toolchains("@nixpkgs_python_toolchain//:all")
2 changes: 1 addition & 1 deletion examples/toolchains/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ To run the example with Nix, issue the following command:
nix-shell --command 'bazel run --config=nix :hello'
```

To specify Python version or modules, change the `python3_attribute_path` parameter in the `nixpkgs_python_configure` call in the `WORKSPACE` file.
To specify Python version or modules, change the `python3_attribute_path` parameter in the `nixpkgs_python_configure` call in the `extension.bzl` file.
25 changes: 0 additions & 25 deletions examples/toolchains/python/WORKSPACE

This file was deleted.

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

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

nixpkgs_python_configure(
python3_attribute_path = "python312.withPackages(ps: with ps; [ numpy opencv4 ])",
repository = "@nixpkgs",
register = False,
)

extension_configure = module_extension(
implementation = _extension_configure_impl,
)
6 changes: 3 additions & 3 deletions examples/toolchains/python/nixpkgs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"owner": "NixOS",
"repo": "nixpkgs",
"branch": "nixos-23.11",
"rev": "b2cf36f43f9ef2ded5711b30b1f393ac423d8f72",
"sha256": "07mmgn752nzh8fish8ff5ar9dbdbiv79qb3hl4sazbckqkw38avc"
"branch": "25.05",
"rev": "11cb3517b3af6af300dd6c055aeda73c9bf52c48",
"sha256": "1915r28xc4znrh2vf4rrjnxldw2imysz819gzhk9qlrkqanmfsxd"
}
2 changes: 1 addition & 1 deletion examples/toolchains/python/shell.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ pkgs ? import ./nixpkgs.nix { } }:

pkgs.mkShellNoCC {
nativeBuildInputs = [ pkgs.nix pkgs.bazel_6 ];
nativeBuildInputs = [ pkgs.nix pkgs.bazel_7 ];
env.BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN = "1";
}
Loading