Skip to content

Commit

Permalink
Build in Nix and use GH Actions instead of CircleCI (inhabitedtype#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed May 11, 2020
1 parent 84abd81 commit 095554d
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "Build"
on:
pull_request:
push:
branches:
- master
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
ocamlVersion: [4_06, 4_07, 4_08, 4_09]
steps:
- uses: actions/checkout@v2
- uses: cachix/install-nix-action@v6
- uses: cachix/cachix-action@v3
with:
name: anmonteiro
skipNixBuild: true
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
- name: Build / Test
shell: bash
run: nix-build ./nix/ci/test.nix --argstr ocamlVersion ${{ matrix.ocamlVersion }}


9 changes: 9 additions & 0 deletions nix/ci/test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ ocamlVersion }:

let
sources = import ../sources.nix { inherit ocamlVersion; };
in
import ./.. {
inherit sources ocamlVersion;
doCheck = true;
}
9 changes: 9 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ sources ? import ./sources.nix { inherit ocamlVersion; }, ocamlVersion ? "4_09", doCheck ? true }:

let
inherit (sources) pkgs ocamlPackages gitignoreSource;
in
pkgs.callPackage ./generic.nix {
inherit ocamlPackages gitignoreSource doCheck;
}

39 changes: 39 additions & 0 deletions nix/generic.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{ lib, stdenv, ocamlPackages, gitignoreSource, doCheck }:

with ocamlPackages;

let
buildHttpaf = args: buildDunePackage ({
version = "0.6.5-dev";
doCheck = doCheck;
src = gitignoreSource ./..;
} // args);

# TODO: httpaf-async, httpaf-mirage
in rec {
httpaf = buildHttpaf {
pname = "httpaf";
buildInputs = [ alcotest hex yojson ];
propagatedBuildInputs = [
angstrom
faraday
];
};

# These two don't have tests
httpaf-lwt = buildHttpaf {
pname = "httpaf-lwt";
doCheck = false;
propagatedBuildInputs = [ httpaf lwt4 ];
};

httpaf-lwt-unix = buildHttpaf {
pname = "httpaf-lwt-unix";
doCheck = false;
propagatedBuildInputs = [
httpaf-lwt
faraday-lwt-unix
lwt_ssl
];
};
}
24 changes: 24 additions & 0 deletions nix/sources.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# nix-build -E \
# 'with import <nixpkgs> { overlays = [(import ./.)];}; pkgs.bs-platform'
{ pkgs ? import <nixpkgs> {}, ocamlVersion ? "4_09" }:

let
gitignoreSrc = pkgs.fetchFromGitHub {
owner = "hercules-ci";
repo = "gitignore";
rev = "7415c4f";
sha256 = "1zd1ylgkndbb5szji32ivfhwh04mr1sbgrnvbrqpmfb67g2g3r9i";
};

overlays = builtins.fetchTarball {
url = https://github.com/anmonteiro/nix-overlays/archive/5e4c96c3efd20048fc04f306956e3e0c5c04f544.tar.gz;
sha256 = "1jaa9i2b5a4x9ryjh7ckvsgikqv6aqbb2lnn6xxdh3nqjk4vhx4m";
};

inherit (import gitignoreSrc { inherit (pkgs) lib; }) gitignoreSource;

ocamlPackages = pkgs.ocaml-ng."ocamlPackages_${ocamlVersion}".overrideScope'
(pkgs.callPackage "${overlays}/ocaml" { });

in
{ inherit pkgs ocamlPackages gitignoreSource; }
19 changes: 19 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
let
sources = import ./nix/sources.nix {};
inherit (sources) pkgs ocamlPackages;
inherit (pkgs) stdenv lib;
httpafPkgs = pkgs.recurseIntoAttrs (import ./nix { inherit sources; doCheck = false; });
httpafDrvs = lib.filterAttrs (_: value: lib.isDerivation value) httpafPkgs;

in
with pkgs;

(mkShell {
inputsFrom = lib.attrValues httpafDrvs;
buildInputs = with ocamlPackages; [ merlin ];
}).overrideAttrs (o : {
propagatedBuildInputs = lib.filter
(drv: drv.pname == null || !(lib.any (name: name == drv.pname) (lib.attrNames httpafDrvs)))
o.propagatedBuildInputs;
})

0 comments on commit 095554d

Please sign in to comment.