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

Update Nix configuration #178

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .nix/with-nixpkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
installPhase = ''
make install PREFIX=$out LIBDIR=$OCAMLFIND_DESTDIR
'';

meta.description =
"Morbig, where all the dependencies come from `nixpkgs`.";
};
};
}
8 changes: 7 additions & 1 deletion .nix/with-opam-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@
resolveArgs.with-doc = true;
resolveArgs.with-test = true;
} "morbig" ./.. { ocaml-base-compiler = "*"; };
in { packages.with-opam-nix = scope.morbig // { inherit scope; }; };
in {
packages.with-opam-nix = scope.morbig // {
inherit scope;
meta.description =
"Morbig, where all the dependencies are handled by `opam-nix`.";
};
};
}
72 changes: 37 additions & 35 deletions flake.lock

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

55 changes: 22 additions & 33 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

opam-nix.url = "github:tweag/opam-nix";
opam-nix.inputs.nixpkgs.follows = "nixpkgs";
opam-nix = {
url = "github:tweag/opam-nix";
inputs.nixpkgs.follows = "nixpkgs";
};

pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.nixpkgs-stable.follows = "";
};

flake-parts.url = "github:hercules-ci/flake-parts";
};
Expand All @@ -24,43 +29,27 @@
perSystem = { self', pkgs, config, ... }: {
formatter = pkgs.nixfmt;

packages.default = self'.packages.with-nixpkgs;

devShells.default = pkgs.mkShell {
buildInputs = with pkgs.ocamlPackages; [
ocaml-lsp
ocp-indent
headache
];
inputsFrom = [ self'.packages.default ];
shellHook = config.pre-commit.installationScript;
packages.default = self'.packages.with-nixpkgs // {
meta.description = "Alias for `with-nixpkgs`.";
};

## For each package, we define a corresponding devShell using its inputs
## and adding pre-commit hooks and development tools on top.
devShells = builtins.mapAttrs (_: package:
pkgs.mkShell {
buildInputs = (with pkgs; [ headache ])
++ (with pkgs.ocamlPackages; [ ocaml-lsp ocp-indent ]);
inputsFrom = [ package ];
shellHook = config.pre-commit.installationScript;
}) self'.packages;

pre-commit.settings.hooks = {
dune-opam-sync.enable = true;
opam-lint.enable = true;
ocp-indent.enable = true;
nixfmt.enable = true;
deadnix.enable = true;

## NOTE: The version of the `dune-fmt` hook in `pre-commit-hooks.nix`
## forgets to bring OCaml in the environment. In the meantime, we use
## our own; will change back to `dune-fmt.enable = true` later.
tmp-dune-fmt = {
enable = true;
name = "dune-fmt";
description = "Runs Dune's formatters on the code tree.";
entry = let
dune-fmt = pkgs.writeShellApplication {
name = "dune-fmt";
text = ''
export PATH=${pkgs.ocaml}/bin:$PATH
exec ${pkgs.dune_3}/bin/dune fmt "$@"
'';
};
in "${dune-fmt}/bin/dune-fmt";
pass_filenames = false;
};
dune-fmt.enable = true;
};
};

Expand Down