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
2 changes: 1 addition & 1 deletion .bazeliskrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
USE_BAZEL_VERSION=6.x
USE_BAZEL_VERSION=7.x
3 changes: 3 additions & 0 deletions .bazelrc.common
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
build --host_platform=@rules_nixpkgs_core//platforms:host

# do not enable bzlmod by default
common --noenable_bzlmod

common:bzlmod --enable_bzlmod
common:bzlmod --registry=https://bcr.bazel.build
common:bzlmod --experimental_isolated_extension_usages
Expand Down
1 change: 1 addition & 0 deletions .bazelrc.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
build --java_language_version=11
build --tool_java_runtime_version=nixpkgs_java_11
build --tool_java_language_version=11
build --repo_env=JAVA_HOME

# vim: ft=conf
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2338,7 +2338,7 @@ API](https://github.com/bazelbuild/rules_python#using-the-package-installation-r
`nixpkgs_python_repository` should be a drop-in replacement of `pip_parse`.
As such, it also provides a `requirement` function.

:warning: Using the `requirement` fucntion inherits the same advantages and
:warning: Using the `requirement` function inherits the same advantages and
limitations as the one in rules_python. All the function does is create a
label of the form `@{nixpkgs_python_repository_name}//:{package_name}`.
While depending on such a label directly will work, the layout may change
Expand Down
9 changes: 9 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
workspace(name = "io_tweag_rules_nixpkgs")

local_repository(
name = "io_tweag_rules_nixpkgs",
path = ".",
)

# For documentation

local_repository(
Expand Down Expand Up @@ -77,3 +82,7 @@ nixpkgs_go_configure(repository = "@nixpkgs")
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies")

go_rules_dependencies()

load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()
4 changes: 2 additions & 2 deletions core/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module(
version = "0.13.0",
)

bazel_dep(name = "platforms", version = "0.0.4")
bazel_dep(name = "platforms", version = "0.0.9")
bazel_dep(name = "bazel_features", version = "1.36.0")
bazel_dep(name = "bazel_skylib", version = "1.0.3")
bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "rules_license", version = "1.0.0")

nix_repo = use_extension("//extensions:repository.bzl", "nix_repo")
Expand Down
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 gnumake bazel_7 ];
};
});
}
3 changes: 3 additions & 0 deletions examples/python-container/.bazelrc
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
import %workspace%/../../.bazelrc.remote-cache

