# Teaser: pluggable cabal backends and a Nix backend

**URL:** <https://discourse.haskell.org/t/teaser-pluggable-cabal-backends-and-a-nix-backend/15261>\
**Category:** Uncategorized\
**Created:** [December 4, 2026, 12:10am UTC](https://discourse.haskell.org/t/teaser-pluggable-cabal-backends-and-a-nix-backend/15261 "2026-12-04T00:10:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidylns](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@aidylns](https://discourse.haskell.org/u/aidylns)\
**Post date:** [December 4, 2026, 12:10am UTC](https://discourse.haskell.org/t/teaser-pluggable-cabal-backends-and-a-nix-backend/15261/1 "2026-12-04T00:10:10Z")

</div>

As is the trend,@Ericson2314 and I have been doing some LLM-assisted prototyping of Haskell devX improvements. We changed Cabal (`cabal-install`) into a frontend for build systems, making the original behavior just one of many backend options. If all goes well, Cabal’s commands will just keep working as normal with any backend.

@simonmar’s [Buck2 build system](https://discourse.haskell.org/t/buck2-build-system-for-cabal-projects/14770)could become one of these (instead of an [external command](https://cabal.readthedocs.io/en/stable/external-commands.html)), and we’ve been implementing a Nix-backend as well. Incremental Nix builds for GHC had already been implemented in [sandstone](https://github.com/obsidiansystems/sandstone), so it was relatively easy to create this backend.

Here’s a little demo showing the behavior of the “classic” backend vs. the Nix (cabal-sandstone) backend:

![demo](https://us1.discourse-cdn.com/flex002/uploads/haskell/original/2X/6/6abe6c1257976b1d38424f14f235a5a61a845b46.webp)

The code for the backend is available for anyone caring to look: [GitHub - parenthetical/cabal-sandstone: A Nix backend for Cabal · GitHub](https://github.com/parenthetical/cabal-sandstone) . The repository contains Git submodules linking to our Cabal fork (and many other forks 😅).

Although the `cabal-sandstone` backend shares many advantages with the [cabal-buck2](https://github.com/simonmar/cabal-buck2) command, it loses out on absolute performance.

However, in return you are freed from worrying about how to get GHC and foreign library dependencies. Getting all your build tools and libraries just happens magically, as long as they are correctly declared in your project and your project’s dependencies’ cabal files.

You also get a centralized persistent cache for (intermediate) build artifacts through the Nix store (I always end up with gigabytes of dist-newstyle spread over my worktrees.)

For users who have tried building Haskell with Nix before, here are some differences from prior attempts to be aware of:

- No slow eval times. `cabal-sandstone` in fact doesn’t use the Nix language at all, and certainly no “import from derivation”. All build plan are expressed with low-level “nix store layer” primitives, most notably [dynamic derivations](https://nix.dev/manual/nix/2.36/store/derivation/#dynamic).
- No coarse caching. Nix solutions traditionally built entire packages in one step, because they viewed Cabal as a complex black box. But, since we’re sliding and dicing Cabal as much as we need to, we don’t have those problems. Also, thanks to the the power of dynamic derivations we do not need to know exact dependencies in advance and can dynamically figure out both package-package dependencies and module-module dependencies. We even support cross-package module-module dependencies!

We know our myriad Cabal changes are not going to go upstream in one giant PR. We have a plan to upstream the work “bottom-up”, first addressing some foundational longstanding architectural issues in Cabal, and then decoupling Cabal’s “backend” using that foundation. See some of @ericson2314’s open/draft Cabal PRs for a sneak preview of what that first step entails.

Happy to answer any questions 🙂

---

<div class="post-metadata">

**Author:** ![simonmar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/simonmar/32/5058_2.png) [@simonmar](https://discourse.haskell.org/u/simonmar)\
**Post date:** [December 4, 2026, 12:24pm UTC](https://discourse.haskell.org/t/teaser-pluggable-cabal-backends-and-a-nix-backend/15261/2 "2026-12-04T12:24:53Z")

</div>

I’m interested in understanding the architecture here, and figuring out how we could converge. I poked around a little but it wasn’t obvious to me how I should understand it - what exactly is the interface to the backend?

I’ve been thinking about the interface to the backend as an expanded `plan.json`, as you might have seen from all the Cabal PRs and [RFC: Buck2 backend · Issue #12456 · haskell/cabal · GitHub](https://github.com/haskell/cabal/issues/12456) . Does your approach differ in any fundamental way or are you just passing the same information as Haskell datatypes to the backend? Is the API documented somewhere?

Is the UI always just `cabal build`? In the Buck2 world we like to run `cabal` once and then use `buck2` as the UI. I suppose we could make it possible to do either.

---

<div class="post-metadata">

**Author:** ![TeofilC](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/teofilc/32/3987_2.png) [@TeofilC](https://discourse.haskell.org/u/TeofilC)\
**Post date:** [December 4, 2026, 12:33pm UTC](https://discourse.haskell.org/t/teaser-pluggable-cabal-backends-and-a-nix-backend/15261/3 "2026-12-04T12:33:23Z")

</div>

This sounds like an excellent candidate for a [cabal-proposal](https://github.com/haskell/cabal-proposals/). I think everyone would benefit from a specification for the change you are trying to accomplish, especially when the diffs are understandably so large

---

<div class="post-metadata">

**Author:** ![Ericson2314](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/ericson2314/32/1026_2.png) [@Ericson2314](https://discourse.haskell.org/u/Ericson2314)\
**Post date:** [December 4, 2026, 4:24pm UTC](https://discourse.haskell.org/t/teaser-pluggable-cabal-backends-and-a-nix-backend/15261/4 "2026-12-04T16:24:58Z")

</div>

> [@simonmar](#):
>
> I’m interested in understanding the architecture here, and figuring out how we could converge. I poked around a little but it wasn’t obvious to me how I should understand it

First of all, we’ve chosen to publish this “open notes”, in that [cabal-sandstone/PLAN.org at main · parenthetical/cabal-sandstone · GitHub](https://github.com/parenthetical/cabal-sandstone/blob/main/PLAN.org) and its full history is here. If you point your LLM at that and ask whatever questions you feel like, you can probably figure out a lot. Even figure out things that we don’t know ;).

> [@simonmar](#):
>
> what exactly is the interface to the backend?

@aidylns worked on the pluggable backends _itself_, and so would be better able to answer that than me. But I can answer some related questions.

> [@simonmar](#):
>
> I’ve been thinking about the interface to the backend as an expanded `plan.json`, as you might have seen from all the Cabal PRs and [RFC: Buck2 backend · Issue #12456 · haskell/cabal · GitHub](https://github.com/haskell/cabal/issues/12456) . Does your approach differ in any fundamental way or are you just passing the same information as Haskell datatypes to the backend?

I do think we want to be able to work from an exported stable plan format eventually, but my view is that current `plan.json` isn’t really the right starting point. It is too much an artifact of the design of the current\[1\] solver. In [Per component plan, elaboration in two steps by Ericson2314 · Pull Request #12679 · haskell/cabal · GitHub](https://github.com/haskell/cabal/pull/12679) (stacked atop other PRs), I tried to rework what in Cabal is known as “elaboration” (solver output → concrete build steps) so that it proceeds in two steps:

1. Turn package-level plan (what `cabal-install-solver` spits out today) into a component-level plan (except when custom setups\[2\] etc. prohibit this).

2. Finish elaboration which figures out concrete CLI flags, concrete file paths including `dist-newstyle`, etc. etc.

Part 2 is blatantly backend-specific. Part 1, however, is nicely backend-agnostic while still discarding irrelevant distinctions. For example, post solving, there is no need to care which component comes from which package. That distinction only matters for solving. In terms of how we invoke GHC to actually build things we just don’t care:

- every library, whether it’s top-level or a “sublibrary”, is built the same way
- test suites and benchmarks are built just like regular executables. (The distinction is just how Cabal wants to run them.) All are “leaf” builds that nothing depends on, and don’t end up in any package database.

So it is the “core language” that sits between steps 1 and 2 that I think is what backends actually want.

Ironically while I think this is a great fit for `cabal-buck2` right away, currently `cabal-sandstone` still ends up using the result of step 2 because we want to crib the concrete flags Cabal chose too (rather than reimplement that logic ourselves). I am next going to try to expose the “lowering to CLI flags” functionality used in step 2 separately, as functions that a backend can use or not use as it pleases. That will be better than today when such a backend has to opt into the entire phase 2 which is blatantly “this local machine” and “this `dist-newstyle` directory” specific, and thus not suitable for backends that do distributed builds and don’t store their build products in `dist-newstyle`.

> [@simonmar](#):
>
> Is the API documented somewhere?

No, but most of what I said above is written — somewhere — in that `PLAN.org` I mentioned. The PRs that [Per component plan, elaboration in two steps by Ericson2314 · Pull Request #12679 · haskell/cabal · GitHub](https://github.com/haskell/cabal/pull/12679) builds on I have actually reviewed somewhat, but that one itself is merely the result of me describing the problem and solution as per above, and the LLM doing…something. I would say the concrete implementation is not fit for other human consumption until I went and reviewed it first :).

> [@simonmar](#):
>
> Is the UI always just `cabal build`? In the Buck2 world we like to run `cabal` once and then use `buck2` as the UI. I suppose we could make it possible to do either.

So @aidylns has been dogfooding this as a `cabal <anything>` replacement. He just sets the backend environment variable, using the right `cabal`, and everything “just works” as if he is using stock cabal, without having to think about it.  
It is true that only building is farmed off to Nix, strictly speaking, but that doesn’t mean that is the only interaction.

For example, consider `cabal repl`. The backend (Nix, Buck2, whatever) will be instructed to just build the dependencies. That’s fine; that’s just pruning the build plan a bit so the backend doesn’t “overbuild”. However, then `cabal` wants to run `ghc --interactive` with the right arguments. So the backend needs to be instructed to make sure certain build products are locally available, and also get their locations _back_ to cabal for it to invoke. (I think currently we might just symlink some things in `dist-newstyle` and then run the normal logic for starting the repl. This works, but is rather hamfisted, and not really in the spirit of relegating `dist-newstyle` and all knowledge about it to just the built-in backend.)

All that said, while I think the above is a great workflow for developers, and users wholly uninterested in the details of Nix, Buck2, etc. :), I totally agree that for more “production build” use-cases, it is better to extract a build plan once, and then make sure nothing is needed from the “original” `cabal` process ever again. For this workflow check out the last section of the read-me, [GitHub - parenthetical/cabal-sandstone: A Nix backend for Cabal · GitHub](https://github.com/parenthetical/cabal-sandstone#planning-inside-nix-cabal-sandstone). Not only is the `cabal` process ephemeral, and doesn’t need to stick around for the duration of the build, but the invocation of `cabal` itself, and the creation of all plans and anything else that is needed, is fully driven by Nix. Think of this as Nix/Buck2 both working strictly from a `plan.json` (once the above tech debt is sorted out), and running the commands that create the `plan.json` in the first place.

(For context to others — I imagine @simonmar is already thinking along these lines — in whole-system production builds, Cabal is not going to be the main “entry point”. For example, when building a NixOS configuration — even if the purpose of the image is just to run a server written in Haskell — the Haskell program and its dependencies are going to be just one executable among many. (The build system doesn’t know which executables are the “main event” and which are a “side show”, e.g. just there for system administrators SSHing to the production system when something goes wrong.) It’s very convenient that all `cabal` interactions can just be another node in the build graph in this scenario so we aren’t forced to commit generated files like `plan.json` if we don’t want to, because the actual top-level build step is going to be some mundane configuration assembly shell script, and not anything Haskell-related.)

The bottom line is this tool supports _both_ “I don’t care what Nix is, just make it go brrrr” and “I love Nix, hide the Cabal from me” workflows :).

* * *

1. The solver today currently just thinks about packages and versions, with global coherence. Interestingly enough there are issues about component-level solving ([Per-component dependency solving · Issue #4087 · haskell/cabal · GitHub](https://github.com/haskell/cabal/issues/4087)) and private dependencies support ([Private dependencies · Issue #4035 · haskell/cabal · GitHub](https://github.com/haskell/cabal/issues/4035)). Component-level solving would allow the solver to understand dependencies on a finer-grained level, which will avoid some unnecessary coherence conditions we impose today. Private dependencies force the solver to also consider more hierarchical structure than original “flat” name → version assignments of yore (though currently it is already more sophisticated than that, to be clear).

2. Custom setups are extremely pathological, because they currently force the entire package to be built in a black-box setup-script-controlled arbitrary way, with no finer-grained caching possible. As many people have expressed in other threads already, we should be moving away from them. The `Hooks` method will soon not have many of these deficiencies, but being able to drop down and write “inline Starlark” (for Buck2) or “inline derivations” (for Nix), analogous to “inline assembly” where one just splices in some code in the backend’s native language directly, is also a good option.

---

<div class="post-metadata">

**Author:** ![Ericson2314](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/ericson2314/32/1026_2.png) [@Ericson2314](https://discourse.haskell.org/u/Ericson2314)\
**Post date:** [December 4, 2026, 4:57pm UTC](https://discourse.haskell.org/t/teaser-pluggable-cabal-backends-and-a-nix-backend/15261/5 "2026-12-04T16:57:22Z")

</div>

> [@TeofilC](#):
>
> This sounds like an excellent candidate for a [cabal-proposal](https://github.com/haskell/cabal-proposals/). I think everyone would benefit from a specification for the change you are trying to accomplish, especially when the diffs are understandably so large

I am happy to write things (_looks up at my marathon reply above_), but a proposal feels a bit too “waterfall” for where we are. We are _not_ in a “the backend authors know exactly what they need from Cabal, now the Cabal devs just need to do it!” place :). At most, I’d feel comfortable writing a meta-level proposal: “this is an important direction for the ecosystem, and we should commit resources to it”.

Instead, I think the process is sitting down with the Cabal developers, e.g. in the periodic Cabal development video call, and gradually aligning mental models while working on intermediate steps. I still need to understand all of the diff _myself_, per the above, but I know it is built atop smaller “tech debt” PRs that I do understand, and believe are good (and would be good even without pluggable backends). Those make good warm-up tasks for aligning everyone’s mental models: small, self-contained, and understandable purely in terms of existing code and use cases. Landing them shrinks the diff right away, while @aidylns and I concurrently rework the rest into reviewable PRs to be discussed in future meetings.

I think the above is a pretty good process that starts shrinking the diffs immediately. But the final state isn’t knowable in advance (by design! it’s supposed to emerge from those meetings organically), so there isn’t much a technical proposal could pin down with confidence today.
