cabal2nix
cabal2nix copied to clipboard
OS conditionals and flags in general
I didn't find reference to this issue, so I wanted to ask it as broadly as possible: is there an intention to better support cabal flags such as compiler version conditionals, but particularly operating system conditionals?
As things stand, the generated Nix is very Linux-centric. To accommodate the switching logic expressible in the Cabal language would mean some burden on existing Linux users in the form of more complex Nix expressions that replicate that logic. In my cabbage
tool, for instance, there is support for dealing with framework
dependencies needed on OS X. With the nixpkgs Haskell infrastructure, these can be shoe-horned into buildInputs
so that they are propagated, but it requires per-package reconfiguration. There are additionally changes to the other dependency fields depending on the platform (e.g. the OpenGL
framework on OS X vs. mesa
on Linux).
I can make PRs to fix this for darwin users on a case-by-case basis in configuration-common.nix
as I encounter problems, or the configuration logic can be pushed down into the derivations themselves. Do the Haskell infrastructure maintainers have an opinion on this?
https://github.com/NixOS/cabal2nix/blob/master/doc/00-future-of-haskell-packaging-in-nixpkgs.md describes our plans for the future. The item https://github.com/NixOS/cabal2nix/blob/master/doc/03-map-cabal-files-to-nix-without-information-loss.md seems particularly relevant for your question.
This is excellent, thank you! I had been thinking that a relatively easy, low-impact option would be to generate per-platform derivations when an os
conditional is used in a cabal file, but that still leaves flags not particularly well supported. I think what you've already done with flags is actually quite good, frankly, but the per-platform build dependencies are a killer.
They're also a bit tricky to convert to Nix for two main reasons:
-
They are not necessarily all in one place, but have a cumulative appending behavior on the list of dependencies.
-
They have default fall-through on conditionals. A cabal author today can somewhat effectively target
darwin
by writing
if os(linux) || os(windows)
...
else
-- darwin things
The latter point is why I started thinking about per-platform derivations as we could then just ask for the cumulative options for each supported platform and let the Cabal
library figure it all out. One strategy would be to collapse the per-platform logic with Cabal
, and then combine them all into one Nix expression that guards the differences.
The newly introduced callHackage
function solves this problem (almost) completely because the generated Nix expressions will be created specifically for the targetted OS and compiler. There's no support for specifying flags yet, but that should be easy to add.