-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflake.nix
81 lines (75 loc) · 2.83 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{
description = "PCRE2 bindings for OCaml";
inputs = {
opam-nix.url = "github:tweag/opam-nix";
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
opam-repository = {
url = "github:ocaml/opam-repository";
flake = false;
};
};
outputs = { self, flake-utils, opam-nix, nixpkgs, opam-repository }:
let package = "pcre2";
in flake-utils.lib.eachDefaultSystem (system:
let
# TODO Use pkgsStatic if on linux
pkgs = nixpkgs.legacyPackages.${system};
on = opam-nix.lib.${system};
opamRepos = [ "${opam-repository}" ];
in let
devOpamPackagesQuery = {
# You can add "development" ocaml packages here. They will get added
# to the devShell automatically.
ocaml-lsp-server = "*";
utop = "*";
ocamlformat = "*";
earlybird = "*";
merlin = "*";
};
opamQuery = devOpamPackagesQuery // {
## You can force versions of certain packages here
# force the ocaml compiler to be 4.14.2 and from opam
ocaml-base-compiler = "4.14.2";
# FIXME: shouldn't be needed. doesn't pick up with-test deps?
ounit2 = "*";
};
# repos = opamRepos to force newest version of opam
scope = on.buildOpamProject' { repos = opamRepos; } ./. opamQuery;
scopeOverlay = final: prev: {
# You can add overrides here
${package} = prev.${package}.overrideAttrs (prev: {
# Prevent the ocaml dependencies from leaking into dependent environments
doNixSupport = false;
# add ounit2 since it's not pulled in for whatever reason
buildInputs = prev.buildInputs ++ [final.ounit2];
});
};
scope' = scope.overrideScope' scopeOverlay;
# for development
devOpamPackages = builtins.attrValues
(pkgs.lib.getAttrs (builtins.attrNames devOpamPackagesQuery) scope');
# osemgrep/semgrep-core
# package with all opam deps but nothing else
baseOpamPackage = scope'.${package}; # Packages from devPackagesQuery
pcre2 = baseOpamPackage.overrideAttrs (prev: rec {
pname = "pcre2";
buildInputs = prev.buildInputs;
buildPhase' = ''
dune build
'';
});
in {
packages.pcre2 = pcre2;
formatter = pkgs.nixpkgs-fmt;
devShells.default = pkgs.mkShell {
# See comment above osemgrep.buildPhase for why we need this
# This doesnt work there because idk
shellHook = with pkgs; ''
export NIX_CXXFLAGS_COMPILE="$NIX_CXXFLAGS_COMPILE -I${pkgs.libcxx.dev}/include/c++/v1"
'';
inputsFrom = [ pcre2 ];
buildInputs = devOpamPackages;
};
});
}