From 64c2f3fd0efcd2200b387ca86127428215af7a26 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Fri, 11 Mar 2022 08:44:02 -0500 Subject: [PATCH] Initial commit --- .envrc | 1 + .githooks/pre-commit | 13 +++++++ .gitignore | 35 +++++++++++++++++++ README.md | 10 ++++++ app/Main.hs | 4 +++ flake.lock | 43 ++++++++++++++++++++++++ flake.nix | 50 +++++++++++++++++++++++++++ hello-world.cabal | 80 ++++++++++++++++++++++++++++++++++++++++++++ hie.yaml | 2 ++ 9 files changed, 238 insertions(+) create mode 100644 .envrc create mode 100644 .githooks/pre-commit create mode 100644 .gitignore create mode 100644 README.md create mode 100644 app/Main.hs create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 hello-world.cabal create mode 100644 hie.yaml diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100644 index 0000000..6dda1fe --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -e + +filesToFormat=$( + git --no-pager diff --name-status --no-color --cached | \ + awk '$1 != "D" && $2 ~ /\.hs/ {print $NF}' +) + +for path in $filesToFormat +do + google-java-format --replace $path + git add $path +done; diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d4bfdbc --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# direnv +*.sw? +.direnv +.gopath +/direnv +/direnv.test +/dist +/test/config +/test/data +/test/scenarios/inherited/.envrc + +# haskell +dist +dist-* +cabal-dev +*.o +*.hi +*.hie +*.chi +*.chs.h +*.dyn_o +*.dyn_hi +.hpc +.hsenv +.cabal-sandbox/ +cabal.sandbox.config +*.prof +*.aux +*.hp +*.eventlog +.stack-work/ +cabal.project.local +cabal.project.local~ +.HTF/ +.ghc.environment.* diff --git a/README.md b/README.md new file mode 100644 index 0000000..e924d0c --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# hello-world + +## Formatting + +A `pre-commit` file is included in `.githooks` to ensure consistent formatting. +Run the following to configure `git` to using it: + +```bash +git config --local core.hooksPath .githooks/ +``` diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..98f25e4 --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = putStrLn "Hello, World!" diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..b8cfd0d --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1646011258, + "narHash": "sha256-+aen4zu5uVp52arEcgL2maCS0zQDuG1t+Azwd/O1gN4=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a25df4c2b79c4343bcc72ad671200e5a3e286c41", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-21.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..cf5afe7 --- /dev/null +++ b/flake.nix @@ -0,0 +1,50 @@ +{ + description = "A minimal Haskell flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-21.11"; + flake-utils = { + url = "github:numtide/flake-utils"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, flake-utils }: { + overlay = final: prev: { + hello-world = prev.haskellPackages.callCabal2nix "hello-world" self { }; + }; + } // (flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ self.overlay ]; + }; + + haskell = { + ghc = pkgs.haskellPackages.ghc; + hls = pkgs.haskell-language-server.override { + supportedGhcVersions = [ "8107" ]; + }; + }; + in + with pkgs; { + packages = { inherit hello-world; }; + + defaultPackage = self.packages.${system}.hello-world; + + devShell = mkShell { + buildInputs = lib.attrValues self.packages.${system} ++ [ + haskell.ghc + haskell.hls + gdb + # GHC depends on LANG so need this package to properly interpret our + # files with e.g. tasty-discover. + # https://www.reddit.com/r/Nix/comments/jyczts/nixshell_locale_issue/ + glibcLocales + haskellPackages.cabal-install + haskellPackages.ormolu + haskellPackages.tasty-discover + ]; + }; + })); +} diff --git a/hello-world.cabal b/hello-world.cabal new file mode 100644 index 0000000..6018d8f --- /dev/null +++ b/hello-world.cabal @@ -0,0 +1,80 @@ + cabal-version: 3.0 + name: hello-world + version: 0.1.0.0 + + synopsis: The Corner programming language. + -- A longer description of the package. + -- description: + + -- license: + author: + maintainer: @.com + bug-reports: https://github.com///issues + + -- A copyright notice. + -- copyright: + -- category: + extra-source-files: + CHANGELOG.md + README.md + +common hello-world-common + default-language: Haskell2010 + default-extensions: BangPatterns, + BinaryLiterals, + ConstrainedClassMethods, + ConstraintKinds, + DeriveDataTypeable, + DeriveFoldable, + DeriveFunctor, + DeriveGeneric, + DeriveLift, + DeriveTraversable, + DoAndIfThenElse, + EmptyCase, + EmptyDataDecls, + EmptyDataDeriving, + ExistentialQuantification, + ExplicitForAll, + -- Enabled by default, but not supported by ghc-8.10. + -- FieldSelectors, + FlexibleContexts, + FlexibleInstances, + ForeignFunctionInterface, + GADTSyntax, + GeneralisedNewtypeDeriving, + HexFloatLiterals, + ImplicitPrelude, + ImportQualifiedPost, + InstanceSigs, + KindSignatures, + MonomorphismRestriction, + MultiParamTypeClasses, + NamedFieldPuns, + NamedWildCards, + NumericUnderscores, + PatternGuards, + PolyKinds, + PostfixOperators, + RankNTypes, + RelaxedPolyRec, + ScopedTypeVariables, + StandaloneDeriving, + StandaloneKindSignatures, + StarIsType, + TraditionalRecordSyntax, + TupleSections, + TypeApplications, + TypeOperators, + TypeSynonymInstances + build-depends: base, + relude + mixins: base hiding (Prelude), + relude (Relude as Prelude), + relude + ghc-options: -Wall + +executable hello-world + import: hello-world-common + main-is: Main.hs + hs-source-dirs: app diff --git a/hie.yaml b/hie.yaml new file mode 100644 index 0000000..04cd243 --- /dev/null +++ b/hie.yaml @@ -0,0 +1,2 @@ +cradle: + cabal: