Nix integration for stack
Original date 2020-02-25T00:00:00.000Z
You might want to build your Haskell application with #Nix even if you did start with #Stack.
#Stack has support for building with #Nix. You need to add nix.enable: true to your stack.yaml file.
nix:
enable: true
packages: [glpk, pcre]
You can build your app with Nix now. Also, you can specify a custom shell file for defining environment variables or anything else. You need to remove the packages parameter and to add the shell-file parameter to stack.yaml file.
nix:
enable: true
shell-file: shell.nix
After that, you can write your shell.nix file.
{ghc}:
with (import <nixpkgs> {});
haskell.lib.buildStackProject {
inherit ghc;
name = "ScottyEnv";
buildInputs = [pkgs.figlet zlib.dev zlib.out glpk pcre];
shellHook = ''
export PORT=3003;
figlet "LISTENING ON PORT "$PORT;
'';
}
And then, just run stack build or stack run or stack ghci commands.
I am a veteran Full-Stack Engineer, Open Source Contributor, and Web Generalist. Having shipped applications continuously since 2005, I don't just write code—I architect scalable digital systems that drive business value. Building Nostr tools: - https://nostr.emre.xyz - https://photo.emre.xyz - https://snips.emre.xyz - https://nostr.org.tr - https://rehber.dev - https://jotstr.com - https://ulasocial.com