Skip to content

Commit

Permalink
Add flake template & test in Github Actions (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
srid authored Jan 11, 2023
1 parent 54334cf commit 6a56fbd
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 29 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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
37 changes: 8 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions example/example.cabal
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions example/flake.nix
Original file line number Diff line number Diff line change
@@ -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;
};
};
}
4 changes: 4 additions & 0 deletions example/src/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = putStrLn "Hello, Haskell!"
4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
}

0 comments on commit 6a56fbd

Please sign in to comment.