Stream: haskell-flake

Topic: Using non-haskell dependencies


view this post on Zulip Perigord (Nov 28 2024 at 08:29):

sandbox.cabal

pkgconfig-depends: libavcodec

Main.hs

foreign import capi "libavcodec/avcodec.h avcodec_version"
  c_avcodecVersion :: CInt

Just wanted to know how I would be able to add C libraries especially using the pkgconfig-depends in cabal. Currently lost on where to add pkgs.ffmpeg.lib and pkgs.ffmpeg.dev.

view this post on Zulip Notification Bot (Jan 06 2025 at 14:21):

Srid has marked this topic as unresolved.

view this post on Zulip Srid (Jan 06 2025 at 14:22):

Hmm, I think we should create a documentation page for this.

Quick answer: you need staticWhich along with extraBuildDepends. You already use the later, just need the former.

view this post on Zulip Daniel Herrera Rendón (Jan 06 2025 at 20:25):

Thanks, @Srid ! I'm a huge fan, btw.

This worked:

cowsayBin :: FilePath
cowsayBin = $(staticWhich "cowsay")

cowsay :: IO String
cowsay = do
  (_, mhout, _, _) <- createProcess (shell $ show cowsayBin <> " hola") { std_out = CreatePipe }
  case mhout of
    Just hout -> hGetContents hout
    Nothing -> pure "mhout failed"

Would staticWhichNix be a better fit?

Is there a reason this way is better?

On my previous iteration of this flake (not using haskell-flake) I used pkgs.haskell.lib.addBuildDepends this way and that worked. Are there advantages to using the which package?

Thanks again and cheers all the way from Querétaro, México : )

view this post on Zulip Srid (Jan 06 2025 at 20:29):

Great. Yes, using staticWhich basically hardcodes the full path to the binary at compile time, so it is guaranteed to be available on user's systems. Otherwise, you rely on it being in $PATH.

staticWhichNix is the same, but expects it to to be in Nix store, thus limiting your software to work only on Nix

view this post on Zulip Srid (Jan 06 2025 at 20:30):

Its implementation is simple enough to see what's going on: https://hackage.haskell.org/package/which-0.2.0.2/docs/src/System.Which.html#staticWhichNix

view this post on Zulip Daniel Herrera Rendón (Jan 06 2025 at 20:37):

I retract what I said about it working with pkgs.haskell.lib.addBuildDepends. I thought it did because I had no errors, but that was because I wasn't using it at all. I also had to use the which package to make it work on my previous flake iteration.


Last updated: Feb 05 2025 at 17:45 UTC