How to set cabal flag from shell.nix?

By default, I create my project without nix, and the executable is statically linked. But when building with nixI want to associate it dynamically. So I added a switch to myproj.cabal:

flag dynamic
  description: Build only dynamic binaries
  default: False

executable RunMe
  ghc-options:         -O2 -Wall
  if !flag(dynamic)
    ghc-options: -optl-static -static

Now I can create a project using

stack --nix --nix-packages=zlib install --flag myproj:dynamic

To avoid passing command line parameters every time, I created shell.nix:

{ghc}:
with (import <nixpkgs> {});
haskell.lib.buildStackProject {
  inherit ghc;
  name = "myproj";
  buildInputs = [ zlib ];
}

Now I do not know how to pass the flag to cabal from the nix file. Based on buildStackProject, I tried to install buildPhase, for example.

haskell.lib.buildStackProject {
  ...
  buildPhase = "stack build --flag=myproj:dynamic";
}

but it does not change anything. How to pass a flag to bondage from a file nix?

+4
source share
1 answer

, nix . nix ( buildStackPackage), GHC . stack , stack cabal, . nix .nix , , nix-build, nix-shell. , stack2nix stackage2nix.

, . shell.nix . stack.yaml:

nix:
    shell-file: shell.nix

:

stack --nix --flag myproj:dynamic

, , GHC zlib nix.

0

Source: https://habr.com/ru/post/1692133/


All Articles