Is there something like writeShellScriptBin for haskell?

I think my title already says everything. I’d love to use something like Shelly for small scripts in my system.

Something like writeHaskellBin could do two different things

  • run an syntax/compile-check on the script and then enter it as plaintext with a runhaskell interpreter
  • compile the script to a binary

I think the second makes more sense but the first is very close to what pkgs.writeShellScriptBin does (just for sh not for haskell).

Do you know about something which provides this? Any useful hints on how to get there would be highly appreciated. Thanks!

Yes, there are the nix-writers.

I will try to do a writeup about them in the near future.

you could use them like this in your configuration.nix:

...
environment.systemPackages = [
  (pkgs.writers.writeHaskellBin "missiles" { libraries = [ pkgs.haskellPackages.acme-missiles ]; } ''
    import Acme.Missiles
    main = launchMissiles
  '')
];
...
6 Likes

Wow! That’s awesome. Exactly what I wanted. Thank you so much!

Just sad, that I couldn’t find this even by intensive and varying search querys to various search engines. (Well, now I know that a grep on my nixpkgs checkout would have helped.)