-
Notifications
You must be signed in to change notification settings - Fork 33
/
flake.nix
165 lines (157 loc) · 5.74 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
opam2json = {
url = "github:tweag/opam2json";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
# Used for examples/tests and as a default repository
opam-repository = {
url = "github:ocaml/opam-repository";
flake = false;
};
# used for opam-monorepo
opam-overlays = {
url = "github:dune-universe/opam-overlays";
flake = false;
};
mirage-opam-overlays = {
url = "github:dune-universe/mirage-opam-overlays";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, opam2json, opam-repository
, opam-overlays, mirage-opam-overlays, ... }@inputs:
{
aux = import ./src/lib.nix nixpkgs.lib;
templates.simple = {
description =
"Simply build an opam package, preferrably a library, from a local directory";
path = ./templates/simple;
};
templates.executable = {
description =
"Build an executable from a local opam package, and provide a development shell with some convinient tooling";
path = ./templates/executable;
};
templates.multi-package = {
description =
"Build multiple packages from a single workspace, and provide a development shell with some convinient tooling";
path = ./templates/multi-package;
};
templates.default = self.templates.simple;
overlays = {
ocaml-overlay = import ./src/overlays/ocaml.nix;
ocaml-static-overlay = import ./src/overlays/ocaml-static.nix;
};
} // flake-utils.lib.eachDefaultSystem (system:
let
# The formats of opam2json output that we support
opam2json-versions = [ "0.4" ];
pkgs = nixpkgs.legacyPackages.${system}.extend
(nixpkgs.lib.composeManyExtensions [
(final: prev: {
opam2json = if __elem (prev.opam2json.version or null)
opam2json-versions then
prev.opam2json
else
(opam2json.overlay final prev).opam2json;
})
]);
opam-nix = import ./src/opam.nix {
inherit pkgs opam-repository opam-overlays mirage-opam-overlays;
};
in rec {
lib = opam-nix;
checks = packages
// (pkgs.callPackage ./examples/docfile { inherit opam-nix; }).checks;
legacyPackages = __mapAttrs (name: versions:
let
allVersions = __listToAttrs (map (version:
nixpkgs.lib.nameValuePair version (lib.queryToScope { } ({
ocaml-base-compiler = "*";
} // {
${name} = version;
})).${name}) versions);
in allVersions // {
latest = allVersions.${nixpkgs.lib.last versions};
}) (lib.listRepo opam-repository);
allChecks =
pkgs.runCommand "opam-nix-checks" { checks = __attrValues checks; }
"touch $out";
packages = let
examples = rec {
_0install = (import ./examples/0install/flake.nix).outputs {
self = _0install;
opam-nix = inputs.self;
inherit (inputs) flake-utils;
};
coq = (import ./examples/coq/flake.nix).outputs {
self = coq;
opam-nix = inputs.self;
inherit (inputs) nixpkgs opam-repository flake-utils;
};
frama-c = (import ./examples/frama-c/flake.nix).outputs {
self = frama-c;
opam-nix = inputs.self;
inherit (inputs) flake-utils;
};
opam-ed = (import ./examples/opam-ed/flake.nix).outputs {
self = opam-ed;
opam-nix = inputs.self;
inherit (inputs) flake-utils;
};
opam2json = (import ./examples/opam2json/flake.nix).outputs {
self = opam2json;
opam-nix = inputs.self;
inherit (inputs) opam2json flake-utils;
};
ocaml-lsp = (import ./examples/ocaml-lsp/flake.nix).outputs {
self = ocaml-lsp;
opam-nix = inputs.self;
inherit (inputs) nixpkgs flake-utils;
};
opam2json-static =
(import ./examples/opam2json-static/flake.nix).outputs {
self = opam2json-static;
opam-nix = inputs.self;
inherit (inputs) opam2json flake-utils;
};
tezos = (import ./examples/tezos/flake.nix).outputs {
self = tezos;
opam-nix = inputs.self;
inherit (inputs) flake-utils;
};
materialized-opam-ed =
(import ./examples/materialized-opam-ed/flake.nix).outputs {
self = materialized-opam-ed;
opam-nix = inputs.self;
inherit (inputs) flake-utils;
};
};
in {
opam-nix-gen = pkgs.substituteAll {
name = "opam-nix-gen";
src = ./scripts/opam-nix-gen.in;
dir = "bin";
isExecutable = true;
inherit (pkgs) runtimeShell coreutils nix;
opamNix = "${self}";
};
opam-nix-regen = pkgs.substituteAll {
name = "opam-nix-regen";
src = ./scripts/opam-nix-regen.in;
dir = "bin";
isExecutable = true;
inherit (pkgs) runtimeShell jq;
opamNixGen =
"${self.packages.${system}.opam-nix-gen}/bin/opam-nix-gen";
};
} // builtins.mapAttrs (_: e: e.defaultPackage.${system}) examples;
});
}