Minimal (?) repo that contains Haskell build set up with rules_bazel, with a
nixpkgs-sourced GHC, and is able to build the results using Bazel from within
nix-build itself with the same toolchain.
Latter is contrieved, since nix-build can't be run inside nix-build, so
rules_haskell can't source its dependent toolchain from nix when bazel is
being run inside a nix-build. See WORKSPACE.nix.part file and release.nix
for details.
Running inside nix-build is needed if you want to use Hydra CI, for example, or depend on Bazel-built binaries from other nix files (maybe for a nixops deployment).
The contents of the nix dir implement niv-style nix version pinning, so the
deps are hermetic and independent of the nix-channel version of the user.
The release.nix file is the main nix-build target, resulting in binaries,
tests and test results.
The treetide dir is the monorepo top.
-
treetide/thirdparty/haskell/BUILDalong withghc.nixdefine the libraries we import from Nix. -
treetide/haskell/build_defscontains some Bazel shorthands for declaring common deps. -
treetide/haskell/extendedcontains some extended upstream libs, using the extended pattern (thus the name extended... ok you likely get it). -
Other dirs in the monorepo are laid out according to project structure. Now we just have the
foo_*family of a toy library, test and binary, along with theirBUILDrules. -
.bazelignorecan be used to exclude eventualnode_modulesinside the monorepo, so Bazel doesn't get confused by BUILD files in there. -
.bazelrcsets up some Bazel compatibility flags, and instructsrules_haskellto pull toolchains from Nix. Note: latter instruction is dropped when building usingnix-build, seerelease.nix.
Having nix installed is a prerequisite.
To build locally while developing:
-
Get a nix shell using
nix-shell. -
Then
bazel build -c opt //treetide/.... -
Test using
LC_ALL=C.UTF-8 ./bazel-bin/treetide/foo_test.
Note: can also execute single-target REPL, or set up REPL rules for multi-target repl.
Note: can test directly using bazel test -c opt //treetide/..., but that
needs a custom main wrapper that forces GHC into UTF-8 mode. But that's a
different story... Ping if interested.
Execute nix-build release.nix. This will build all targets and run the tests.
The symlinked results output has a directory for the binaries (executables)
and tests, respectively. The results-2 dir contains the test logs (if
successful).
Note: there are some tools available in the nix-shell, see
README.haskell.md for details.
Cleanup PRs, additional tooling welcome!