Skip to content

Instantly share code, notes, and snippets.

@ScottFreeCode
Last active July 25, 2023 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ScottFreeCode/87bec0c569598014053579990a5bef6e to your computer and use it in GitHub Desktop.
Save ScottFreeCode/87bec0c569598014053579990a5bef6e to your computer and use it in GitHub Desktop.
Haskell+Nix, One Package
/dist/
/dist-*/
/result
/result-*
cabal.project.local
Setup

Fixup (work around gist limitations)

mkdir app ; git mv app{_slash_,/}Main.hs

Commands

Clean full build

nix-build

Dev mode

nix-shell

Then you can build with cabal v1-build or cabal build with or without --nix=True (or $HOME/.cabal/config containing nix: True).

module Main where
main = putStrLn "Hello, World!"
{ pkgs ? import <nixpkgs> {} }:
let
src = builtins.fetchGit {
url = ./.;
};
in pkgs.haskellPackages.callCabal2nix "" src {}
cabal-version: 3.0
name: example
version: 0.1.0.0
build-type: Simple
-- This could be split up into lib or src folder and app folder,
-- a library with most of the code and an executable that exposes it as a CLI,
-- as many projects prefer. Here, it has been kept simplistic/minimal.
executable example
main-is: Main.hs
build-depends:
base
hs-source-dirs: app
default-language: Haskell2010
{ pkgs ? import <nixpkgs> {} }:
(pkgs.haskell.lib.addBuildTool
(import ./. { inherit pkgs; })
pkgs.cabal-install
).env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment