-
-
Save patrl/0fa53b81d2ee42508556a1244ceb5eae 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 | |
type git >/dev/null 2>&1 || { echo >&2 "I require git but it's not installed. Aborting."; exit 1; } | |
type nix >/dev/null 2>&1 || { echo >&2 "I require nix but it's not installed. Aborting."; exit 1; } | |
type niv >/dev/null 2>&1 || { echo >&2 "I require niv but it's not installed. Aborting."; exit 1; } | |
type direnv >/dev/null 2>&1 || { echo >&2 "I require direnv but it's not installed. Aborting."; exit 1; } | |
type lorri >/dev/null 2>&1 || { echo >&2 "I require lorri but it's not installed. Aborting."; exit 1; } | |
git init # initialize git repository | |
git ignore haskell > .gitignore # create gitignore file from haskell template | |
echo '*.cabal' >> .gitignore # cabal file doesn't need to be committed | |
export GITHUB_TOKEN=${gpg2 -q --for-your-eyes-only --no-tty -d $PASSWORD_STORE_DIR/services/github-token.gpg} | |
niv init # initialize niv | |
niv drop nixpkgs # we're going to be pinning nixpkgs anyway | |
niv add -n ghcide-nix cachix/ghcide-nix | |
niv add -n iohk-nixpkgs input-output-hk/nixpkgs | |
niv add -n iohk-hnix input-output-hk/haskell.nix | |
export author="Patrick D. Elliott" | |
export email="patrick.d.elliott@gmail.com" | |
export ghc="ghc883" | |
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 | |
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 | |
haskellCompiler = "${ghc}"; | |
sources = import ./nix/sources.nix; | |
ghcide = (import sources.ghcide-nix {})."ghcide-\${haskellCompiler}"; | |
haskellNix = import sources.iohk-hnix {}; | |
nixpkgsSrc = haskellNix.sources.nixpkgs-2003; | |
nixpkgsArgs = haskellNix.nixpkgsArgs; | |
pkgs = import nixpkgsSrc nixpkgsArgs; | |
hspkgs = pkgs.haskell-nix.cabalProject { | |
src = pkgs.haskell-nix.haskellLib.cleanGit { name = "${projectname}"; src = ./.; }; | |
compiler-nix-name = "\${haskellCompiler}"; | |
}; | |
shell = hspkgs.shellFor { | |
withHoogle = true; | |
buildInputs = [ | |
pkgs.cabal-install | |
pkgs.haskellPackages.ghcid | |
pkgs.haskellPackages.hpack | |
pkgs.haskellPackages.brittany | |
ghcide | |
]; | |
}; | |
in | |
{ | |
inherit shell; | |
inherit hspkgs; | |
${projectname} = hspkgs.${projectname}; | |
} | |
EOF | |
cat << EOF > ./shell.nix | |
(import ./default.nix).shell | |
EOF | |
# Create direnv file | |
cat << 'EOF' > .envrc | |
eval "\$(lorri direnv)" | |
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: | |
- ghcide-nix | |
- iohk | |
EOF | |
git add . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment