Skip to content
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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

- Remove `flake-utils` Nix Flake dependency

## Features

- Introduce a configuration option to control dune diagnostics. The option is
Expand Down
34 changes: 0 additions & 34 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

249 changes: 115 additions & 134 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,130 +1,84 @@
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
};

outputs = { self, flake-utils, nixpkgs, ... }@inputs:
outputs = { self, nixpkgs, ... }@inputs:
let
package = "ocaml-lsp-server";
overlay = final: prev: {
${package} = prev.${package}.overrideAttrs (_: {
# Do not add share/nix-support, so that dependencies from
# the scope don't leak into dependent derivations
doNixSupport = false;
});
dune-release = prev.dune-release.overrideAttrs (_: {
doCheck = false;
});
ocamlPackages = prev.ocamlPackages.overrideScope' (oself: osuper:
let
fixPreBuild = o: {
propagatedBuildInputs = o.propagatedBuildInputs ++ [ oself.pp ];
preBuild = ''
rm -r vendor/csexp vendor/pp
'';
};
in
{
dyn = osuper.dyn.overrideAttrs fixPreBuild;
dune-private-libs = osuper.dune-private-libs.overrideAttrs fixPreBuild;
dune-glob = osuper.dune-glob.overrideAttrs fixPreBuild;
dune-action-plugin = osuper.dune-action-plugin.overrideAttrs fixPreBuild;
dune-rpc = osuper.dune-rpc.overrideAttrs fixPreBuild;
stdune = osuper.stdune.overrideAttrs fixPreBuild;
});
};
lspPackage = pkgs:
with pkgs.ocamlPackages;
buildDunePackage {
pname = package;
version = "n/a";
src = ./.;
duneVersion = "3";
buildInputs = [
ocamlc-loc
astring
camlp-streams
dune-build-info
re
dune-rpc
chrome-trace
dyn
fiber
xdg
ordering
spawn
pp
csexp
ocamlformat-rpc-lib
stdune
yojson
ppx_yojson_conv_lib
uutf
merlin-lib
];
propagatedBuildInputs = [ ];
doCheck = false;
buildPhase = ''
runHook preBuild
dune build ${package}.install --release ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
runHook postBuild
'';
meta = {
mainProgram = "ocamllsp";
};
};
in
{
overlays.default = (final: prev: {
ocamlPackages = prev.ocamlPackages.overrideScope (oself: osuper:
with oself;

{
ocaml-lsp = lspPackage final;
}
);
supportedSystems = [
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not Nix’s defaults (theirs includes 32-bit Linux last I checked), but matches the default systems of flake-utils so the change should have no effect on anyone.

"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];

forAllSystems = nixpkgs.lib.genAttrs supportedSystems;

nixpkgsFor = forAllSystems (system: import nixpkgs {
inherit system;
overlays = builtins.attrValues self.overlays;
});
} // (flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { overlays = [ overlay ]; inherit system; };
inherit (pkgs.ocamlPackages) buildDunePackage;
fast = rec {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are stubs to speed up the build? I moved them all to packages since it doesn’t hurt while using less recs & temporary attrsets which slow down evaluation.

in
{
overlays = {
default = final: prev: {
${package} = prev.${package}.overrideAttrs (_: {
# Do not add share/nix-support, so that dependencies from
# the scope don't leak into dependent derivations
doNixSupport = false;
});

jsonrpc = buildDunePackage {
pname = "jsonrpc";
version = "n/a";
src = ./.;
duneVersion = "3";
propagatedBuildInputs = with pkgs.ocamlPackages; [ ];
dune-release = prev.dune-release.overrideAttrs (_: {
doCheck = false;
};
});

lsp = buildDunePackage {
pname = "lsp";
version = "n/a";
src = ./.;
duneVersion = "3";
propagatedBuildInputs = with pkgs.ocamlPackages; [
jsonrpc
yojson
stdune
ppx_yojson_conv_lib
uutf
];
checkInputs = with pkgs.ocamlPackages; [ cinaps ppx_expect ];
doCheck = false;
};
ocamlPackages = prev.ocamlPackages.overrideScope' (oself: osuper:
let
fixPreBuild = o: {
propagatedBuildInputs = o.propagatedBuildInputs ++ [ oself.pp ];
preBuild = ''
rm -r vendor/csexp vendor/pp
'';
};
in
{
dyn = osuper.dyn.overrideAttrs fixPreBuild;
dune-private-libs = osuper.dune-private-libs.overrideAttrs fixPreBuild;
dune-glob = osuper.dune-glob.overrideAttrs fixPreBuild;
dune-action-plugin = osuper.dune-action-plugin.overrideAttrs fixPreBuild;
dune-rpc = osuper.dune-rpc.overrideAttrs fixPreBuild;
stdune = osuper.stdune.overrideAttrs fixPreBuild;
ocaml-lsp = self.packages.${prev.system}.ocaml-lsp;
});
};

ocaml-lsp-only = final: prev: {
ocamlPackages = prev.ocamlPackages.overrideScope' (_: _: {
ocaml-lsp = self.packages.${prev.system}.ocaml-lsp;
});
};
};

packages = forAllSystems (system:
let
pkgs = nixpkgsFor.${system};
inherit (pkgs.ocamlPackages) buildDunePackage;
in
{
# we have a package without opam2nix for easy consumption for nix users
default = self.packages.${system}.ocaml-lsp;

ocaml-lsp = buildDunePackage {
pname = "ocaml-lsp";
pname = package;
version = "n/a";
src = ./.;
duneVersion = "3";
checkInputs = with pkgs.ocamlPackages; [ ppx_expect ];
propagatedBuildInputs = with pkgs.ocamlPackages; [
buildInputs = with pkgs.ocamlPackages; [
ocamlc-loc
octavius
astring
camlp-streams
dune-build-info
re
dune-rpc
Expand All @@ -141,43 +95,70 @@
yojson
ppx_yojson_conv_lib
uutf
lsp
astring
camlp-streams
merlin-lib
] ++ [
self.packages.${system}.lsp
];
propagatedBuildInputs = [ ];
doCheck = false;
buildPhase = ''
runHook preBuild
dune build ${package}.install --release ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
runHook postBuild
'';
meta = {
mainProgram = "ocamllsp";
};
};

# stub builds
jsonrpc = buildDunePackage {
pname = "jsonrpc";
version = "n/a";
src = ./.;
duneVersion = "3";
propagatedBuildInputs = with pkgs.ocamlPackages; [ ];
doCheck = false;
};
};
in
{
packages =
rec {
# we have a package without opam2nix for easy consumption for nix users
default = lspPackage pkgs;

ocaml-lsp = fast.ocaml-lsp;
lsp = buildDunePackage {
pname = "lsp";
version = "n/a";
src = ./.;
duneVersion = "3";
propagatedBuildInputs = with pkgs.ocamlPackages; [
yojson
stdune
ppx_yojson_conv_lib
uutf
] ++ [
self.packages.${system}.jsonrpc
];
checkInputs = with pkgs.ocamlPackages; [ cinaps ppx_expect ];
doCheck = false;
};
});

devShells = {
devShells = forAllSystems (system:
let pkgs = nixpkgsFor.${system}; in {
default = pkgs.mkShell {
buildInputs = (with pkgs;
[
# dev tools
ocamlformat_0_26_1
yarn
name = package;
inputsFrom = builtins.attrValues self.packages.${system};
buildInputs = with pkgs; [
# dev tools
ocamlformat_0_26_1
yarn

ocamlPackages.ppx_expect
ocamlPackages.utop
ocamlPackages.cinaps
ocamlPackages.ppx_yojson_conv
]);
inputsFrom = [ fast.ocaml-lsp fast.jsonrpc fast.lsp ];
ocamlPackages.ppx_expect
ocamlPackages.utop
ocamlPackages.cinaps
ocamlPackages.ppx_yojson_conv
];
};

release = pkgs.mkShell {
buildInputs = [ pkgs.dune-release ];
};
};
}));
});
};
}