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.
# writeHaskell takes a name, an attrset with libraries and haskell version (both optional)
# and some haskell source code and returns an executable.
#
# Example:
# writeHaskell "missiles" { libraries = [ pkgs.haskellPackages.acme-missiles ]; } ''
# import Acme.Missiles
#
# main = launchMissiles
# '';
writeHaskell = name: {
libraries ? [],
ghc ? pkgs.ghc
}:
makeBinWriter {
compileScript = ''
cp $contentPath tmp.hs
${ghc.withPackages (_: libraries )}/bin/ghc tmp.hs
mv tmp $out
'';
} name;
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.)