Giter Club home page Giter Club logo

haskell-template's Introduction

haskell-template

Get a Haskell development environment up and running quickly. Thanks to Nix, this template is optimized for a fully reproducible and friendly development environment. It is based on:

If you have an existing Haskell project, you should probably use https://github.com/srid/haskell-flake instead.

Getting Started

tldr: Install Nix, setup direnv, open in VSCode, install recommended extensions and run just run.

Full instructions: https://srid.ca/haskell-template/start

Recommended dev environment setup: https://nixos.asia/en/direnv

Tips

  • Run nix flake update to update all flake inputs.
  • Run nix run github:srid/nixci build to build all outputs.
  • Run just fmt in nix shell to autoformat the project. This uses treefmt.
  • Run just docs to start Hoogle with packages in your cabal file.
  • Run the application without installing: nix run github:srid/haskell-template (or nix run . from checkout)
  • Common workflows

Discussions

Questions? Ideas? Suggestions? Join our NixOS Zulip or post in Github Discussions.

haskell-template's People

Contributors

ashwinmathi avatar evanpiro avatar github-actions[bot] avatar hariamoor-professional avatar jedimahdi avatar nixypanda avatar paretooptimaldev avatar programmerino avatar srid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

haskell-template's Issues

adding new package to haskell-template.cabal doesn't make direnv reload

Excuse the direct notes export, I hope it's still clean/understandable enough:

Okay it doesn't work cloning at dfad1869ef4f496ece09a323b25ed8cb07f4f52a and then

direnv allow and let things build

ghc-pkg list | grep relude

$ ghc-pkg list | grep relude
(standard input):    relude-1.1.0.0

adding cborg to cabal

modified   haskell-template.cabal
@@ -86,6 +86,7 @@ common shared
     , relude        >=1.0
     , shower
     , time
+    , cborg
     , with-utf8

   hs-source-dirs:     src

No downloads/rebuilds like I've noticed in the past after adding a dependency

ghc-pkg list | grep cborg, it's not there

$ ghc-pkg list | grep cborg

nix develop -c ghc-pkg list | grep cborg starts rebuilding and then shows it though

$ nix develop -c ghc-pkg list | grep cborg
trace: WARNING[haskell-flake]: Multiple haskell overlays are applied in arbitrary order.
building '/nix/store/x42h26avjqvs0sain2yvbji1biyx9z15-cabal2nix-haskell-template.drv'...
copying path '/nix/store/wqflpy76gl29f57g7znljn91ql9m7f6n-half-0.3.1-doc' from 'https://cache.nixos.org'...
copying path '/nix/store/mwk6kr92f2mgf6q2jl3yqh8k7cz68wvr-cborg-0.2.8.0-doc' from 'https://cache.nixos.org'...
copying path '/nix/store/5k1cmqka552byr7wfk1ps4hrmwf25sbz-half-0.3.1' from 'https://cache.nixos.org'...
copying path '/nix/store/4mp9l9y1nxfm7vmjbwq3v52kyf5ns5jx-cborg-0.2.8.0' from 'https://cache.nixos.org'...
building '/nix/store/1gkbglrjymksa1alj0ggp485d1ifqn1g-hoogle-with-packages.drv'...
building '/nix/store/g89g2qkd1djg3qyq22w4aapp5clgvhwn-ghc-9.2.4-with-packages.drv'...
building '/nix/store/h7arqgyzjsp8c2zsgb2kizspb26rvj97-ghc-shell-for-haskell-template-0.1.0.0-0-env.drv'...
(standard input):    cborg-0.2.8.0

nixpkgs is at 5efc8ca954272c4376ac929f4c5ffefcc20551d5

My configuration for nix-direnv is

programs.direnv = {
  enable = true;
  nix-direnv.enable = true;
  enableZshIntegration = true;
};

I can reproduce the issue both from vterm in emacs and eshell using envrc-mode

Add Githook for Code Formatting

Putting auto-formatting on a per commit basis would save the developer time resolving formatting issues due to failing CI.

Getting something like the following in a githook would suffice:
nix develop -c "treefmt"

Modules not being parsed in HLS

Commit 27aacd1 seem to have caused issues when modules/source files are added inside of src. For example, when I add src/Lib/Lib.hs, HLS cannot parse the file and I get this error:

