Skip to content

An example of a fully hermetic build with self-installing nix

Notifications You must be signed in to change notification settings

filmil/bazel-nix-flakes

Repository files navigation

Fully hermetic bazel build with nix, without /nix/store Test status

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.

  1. install bazelisk, name it bazel
  2. 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


bazel-nix-flakes-example

The example is generating a local nixpkgs repository using the flakes.lock file already present on flakes projects.

Requirements

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"

About

An example of a fully hermetic build with self-installing nix

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published