nix-shell -p
~/.bashrc:
function haskell-shell() {
nix-shell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [$@])"
}
Example:
$ haskell-shell random
[nix-shell]$ ghci
Prelude> System.Random.randomRIO (1, 100)
42
Main.hs:
import System.Console.ANSI
= do
main SetConsoleIntensity NormalIntensity
setSGR [ SetColor Foreground Vivid White
, SetColor Background Dull Blue
,
]putStr "Hello,"
Reset]
setSGR [putStrLn " world!"
default.nix:
{ pkgs ? import <nixpkgs> {} }:
let ghcPackages = pkgs: with pkgs; [ ansi-terminal ];
ghc = pkgs.haskellPackages.ghcWithPackages ghcPackages;
in pkgs.stdenv.mkDerivation {
name = "hello";
src = ./.;
buildInputs = [ ghc ];
buildPhase = ''
ghc -O2 Main.hs
'';
doCheck = true;
checkPhase = ''
diff <(printf '\033[97;44mHello,\033[0m world!\n') <(./Main)
'';
installPhase = ''
mkdir -pv $out/bin
cp Main $out/bin/hello
'';
}
$ nix-shell
[nix-shell]$ runhaskell Main.hs
Hello, world!
$ nix-build
$ ./result/bin/example
Hello, world!