Failed to run ["cabal","v2-repl","/home/bill/Projects/test/src/Lib/Lib.hs"] in directory "/home/bill/Projects/sari". Consult the logs for full command and error.
Failed command: cabal --builddir=/home/bill/.cache/hie-bios/dist-test-46b5963281c285ba43873006efe139c6 v2-repl --with-compiler /home/bill/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /home/bill/.cache/hie-bios/ghc-pkg-1267337f2438d8be4f64a47aa79ad3bf /home/bill/Projects/test/src/Lib/Lib.hs
Error: cabal: Failed extracting script block: `{- cabal:` start marker not
found
Process Environment:
HIE_BIOS_GHC: /nix/store/4wjl91hrizxghwqy18a1337gq2y9mh40-ghc-9.2.7/lib/ghc-9.2.7/bin/ghc
HIE_BIOS_GHC_ARGS: -B/nix/store/73mpvqn6z1sh3y1mx9g716wmfv1qmfqv-ghc-9.2.7-with-packages/lib/ghc-9.2.7
cradle

To get rid of this error, I had to manually add back the component and path parameters in hie.yaml:

cradle:
  cabal:
    - component: exe:test
      path: src

Test `haskell-language-server` in CI

Regressions like #37 should have been prevented in CI checks.

Add check (nix flake check) to test HLS functionality. The equivalent of running nix develop -c haskell-language-server.

Haskell Template Discord

I have some questions about how to do specific things with the haskell template that might be helpful for others to see and to encourage them to share any question they might have.

Add documentation directory

  1. Add a directory ./docs where application/library specific documentation will be stored.
    • In the template repo itself, this directory can store documentation for haskell-template and "recipes" like #33 (the user can replace them with their own docs)
  2. Provide .#docs-live that runs Emanote live server and .#docs that builds the statically generated site; like https://github.com/srid/emanote-template
  3. Move the bulk of README.md to ./docs; and link to the latter from the former.

