diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..8dad6c38 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,27 @@ +name: "CI" +on: + push: + branches: + - '*' + pull_request: +jobs: + checks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: cachix/install-nix-action@v18 + with: + extra_nix_config: | + experimental-features = nix-command flakes + access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} + - name: Test template + id: template + run: | + FLAKE=$(pwd) + TEMP_DIR=$(mktemp -d) + cd $TEMP_DIR + nix flake init -t $FLAKE + # Build haskell executable + nix build --override-input haskell-flake path:${FLAKE} + # Test haskell devshell (via HLS check) + nix develop --override-input haskell-flake path:${FLAKE} -c haskell-language-server diff --git a/README.md b/README.md index 4a8a1b5f..7cfcba78 100644 --- a/README.md +++ b/README.md @@ -8,37 +8,16 @@ To keep `flake.nix` smaller (see examples below) and declarative ([what](https:/ ## Usage -To use `haskell-flake` in your Haskell projects, create a `flake.nix` containing the following: - -```nix -{ - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; - flake-parts.url = "github:hercules-ci/flake-parts"; - haskell-flake.url = "github:srid/haskell-flake"; - }; - outputs = inputs@{ self, nixpkgs, flake-parts, ... }: - flake-parts.lib.mkFlake { inherit self; } { - systems = nixpkgs.lib.systems.flakeExposed; - imports = [ inputs.haskell-flake.flakeModule ]; - perSystem = { self', pkgs, ... }: { - haskellProjects.default = { - packages = { - # You can add more than one local package here. - my-package.root = ./.; # Assumes ./my-package.cabal - }; - # buildTools = hp: { fourmolu = hp.fourmolu; ghcid = null; }; - # overrides = self: super: { }; - # hlintCheck.enable = true; - # hlsCheck.enable = true; - }; - # haskell-flake doesn't set the default package, but you can do it here. - packages.default = self'.packages.my-package; - }; - }; -} +To use `haskell-flake` in your Haskell projects, run: + +``` nix +nix flake init -t github:srid/haskell-flake ``` +This will generate a template Haskell project with a `flake.nix`. If you already have a Haskell project, copy over this `flake.nix` and adjust accordingly. + +## Documentation + Check out the [list of options](https://flake.parts/options/haskell-flake.html). `haskell-flake` uses `callCabal2nix` and `shellFor` [under the hood](https://github.com/srid/haskell-multi-nix/blob/master/flake.nix). ## Template diff --git a/example/example.cabal b/example/example.cabal new file mode 100644 index 00000000..bfe6aa4a --- /dev/null +++ b/example/example.cabal @@ -0,0 +1,17 @@ +cabal-version: 3.0 +name: example +version: 0.1.0.0 +license: NONE +author: Joe +maintainer: joe@example.com +build-type: Simple + +common warnings + ghc-options: -Wall + +executable example + import: warnings + main-is: Main.hs + build-depends: base + hs-source-dirs: src + default-language: Haskell2010 diff --git a/example/flake.nix b/example/flake.nix new file mode 100644 index 00000000..352c76c5 --- /dev/null +++ b/example/flake.nix @@ -0,0 +1,26 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + haskell-flake.url = "github:srid/haskell-flake"; + }; + outputs = inputs@{ self, nixpkgs, flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = nixpkgs.lib.systems.flakeExposed; + imports = [ inputs.haskell-flake.flakeModule ]; + perSystem = { self', pkgs, ... }: { + haskellProjects.default = { + packages = { + # You can add more than one local package here. + example.root = ./.; # Assumes ./example.cabal + }; + # buildTools = hp: { fourmolu = hp.fourmolu; ghcid = null; }; + # overrides = self: super: { }; + # hlintCheck.enable = true; + # hlsCheck.enable = true; + }; + # haskell-flake doesn't set the default package, but you can do it here. + packages.default = self'.packages.example; + }; + }; +} diff --git a/example/src/Main.hs b/example/src/Main.hs new file mode 100644 index 00000000..65ae4a05 --- /dev/null +++ b/example/src/Main.hs @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = putStrLn "Hello, Haskell!" diff --git a/flake.nix b/flake.nix index 52d0c10b..c4bc81c7 100644 --- a/flake.nix +++ b/flake.nix @@ -2,5 +2,9 @@ description = "A `flake-parts` module for Haskell development"; outputs = { self, ... }: { flakeModule = ./flake-module.nix; + templates.default = { + description = "Example project using haskell-flake"; + path = ./example; + }; }; }