Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add build / develop environment in Nix #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/test-in-nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: test in Nix

on:
- push
- pull_request

jobs:
tests-in-nix:
name: Tests in Nix
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
ocaml-version:
- 4_11
- 4_12
- 4_13

runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Nix
uses: cachix/install-nix-action@v15
with:
nix_path: nixpkgs=channel:nixos-21.11
extra_nix_config: |
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
substituters = https://cache.nixos.org/
max-jobs = auto
cores = 0

- name: Build
run: |
nix-shell --argstr ocamlVersion ${{ matrix.ocaml-version }} --run "dune build"

- name: Test
run: |
nix-shell --argstr ocamlVersion ${{ matrix.ocaml-version }} --run "dune runtest"

- name: Examples
run: |
nix-shell --argstr ocamlVersion ${{ matrix.ocaml-version }} --run "dune build @examples"
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build
name: test

on:
- push
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ lib_test/tests_
*.docdir
.merlin
*.install

/result*
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ opam pin add -n httpaf .
opam install --deps-only httpaf
```

If you use [Nix](https://nixos.org/), you can enter `nix-shell`, which contains dev dependencies including ocaml-lsp.

```bash
nix-shell shell.nix
```

After this, you may install a development version of the library using the
install command as usual.

Expand Down
10 changes: 10 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ pkgs ? import <nixpkgs> {}
, ocamlVersion ? import ./nix/ocamlDefaultVersion.nix
, opam2nix ?
pkgs.callPackage ./nix/opam2nix.nix {
inherit pkgs;
ocamlPackagesOverride = pkgs.ocaml-ng."ocamlPackages_${ocamlVersion}";

} }:

pkgs.callPackage ./nix { inherit ocamlVersion opam2nix; }
36 changes: 36 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{ pkgs, lib, stdenv, ocamlVersion, opam2nix }:
let
inherit (lib) strings;
args = {
inherit (pkgs.ocaml-ng."ocamlPackages_${ocamlVersion}") ocaml;
src =
let ignores = pkgs.lib.strings.fileContents ../.gitignore;
in pkgs.nix-gitignore.gitignoreSourcePure ignores ../.;
};

opam-selection = opam2nix.build (args // {
selection = "${./opam-selection_${ocamlVersion}.nix}";
});

localPackages =
let contents = builtins.attrNames (builtins.readDir ../.);
in builtins.filter (strings.hasSuffix ".opam") contents;

# list of dependencies with "with-test" flag manually
testPackageNames = [ "alcotest" ];
testPackages =
builtins.map (name: builtins.getAttr name opam-selection) testPackageNames;

resolve = opam2nix.resolve (args // {
selection = "./nix/opam-selection_${ocamlVersion}.nix";
}) (localPackages ++ testPackageNames);


in (builtins.listToAttrs (builtins.map (fname:
let packageName = strings.removeSuffix ".opam" fname;
in {
name = packageName;
value = builtins.getAttr packageName opam-selection;
}) localPackages)) // {
inherit resolve opam-selection testPackages;
}
1 change: 1 addition & 0 deletions nix/ocamlDefaultVersion.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"4_13"
Loading