mkdir app ; git mv app{_slash_,/}Main.hs
nix-build
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).
| /dist/ | |
| /dist-*/ | |
| /result | |
| /result-* | |
| cabal.project.local | |
| Setup |
| 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 |