# TODO(cb) migrate to bzlmod
common --noenable_bzlmod
2 changes: 1 addition & 1 deletion examples/python-container/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ platform(
py3_image(
name = "hello_image",
srcs = [ "hello.py" ],
base = "@python310_base_image//image",
base = "@python3_base_image//image",
main = "hello.py",

# Currently needs to be built on Linux.
Expand Down
5 changes: 5 additions & 0 deletions examples/python-container/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# bazel-nix-python-container

_Note_: this example uses rules_docker, which is not actively maintained anymore. It is
depending on old versions of other rulesets and does not support bzlmod.

<!-- TODO(cb): modernize this example and use rules_img or rules_oci. -->

An example for a minimal Python flask app running in a Nix-based, Bazel-built, Docker container.
Based on https://github.com/jvolkman/bazel-nix-example. This step-by-step guide below and the
dependency on flask have been added.
Expand Down
51 changes: 45 additions & 6 deletions examples/python-container/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,44 @@ local_repository(
path = "../../",
)

http_archive(
name = "rules_cc",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.7/rules_cc-0.0.7.tar.gz"],
sha256 = "eb389b5b74862a3d310ee9d6c63348388223b384ae4423ff0fd286fcd123942d",
strip_prefix = "rules_cc-0.0.7",
)

http_archive(
name = "io_bazel_rules_go",
sha256 = "f4a9314518ca6acfa16cc4ab43b0b8ce1e4ea64b81c38d8a3772883f153346b8",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.50.1/rules_go-v0.50.1.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.50.1/rules_go-v0.50.1.zip",
],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

http_archive(
name = "bazel_gazelle",
integrity = "sha256-tzh/cu+1n4duTarkLx05EtDUVWPqx8sj0d4LCUq1iM8=",
urls = [
"https://mirror.bazel.build/github.com/bazel-contrib/bazel-gazelle/releases/download/v0.34.0/bazel-gazelle-v0.34.0.tar.gz",
"https://github.com/bazel-contrib/bazel-gazelle/releases/download/v0.34.0/bazel-gazelle-v0.34.0.tar.gz",
],
)

load("@io_tweag_rules_nixpkgs//nixpkgs:repositories.bzl", "rules_nixpkgs_dependencies")
rules_nixpkgs_dependencies()

# Define nixpkgs version
load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_git_repository")
nixpkgs_git_repository(
name = "nixpkgs",
revision = "22.05",
sha256 = "0f8c25433a6611fa5664797cd049c80faefec91575718794c701f3b033f2db01",
# branch nixos-25.05
revision = "ac62194c3917d5f474c1a844b6fd6da2db95077d",
sha256 = "bf13a5324bc541eeda82fb97a80ba6326acc4fa91d6bac8f78fb309ce4a31e37",
)

# Configure the C++ toolchain
Expand All @@ -40,7 +69,13 @@ nixpkgs_cc_configure(
# Configure python
load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_python_configure")
nixpkgs_python_configure(
python3_attribute_path = "python310.withPackages(ps: [ ps.flask ])",
python3_attribute_path = "python3.withPackages(ps: [ ps.flask ])",
repository = "@nixpkgs",
)

# Configure the Go toolchain
load("@io_tweag_rules_nixpkgs//nixpkgs:toolchains/go.bzl", "nixpkgs_go_configure")
nixpkgs_go_configure(
repository = "@nixpkgs",
)

Expand All @@ -54,6 +89,10 @@ http_archive(
"https://mirror.bazel.build/github.com/bazelbuild/rules_docker/releases/download/v0.26.0/rules_docker-v0.26.0.tar.gz",
"https://github.com/bazelbuild/rules_docker/releases/download/v0.26.0/rules_docker-v0.26.0.tar.gz",
],
patches = [
"//:rules_docker-skip-register-go-toolchains.diff",
],
patch_args = ["-p1"],
)

load("@io_bazel_rules_docker//repositories:repositories.bzl", container_repositories = "repositories",)
Expand All @@ -70,17 +109,17 @@ py3_image_repos()

load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_package")
nixpkgs_package(
name = "raw_python310_base_image",
name = "raw_python3_base_image",
build_file_content = """
package(default_visibility = [ "//visibility:public" ])
exports_files(["image"])
""",
nix_file = "//:python310_base_image.nix",
nix_file = "//:python3_base_image.nix",
repository = "@nixpkgs//:default.nix",
)

load("@io_bazel_rules_docker//container:container.bzl", "container_load" )
container_load(name = "python310_base_image", file = "@raw_python310_base_image//:image")
container_load(name = "python3_base_image", file = "@raw_python3_base_image//:image")

register_execution_platforms(
"@io_tweag_rules_nixpkgs//nixpkgs/platforms:host",
Expand Down
6 changes: 3 additions & 3 deletions examples/python-container/nixpkgs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"owner": "NixOS",
"repo": "nixpkgs",
"branch": "22.11",
"rev": "f413457e0dd7a42adefdbcea4391dd9751509025",
"sha256": "sha256-F7/F65ZFWbq7cKSiV3K2acxCv64jKaZZ/K0A3VNT2kA="
"branch": "nixos-25.05",
"rev": "ac62194c3917d5f474c1a844b6fd6da2db95077d",
"sha256": "16KkgfdYqjaeRGBaYsNrhPRRENs0qzkQVUooNHtoy2w="
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let
coreutils

# Specify your Python version and packages here:
(python310.withPackages( p: [p.flask] ))
(python3.withPackages( p: [p.flask] ))

stdenv.cc.cc.lib
iana-etc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/repositories/go_repositories.bzl b/repositories/go_repositories.bzl
index e6998c3..23a0f4b 100644
--- a/repositories/go_repositories.bzl
+++ b/repositories/go_repositories.bzl
@@ -37,7 +37,7 @@ def go_deps(go_repository_default_config = "@//:WORKSPACE"):
go_repository_default_config (str, optional): A file used to determine the root of the workspace.
"""
go_rules_dependencies()
- go_register_toolchains()
+ #go_register_toolchains()
gazelle_dependencies(go_repository_default_config = go_repository_default_config)
excludes = native.existing_rules().keys()
if "com_github_google_go_containerregistry" not in excludes:
2 changes: 1 addition & 1 deletion examples/python-container/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pkgs.mkShellNoCC {
nativeBuildInputs = [
pkgs.bazel_6
pkgs.bazel_7
];
}

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

common --noenable_bzlmod

build:nix --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host
13 changes: 9 additions & 4 deletions examples/toolchains/python/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_git_repository")

nixpkgs_git_repository(
name = "nixpkgs",
revision = "22.05",
sha256 = "0f8c25433a6611fa5664797cd049c80faefec91575718794c701f3b033f2db01",
# branch nixos-25.05
revision = "ac62194c3917d5f474c1a844b6fd6da2db95077d",
sha256 = "bf13a5324bc541eeda82fb97a80ba6326acc4fa91d6bac8f78fb309ce4a31e37",
)

load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_python_configure")
load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_cc_configure", "nixpkgs_python_configure")

nixpkgs_cc_configure(
repository = "@nixpkgs",
)

nixpkgs_python_configure(
python3_attribute_path = "python39.withPackages(ps: with ps; [ numpy opencv4 ])",
python3_attribute_path = "python3.withPackages(ps: with ps; [ numpy opencv4 ])",
repository = "@nixpkgs",
)
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": "nixos-25.05",
"rev": "ac62194c3917d5f474c1a844b6fd6da2db95077d",
"sha256": "16KkgfdYqjaeRGBaYsNrhPRRENs0qzkQVUooNHtoy2w="
}
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";
}
3 changes: 3 additions & 0 deletions examples/toolchains/rust/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import %workspace%/../../../.bazelrc.remote-cache

# TODO(cb) migrate to bzlmod
common --noenable_bzlmod

# merge env and action_env variables for action.run
# (note, this is the default in Bazel 7)
build --incompatible_merge_fixed_and_default_shell_env
Expand Down
12 changes: 10 additions & 2 deletions examples/toolchains/rust/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ local_repository(

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "platforms",
integrity = "sha256-KXQuhydYCbXlmNwvBNhpYMx6VbMGfZciHJq7yZJr/w8=",
urls = [
"https://github.com/bazelbuild/platforms/releases/download/0.0.11/platforms-0.0.11.tar.gz",
],
)

# https://bazelbuild.github.io/rules_rust/#setup
http_archive(
name = "rules_rust",
sha256 = "f1306aac0b258b790df01ad9abc6abb0df0b65416c74b4ef27f4aab298780a64",
integrity = "sha256-liB1wWSmA/Q/tKPRlhWrkeQbzQWByNovcKGu8nOB/lM=",
urls = [
"https://github.com/bazelbuild/rules_rust/releases/download/0.56.0/rules_rust-0.56.0.tar.gz",
"https://github.com/bazelbuild/rules_rust/releases/download/0.58.0/rules_rust-0.58.0.tar.gz",
],
)

Expand Down
Loading
Loading