Nix vs. Cabal Conditionals
I am almost ready to merge my PhatSort
changes to the develop branch and push to GitHub. The only
thing that does not work is the Nix
configuration. The current configuration makes use of cabal2nix, which does not
seem to work well with conditional
compilation.
The package includes two conditionals. The library uses a conditional to only build a module on non-Windows platforms, as described in the FFI Sync blog entry.
if !os(windows)
  other-modules:
      PhatSort.Monad.Sync.UnistdThe test suite uses a conditional to only depend on HMock and build tests that use HMock when using GHC 8.6 or newer. This is required because I test PhatSort on older versions of GHC than are supported by HMock.
if impl(ghc >= 8.6.1)
  other-modules:
    PhatSort.Cmd.PhatSort.HMock
  build-depends:
    HMockThe package builds and all tests pass using all of the supported GHC versions when using Stack or Cabal, but Nix builds fail. It appears that the above conditionals are not being parsed (correctly). Searching for information about this problem, I found an OS conditionals and flags in general issue that links to some documentation titled “Map Cabal Files To Nix Without Information Loss” that confirms my suspicions.
The issue suggests using the callHackage function
instead, but I am not sure how to use callHackage to do
what I want. I unfortunately do not have time to really dig into the
problem at this time, especially with the incredibly slow build
times. I would like to move forward with PhatSort,
so I am considering removing the Nix configuration from the project
until I can find a way to make it work with conditional compilation.