(Example: https://github.com/EmaApps/ema has ./docs)

Getting flake error: devshell attributes not provided

I'm getting:

error: flake 'git+file:///home/<user>/vault/dev/Current/haskell-template' does not provide attribute 'devShells.x86_64-linux.devShell.x86_64-linux', 'packages.x86_64-linux.devShell.x86_64-linux', 'legacyPackages.x86_64-linux.devShell.x86_64-linux', 'devShell.x86_64-linux' or 'defaultPackage.x86_64-linux

I just updated from nix 2.4 to 2.7 so I made sure to run nix develop:

$ nix develop
error: flake 'git+file:///home/narice/vault/dev/Current/haskell-template' does not provide attribute 'devShells.x86_64-linux.devShell.x86_64-linux', 'packages.x86_64-linux.devShell.x86_64-linux', 'legacyPackages.x86_64-linux.devShell.x86_64-linux', 'devShell.x86_64-linux' or 'defaultPackage.x86_64-linux
$ nix --version
nix (Nix) 2.7.0pre20220127_558c4ee

Maybe there was a change in the flake structure recently?

Unable to use HLS with VSCode on Mac os

OS - MAC OS Monterey (M1)
Nix - nix (Nix) 2.9.1

steps to reproduce:
1- clone repo
2- run: nix develop -c haskell-language-server
OUTPUT :
Completed (1 file worked, 0 files failed)

Got an HLS error on VS Code
image

Document philosophy

What is the philosophy under which this template must exist / evolve in future?


We could say that the following are made available by default because they are useful in any repo:

  • relude
  • hls
  • hlint
  • autoformatting (treefmt)
  • etc..

But we can also refrain from adding stuff that are considered generally important, but not critical for every repo:

Some things have to exist because the template repo itself uses it, but is not generally necessary for non-srid users

  • garnix.yml

Error overriding library

I tried to follow the instructions for overriding library versions here: https://srid.ca/haskell-template/dependency

However, I am getting the following error:

error: attribute 'callCabal2Nix' missing

       at /nix/store/pf28nmzgqjy7sarx5rlhay83jharcrm0-source/flake.nix:30:34:

           29|           overrides = self: super: with pkgs.haskell.lib; {
           30|             ihp-hsx = dontCheck (self.callCabal2Nix "ihp-hsx" inputs.ihp-hsx {});
             |                                  ^
           31|           };
       Did you mean callCabal2nix?
(use '--show-trace' to show detailed location information)

cannot work with ghc 8.10

Hi. I use your template https://github.com/srid/haskell-multi-nix and get an error

Here is my flake.nix

{
    inputs = {
        nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
        flake-parts.url = "github:hercules-ci/flake-parts";
        haskell-flake.url = "github:srid/haskell-flake";
        systems.url = "github:nix-systems/default";
        flake-root.url = "github:srid/flake-root";
        mission-control.url = "github:Platonic-Systems/mission-control";
    };

    outputs = inputs:
        inputs.flake-parts.lib.mkFlake { inherit inputs; } {
            systems = import inputs.systems;
            imports = [
                inputs.haskell-flake.flakeModule
                inputs.flake-root.flakeModule
                inputs.mission-control.flakeModule
            ];
            perSystem = { self', inputs', system, lib, config, pkgs, ... }: {

                haskellProjects.hello1 = {
                    basePackages = pkgs.haskell.packages.ghc8107;
                };
                haskellProjects.hello2 = {
                };

                devShells.default = pkgs.mkShell {
                    inputsFrom = [
                        config.flake-root.devShell
                        config.mission-control.devShell
                    ];
                };
            };
        };
}

If I run nix develop .#hello2, the shell is built OK and the ghc version is 9.2.7. But if I run nix develop .#hello1, it runs very long and eventually I get the following error

error: builder for '/nix/store/fw26751xhsn8x6891pa6rl6fqd6kal8r-pretty-simple-4.1.2.0.drv' failed with exit code 1;
       last 10 log lines:
       > running tests
       > Running 1 test suites...
       > Test suite pretty-simple-doctest: RUNNING...
       > ghc: mmap 4096 bytes at (nil): Cannot allocate memory
       > ghc: Try specifying an address with +RTS -xm<addr> -RTS
       > pretty-simple-doctest: fd:15: hGetLine: end of file
       > Test suite pretty-simple-doctest: FAIL
       > Test suite logged to:
       > dist/test/pretty-simple-4.1.2.0-pretty-simple-doctest.log
       > 0 of 1 test suites (0 of 1 test cases) passed.
       For full logs, run 'nix-store -l /nix/store/fw26751xhsn8x6891pa6rl6fqd6kal8r-pretty-simple-4.1.2.0.drv'.
error: 1 dependencies of derivation '/nix/store/cjyx9cagbh0cr9asldwynsbh7nclak7l-hls-eval-plugin-1.5.0.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/7c83fg5fl4r375zy5qj4l9knrk2qbs4c-haskell-language-server-1.10.0.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/j6sc290qhdrwyvwpifgz2z3p1dybf43v-ghc-shell-for-packages-0-env.drv' failed to build

How can I fix that? Thanks.

Nixify `fourmolu.yaml`

Similar to how we got rid of ./treefmt.toml in #75 - get rid of fourmolu.yaml by nixifying that configuration.

M1 Mac support

Make nix build (and bin/run) succeed on M1 Mac with native Nix installed.

No rosetta.

error: flake haskell-template does not provide attribute 'devShells.x86_64-linux.devShell.x86_64-linux' ...

Hi,

I'm getting this error when trying to enter nix develop or run the sanity check per instructions:

$ nixos-version
21.11.337526.8b3398bc758 (Porcupine)

$ git clone https://github.com/srid/haskell-template
Cloning into 'haskell-template'...
remote: Enumerating objects: 566, done.
remote: Counting objects: 100% (181/181), done.
remote: Compressing objects: 100% (45/45), done.
remote: Total 566 (delta 147), reused 142 (delta 136), pack-reused 385
Receiving objects: 100% (566/566), 120.24 KiB | 578.00 KiB/s, done.
Resolving deltas: 100% (322/322), done.

$ cd haskell-template/

$ nix develop -i -c haskell-language-server
error: flake 'git+file:///tmp/haskell-template' does not provide attribute 'devShells.x86_64-linux.devShell.x86_64-linux', 'packages.x86_64-linux.devShell.x86_64-linux', 'legacyPackages.x86_64-linux.devShell.x86_64-linux', 'devShell.x86_64-linux' or 'defaultPackage.x86_64-linux'

$ nix develop
error: flake 'git+file:///tmp/haskell-template' does not provide attribute 'devShells.x86_64-linux.devShell.x86_64-linux', 'packages.x86_64-linux.devShell.x86_64-linux', 'legacyPackages.x86_64-linux.devShell.x86_64-linux', 'devShell.x86_64-linux' or 'defaultPackage.x86_64-linux'

$ nix run .
error: cannot find flake attribute 'git+file:///tmp/haskell-template#defaultApp.x86_64-linux'

Integration with HSL does not work

Hi! I just started a project with the template and used Nix Env Selector and VSCode + HLS and it is not able to detect the GHC version etc ๐Ÿ˜ข

Sanity Check Fails

I'm not sure what debugging I can provide you with, but I'm running nix (Nix) 2.10.3 and did the following:

  1. git clone https://github.com/srid/haskell-template
  2. nix develop -i -c haskell-language-server

That got to step 4 and produced the following error:

$ nix develop -i -c haskell-language-server
2022-08-18T14:01:38.093670Z | Info | No log file specified; using stderr.
2022-08-18T14:01:38.093966Z | Info | haskell-language-server version: 1.7.0.0 (GHC: 9.0.2) (PATH: /nix/store/9r70hgwq3fx1pnxr1gjygrww3jkxppw5-haskell-language-server-1.7.0.0/bin/haskell-language-server)
2022-08-18T14:01:38.094979Z | Info | Directory: /private/tmp/haskell-template
2022-08-18T14:01:38.095214Z | Info | Logging heap statistics every 60.00s
 ghcide setup tester in /private/tmp/haskell-template.
Report bugs at https://github.com/haskell/haskell-language-server/issues

Step 1/4: Finding files to test in /private/tmp/haskell-template
Found 3 files

Step 2/4: Looking for hie.yaml files that control setup
Found 1 cradle
  ()

Step 3/4: Initializing the IDE

Step 4/4: Type checking the files
2022-08-18T14:01:38.129318Z | Info | Cradle path: src/Lib.hs
2022-08-18T14:01:38.129389Z | Warning | No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for src/Lib.hs.
Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
2022-08-18T14:01:38.133733Z | Info | Cradle path: tests/Spec.hs
2022-08-18T14:01:38.133798Z | Warning | No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for tests/Spec.hs.
Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
2022-08-18T14:01:38.145244Z | Info | updateFileDiagnostics published different from new diagnostics - file diagnostics: File:     /private/tmp/haskell-template/src/Lib.hs
Hidden:   no
Range:    1:1-2:1
Source:   cradle
Severity: DsError
Message:
  Multi Cradle: No prefixes matched
  pwd: /private/tmp/haskell-template
  filepath: /private/tmp/haskell-template/src/Lib.hs
  prefixes:
  ("./Main.hs",Cabal {component = Just "haskell-template:exe:haskell-template"})
  ("tests",Cabal {component = Just "haskell-template:test:tests"})
2022-08-18 07:01:40.728715 [ThreadId 50] INFO hie-bios: Resolving dependencies...
2022-08-18 07:01:40.992997 [ThreadId 50] INFO hie-bios: Build profile: -w ghc-9.0.2 -O1
2022-08-18 07:01:40.993078 [ThreadId 50] INFO hie-bios: In order, the following will be built (use -v for more details):
2022-08-18 07:01:40.993103 [ThreadId 50] INFO hie-bios:  - haskell-template-0.1.0.0 (test:tests) (first run)
2022-08-18 07:01:41.059092 [ThreadId 50] INFO hie-bios: Configuring test suite 'tests' for haskell-template-0.1.0.0..
2022-08-18 07:01:41.605033 [ThreadId 48] INFO hie-bios: Warning: Packages using 'cabal-version: >= 1.10' and before 'cabal-version:
2022-08-18 07:01:41.605106 [ThreadId 48] INFO hie-bios: 3.4' must specify the 'default-language' field for each component (e.g.
2022-08-18 07:01:41.605148 [ThreadId 48] INFO hie-bios: Haskell98 or Haskell2010). If a component uses different languages in
2022-08-18 07:01:41.605183 [ThreadId 48] INFO hie-bios: different modules then list the other ones in the 'other-languages' field.
2022-08-18 07:01:42.568375 [ThreadId 50] INFO hie-bios: Preprocessing test suite 'tests' for haskell-template-0.1.0.0..
2022-08-18T14:01:43.151612Z | Info | Interface files cache directory: /Users/devin.fee/.cache/ghcide/main-a0fdafc114593191f79773368a636c11d0431c0e
2022-08-18T14:01:43.152187Z | Info | Making new HscEnv. In-place unit ids: [main]
2022-08-18T14:01:43.284161Z | Info | Cradle path: src/Main.hs
2022-08-18T14:01:43.284233Z | Warning | No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for src/Main.hs.
Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie).
You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error.
2022-08-18T14:01:43.289071Z | Info | updateFileDiagnostics published different from new diagnostics - file diagnostics: File:     /private/tmp/haskell-template/src/Main.hs
Hidden:   no
Range:    1:1-2:1
Source:   cradle
Severity: DsError
Message:
  Multi Cradle: No prefixes matched
  pwd: /private/tmp/haskell-template
  filepath: /private/tmp/haskell-template/src/Main.hs
  prefixes:
  ("./Main.hs",Cabal {component = Just "haskell-template:exe:haskell-template"})
  ("tests",Cabal {component = Just "haskell-template:test:tests"})
Files that failed:
 * /private/tmp/haskell-template/src/Main.hs

Completed (2 files worked, 1 file failed)

Add a Nix template

I changed my mind about #98

But we should do it a limited manner. In particular nix flake init should only bring the following files:

  • flake.nix
  • fourmolu.yaml
  • hie.yaml
  • justfile
  • Jenkinsfile
  • .hlint.yaml
  • .envrc

Basically help automate modernization work like srid/commonmark-simple@4339af1

Remove tests; but document how to add them

I personally don't use tests for most of the repos created off this template. I find myself having to delete the tests.

For pedagogic reasons also, we want a self-sufficient Main.hs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.