-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
97 lines (97 loc) · 4.17 KB
/
flake.nix
File metadata and controls
97 lines (97 loc) · 4.17 KB
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
{
description = "Literally the simplest script in existence for changing directories and entering a nix shell.";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.dunix.url = "github:eureka-cpu/dunix/master";
outputs = { self, nixpkgs, dunix }:
let
inherit (builtins) attrValues;
inherit (nixpkgs.lib) genAttrs;
inherit (nixpkgs.lib.systems) flakeExposed;
eachSystem = f: genAttrs flakeExposed (system: f (import nixpkgs { inherit system; overlays = [ dunix.overlays.default ]; }));
in
{
packages = eachSystem (pkgs:
let
inherit (builtins) elemAt split attrNames foldl' listToAttrs;
inherit (pkgs.ocamlPackages) buildDunePackage;
inherit (pkgs.lib) cleanSource getLicenseFromSpdxId;
dune-project = pkgs.importDuneProject ./dune-project;
depends = let depends = listToAttrs (map (dep: { name = dep; value = pkgs.ocamlPackages.${dep}; }) (attrNames (foldl' (acc: dep: acc // dep) { } dune-project.package.depends))); in removeAttrs depends [ "dune" "ocaml" ];
in
{
default = buildDunePackage (finalAttrs: {
inherit (dune-project) version;
pname = dune-project.package.name;
src = cleanSource ./.;
buildInputs = attrValues depends;
doCheck = true;
nativeCheckInputs = attrValues {
inherit (pkgs) ocamlformat;
inherit (pkgs) rustc clippy rustfmt;
};
checkPhase = ''
red() {
printf "\033[1;31m%s\033[0m" "$*"
}
if ! diff --color=always "${finalAttrs.src}/${dune-project.name}.opam" "./${dune-project.name}.opam"; then
printf "\n"
printf "$(red "Error:") Generated opam file does not match provided opam file\n"
exit 1
fi
if ! dune test --force --no-buffer --display=quiet; then
printf "\n"
printf "$(red "Error:") dune test reported test failures\n"
exit 1
fi
if ! clippy-driver --test "${finalAttrs.src}/test/test_ns.rs" -Dwarnings; then
printf "\n"
printf "$(red "Error:") test.rs contains warnings\n"
exit 1
fi
if ! dune fmt --diff-command="diff --color=always"; then
printf "\n"
printf "$(red "Error:") Some OCaml files are not properly formatted\n"
exit 1
fi
if ! rustfmt --check --color=always "${finalAttrs.src}/test/test_ns.rs"; then
printf "\n"
printf "$(red "Error:") test.rs is not properly formatted\n"
exit 1
fi
'';
postInstall = ''
${depends.cmdliner}/bin/cmdliner install tool-support $out/bin/ns $out
${depends.cmdliner}/bin/cmdliner install generic-completion $out/share
'';
meta =
let
inherit (dune-project.source) type owner repo;
maintainers = map (m: pkgs.lib.maintainers.${(elemAt (split " " m) 0)}) dune-project.maintainers;
in
{
inherit maintainers;
description = dune-project.package.synopsis;
longDescription = dune-project.package.description;
homepage = "https://${type}.com/${owner}/${repo}";
license = getLicenseFromSpdxId dune-project.license;
};
});
});
devShells = eachSystem (pkgs: {
default = pkgs.mkShell {
inputsFrom = [ self.packages.${pkgs.stdenv.hostPlatform.system}.default ];
packages = attrValues {
inherit (pkgs) ocamlformat nil rustc clippy rustfmt;
inherit (pkgs.ocamlPackages) ocaml-lsp odoc;
};
shellHook = ''
dune build # Ensure build artifacts exist for LSP
'';
};
});
checks = eachSystem (pkgs: {
inherit (self.packages.${pkgs.stdenv.hostPlatform.system}) default;
});
formatter = eachSystem (pkgs: pkgs.nixpkgs-fmt);
};
}