An experiment in fully hermetic, but also self-installing nix based hermetic bazel build.
The build rules at https://github.com/tweag/rules_nixpkgs allow bazel to bring
in dependencies from nixpkgs. But, it requires having a /nix/store
on
your machine, which in turn means you need to have a pre-existing system-wide
nix installation.
This repository goes one step further: bazel
will instantiate a bazel-specific
nix store and pull in the appropriate dependencies from nixpkgs. This means that
you will not need to install nix in order to use the packages from nixpkgs.
This example repo adds the dir //tools
to an existing rules_nixpkgs
example, which makes a stand-alone and ephemeral nix installation in your bazel
cache, and prepares all dependencies for compilation. It then builds a hello
world app.
- install bazelisk, name it
bazel
- try:
bazel run :hello
The actual reusable set of bazel local nix rules is at: https://github.com/filmil/bazel_local_nix.
Original README.md below. From https://github.com/tweag/rules_nixpkgs/tree/master/examples/flakes
The example is generating a local nixpkgs repository using the flakes.lock
file already present on
flakes projects.
The nix package manager should be installed with flakes support enabled.
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"