Skip to content

Instantly share code, notes, and snippets.

@DeCentN2Madness
Forked from oneingan/init-haskell.sh
Created September 12, 2022 02:12
Show Gist options
  • Save DeCentN2Madness/20cc9a74af8abcc93112c2bcae9a2031 to your computer and use it in GitHub Desktop.
Save DeCentN2Madness/20cc9a74af8abcc93112c2bcae9a2031 to your computer and use it in GitHub Desktop.

Revisions

  1. @masaeedu masaeedu revised this gist Dec 22, 2019. 1 changed file with 96 additions and 22 deletions.
    118 changes: 96 additions & 22 deletions init-haskell.sh
    Original file line number Diff line number Diff line change
    @@ -1,44 +1,118 @@
    #!/usr/bin/env bash
    set -Eeuxo pipefail

    # Set up git
    git init
    gitignore haskell
    echo '*.cabal' >> .gitignore

    # Set up niv
    niv init
    niv update nixpkgs -b nixos-unstable
    niv add Infinisil/all-hies
    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

    # Create cabal project
    export currentdir=${PWD##*/}
    cabal init -n -m --is-libandexe --source-dir src --main-is Main.hs -p $currentdir
    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
    cat <<EOF > ./default.nix
    let
    compilerVersion = "ghc865";
    sources = import ./nix/sources.nix;
    pkgs = import sources.nixpkgs {};
    hie = (import sources.all-hies {}).versions."${compilerVersion}";
    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

    with pkgs;
    cat << EOF > ./shell.nix
    let
    hpkgs = haskell.packages."${compilerVersion}";
    btools = [
    hpkgs.cabal-install
    hpkgs.ghcid
    hpkgs.hoogle
    hpkgs.stylish-cabal
    hie
    ];
    modifier = drv: haskell.lib.addBuildTools drv btools;
    sources = import ./nix/sources.nix;
    compilerVersion = "${ghc}";
    ghcide = (import sources.ghcide-nix {})."ghcide-\${compilerVersion}";
    pkgs = import sources.iohk-nixpkgs {};
    hspkgs = import ./default.nix;
    in
    hpkgs.developPackage { root = ./.; inherit modifier; }
    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
  2. @masaeedu masaeedu revised this gist Aug 31, 2019. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions init-haskell.sh
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,28 @@
    #!/usr/bin/env bash
    set -euxo pipefail
    set -Eeuxo pipefail

    # Set up niv
    niv init
    niv update nixpkgs -b nixos-unstable
    niv add Infinisil/all-hies

    # Create cabal project
    cabal init -n
    export currentdir=${PWD##*/}
    cabal init -n -m --is-libandexe --source-dir src --main-is Main.hs -p $currentdir

    # Add default.nix
    cat << 'EOF' > ./default.nix
    let
    compilerVersion = "ghc865";
    sources = import ./nix/sources.nix;
    pkgs = import sources.nixpkgs {};
    hie = (import sources.all-hies {}).versions.ghc865;
    hie = (import sources.all-hies {}).versions."${compilerVersion}";
    in
    with pkgs;
    let
    hpkgs = haskellPackages;
    hpkgs = haskell.packages."${compilerVersion}";
    btools = [
    hpkgs.cabal-install
    hpkgs.ghcid
  3. @masaeedu masaeedu revised this gist Jul 17, 2019. 1 changed file with 0 additions and 21 deletions.
    21 changes: 0 additions & 21 deletions default.nix
    Original file line number Diff line number Diff line change
    @@ -1,21 +0,0 @@
    let
    sources = import ./nix/sources.nix;
    pkgs = import sources.nixpkgs {};
    hie = (import sources.all-hies {}).versions.ghc865;
    in

    with pkgs;

    let
    hpkgs = haskellPackages;
    btools = [
    hpkgs.cabal-install
    hpkgs.ghcid
    hpkgs.hoogle
    hpkgs.stylish-cabal
    hie
    ];
    modifier = drv: haskell.lib.addBuildTools drv btools;
    in

    hpkgs.developPackage { root = ./.; inherit modifier; }
  4. @masaeedu masaeedu revised this gist Jul 17, 2019. 3 changed files with 58 additions and 22 deletions.
    37 changes: 16 additions & 21 deletions default.nix
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,21 @@
    let
    sources = import ./nix/sources.nix;
    pkgs = import sources.nixpkgs {};
    hie = (import sources.all-hies {}).versions.ghc865;
    hpkgs = pkgs.haskellPackages;
    drv = hpkgs.callCabal2nix "questiongraph" ./. {};
    sources = import ./nix/sources.nix;
    pkgs = import sources.nixpkgs {};
    hie = (import sources.all-hies {}).versions.ghc865;
    in

    with pkgs;
    rec {
    rebase-tree = drv;

    shell =
    let pkg' =
    haskell.lib.addBuildTools
    rebase-tree
    [
    hpkgs.cabal-install
    hpkgs.ghcid
    hpkgs.hoogle
    hpkgs.stylish-cabal
    hie
    ];
    in
    pkg'.env;
    }
    let
    hpkgs = haskellPackages;
    btools = [
    hpkgs.cabal-install
    hpkgs.ghcid
    hpkgs.hoogle
    hpkgs.stylish-cabal
    hie
    ];
    modifier = drv: haskell.lib.addBuildTools drv btools;
    in

    hpkgs.developPackage { root = ./.; inherit modifier; }
    42 changes: 42 additions & 0 deletions init-haskell.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    #!/usr/bin/env bash
    set -euxo pipefail

    # Set up niv
    niv init
    niv update nixpkgs -b nixos-unstable
    niv add Infinisil/all-hies

    # Create cabal project
    cabal init -n

    # Add default.nix
    cat << 'EOF' > ./default.nix
    let
    sources = import ./nix/sources.nix;
    pkgs = import sources.nixpkgs {};
    hie = (import sources.all-hies {}).versions.ghc865;
    in
    with pkgs;
    let
    hpkgs = haskellPackages;
    btools = [
    hpkgs.cabal-install
    hpkgs.ghcid
    hpkgs.hoogle
    hpkgs.stylish-cabal
    hie
    ];
    modifier = drv: haskell.lib.addBuildTools drv btools;
    in
    hpkgs.developPackage { root = ./.; inherit modifier; }
    EOF

    # Create direnv file
    cat << 'EOF' > .envrc
    use nix
    EOF

    direnv allow
    1 change: 0 additions & 1 deletion shell.nix
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    (import ./.).shell
  5. @masaeedu masaeedu created this gist Jul 4, 2019.
    26 changes: 26 additions & 0 deletions default.nix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    let
    sources = import ./nix/sources.nix;
    pkgs = import sources.nixpkgs {};
    hie = (import sources.all-hies {}).versions.ghc865;
    hpkgs = pkgs.haskellPackages;
    drv = hpkgs.callCabal2nix "questiongraph" ./. {};
    in

    with pkgs;
    rec {
    rebase-tree = drv;

    shell =
    let pkg' =
    haskell.lib.addBuildTools
    rebase-tree
    [
    hpkgs.cabal-install
    hpkgs.ghcid
    hpkgs.hoogle
    hpkgs.stylish-cabal
    hie
    ];
    in
    pkg'.env;
    }
    1 change: 1 addition & 0 deletions shell.nix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    (import ./.).shell