Last active
May 20, 2021 15:24
-
-
Save masaeedu/ae22af4d4640d48705a7803d27906225 to your computer and use it in GitHub Desktop.
Basic nix haskell setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -Eeuxo pipefail | |
# Set up git | |
git init | |
gitignore haskell | |
echo '*.cabal' >> .gitignore | |
# Set up niv | |
niv init | |
niv add hercules-ci/ghcide-nix | |
niv add -n iohk-nixpkgs input-output-hk/nixpkgs -b a8f81dc037a5977414a356dd068f2621b3c89b60 | |
niv add -n iohk-hnix input-output-hk/haskell.nix -b master | |
export author="Asad Saeeduddin" | |
export email="[email protected]" | |
export ghc="ghc865" | |
export projectname=${PWD##*/} | |
# Create hpack project | |
cat <<EOF > ./package.yaml | |
spec-version: 0.30.0 | |
name: $projectname | |
author: ${author} | |
maintainer: ${email} | |
license: MIT | |
build-type: Simple | |
source-dirs: src | |
dependencies: | |
- { name: "base", version: '>=4.12 && <4.13' } | |
ghc-options: -Wall | |
default-extensions: | |
- GADTs | |
- StandaloneDeriving | |
- ScopedTypeVariables | |
- RankNTypes | |
- QuantifiedConstraints | |
- TypeApplications | |
- TypeOperators | |
- MultiParamTypeClasses | |
- ConstraintKinds | |
- DataKinds | |
- PolyKinds | |
- KindSignatures | |
- FlexibleInstances | |
- FlexibleContexts | |
library: {} | |
executable: | |
main: Main.hs | |
EOF | |
mkdir src | |
cat <<EOF > ./src/Main.hs | |
module Main where | |
main :: IO () | |
main = putStrLn "Hello, Haskell!" | |
EOF | |
cat <<EOF > ./hie.yaml | |
cradle: { cabal: {} } | |
EOF | |
# Add default.nix | |
cat <<EOF > ./default.nix | |
let | |
sources = import ./nix/sources.nix; | |
compilerVersion = "${ghc}"; | |
pkgs = (import sources.iohk-nixpkgs) (import sources.iohk-hnix); | |
in | |
pkgs.haskell-nix.cabalProject { | |
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; }; | |
ghc = pkgs.buildPackages.pkgs.haskell-nix.compiler.\${compilerVersion}; | |
} | |
EOF | |
cat << EOF > ./shell.nix | |
let | |
sources = import ./nix/sources.nix; | |
compilerVersion = "${ghc}"; | |
ghcide = (import sources.ghcide-nix {})."ghcide-\${compilerVersion}"; | |
pkgs = import sources.iohk-nixpkgs {}; | |
hspkgs = import ./default.nix; | |
in | |
hspkgs.shellFor { | |
withHoogle = true; | |
buildInputs = [ ghcide pkgs.haskellPackages.ghcid ]; | |
} | |
EOF | |
# Create direnv file | |
# TODO: Remove the grep stuff once https://github.com/hercules-ci/ghcide-nix/issues/26 is resolved | |
cat << 'EOF' > .envrc | |
use nix | |
source <(grep 'export NIX_' $(which ghc)) | |
EOF | |
cat << 'EOF' > CACHES.md | |
This project uses various nix expressions for building code. In order to avoid building a huge amount of stuff at once, you might want to enable the following [cachix](https://cachix.org/) caches: | |
- nix-tools | |
- hercules-ci | |
EOF | |
git add . | |
direnv allow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has since been superseded by: https://github.com/masaeedu/init-haskell/