From 095554de31ed2ef55c3d294cdfd91f1301bc2fdb Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Tue, 21 Jan 2020 23:03:06 -0800 Subject: [PATCH] Build in Nix and use GH Actions instead of CircleCI (#38) --- .github/workflows/test.yml | 25 ++++++++++++++++++++++++ nix/ci/test.nix | 9 +++++++++ nix/default.nix | 9 +++++++++ nix/generic.nix | 39 ++++++++++++++++++++++++++++++++++++++ nix/sources.nix | 24 +++++++++++++++++++++++ shell.nix | 19 +++++++++++++++++++ 6 files changed, 125 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 nix/ci/test.nix create mode 100644 nix/default.nix create mode 100644 nix/generic.nix create mode 100644 nix/sources.nix create mode 100644 shell.nix diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..f938ec92 --- /dev/null +++ b/.github/workflows/test.yml @@ -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 }} + + diff --git a/nix/ci/test.nix b/nix/ci/test.nix new file mode 100644 index 00000000..33ad5160 --- /dev/null +++ b/nix/ci/test.nix @@ -0,0 +1,9 @@ +{ ocamlVersion }: + +let + sources = import ../sources.nix { inherit ocamlVersion; }; +in + import ./.. { + inherit sources ocamlVersion; + doCheck = true; + } diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 00000000..350ff3e6 --- /dev/null +++ b/nix/default.nix @@ -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; + } + diff --git a/nix/generic.nix b/nix/generic.nix new file mode 100644 index 00000000..516bbb3e --- /dev/null +++ b/nix/generic.nix @@ -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 + ]; + }; +} diff --git a/nix/sources.nix b/nix/sources.nix new file mode 100644 index 00000000..fbaac55a --- /dev/null +++ b/nix/sources.nix @@ -0,0 +1,24 @@ +# nix-build -E \ +# 'with import { overlays = [(import ./.)];}; pkgs.bs-platform' +{ pkgs ? import {}, 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; } diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000..87cda8be --- /dev/null +++ b/shell.nix @@ -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; + }) +