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

Add onix-based flake, associated make task, and .envrc template #7

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
13 changes: 13 additions & 0 deletions .envrc.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# rebuild the environment on `nix-direnv-reload` only
nix_direnv_manual_reload

# direnv will consider the environment changed if these files change, and
# nix-direnv will then prompt for the manual reload
watch_file flake.nix flake.lock onix-lock.json onix-lock-dev.json

# use the flake with the `default` devShell:
use flake

# To use another devShell, you can use (e.g. for devShell.other:
# use flake .#other

2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
operating-system: [ubuntu-latest]
ocaml-compiler: [ '4.08.1', '4.11.0' ]
ocaml-compiler: [ '4.08.1', '4.11.0', '4.12.1' ]
steps:
- uses: actions/checkout@master
- uses: ocaml/setup-ocaml@v2
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@ clean:

watch:
@dune build @all -w

nix-lock:
nix run .#onix-lock

.PHONY: onix-lock.json
onix-lock.json:
onix lock ./imandra-document.opam --resolutions="ocaml-system=5.2.0" --lock-file ./onix-lock.json

.PHONY: onix-lock-dev.json
onix-lock-dev.json:
onix lock ./imandra-document.opam --resolutions="ocaml-system=5.2.0,ocaml-lsp-server,utop" --with-test=true --lock-file ./onix-lock-dev.json

.PHONY: lock
lock: onix-lock.json onix-lock-dev.json
git add onix-lock.json onix-lock-dev.json

98 changes: 98 additions & 0 deletions flake.lock

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

102 changes: 102 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";

onix = {
url = "github:rizo/onix/3740a2beb84bc21860385f8bbb0d5f557842de03";
Copy link
Author

Choose a reason for hiding this comment

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

Per the onix readme, the API might change, so I've pinned the version here.

inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs =
{
self,
nixpkgs,
flake-utils,
onix,
}@inputs:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
onix' = onix.packages.${system}.latest;
compilerVersion = "5.2.0";
opamFiles = [
./imandra-document.opam
];
onixEnv = onix'.env {
path = ./.;
roots = opamFiles;
lock = ./onix-lock.json;
deps = {
"ocaml-system" = compilerVersion;
};
};
onixEnvDev = onix'.env {
path = ./.;
roots = opamFiles;
lock = ./onix-lock-dev.json;
deps = {
"ocaml-system" = compilerVersion;
"ocaml-lsp-server" = "*";
"utop" = "*";
};
};
onixLock =
let
shellHook = pkgs.writeText "onix-lock-shellHook" onixEnv.lock.shellHook;
lockPatched = pkgs.runCommand "onix-lock-shellHook-patched" { } ''
sed 's:--lock-file=/nix/store/.*/onix-lock.json:--lock-file=./onix-lock.json:' "${shellHook}" > "$out"
chmod +x "$out"
'';
in
pkgs.writeShellApplication {
name = "onix-lock";
runtimeInputs = [ onix' ];
text = lockPatched;
};
onixLockDev =
let
shellHook = pkgs.writeText "onix-lock-dev-shellHook" onixEnvDev.lock.shellHook;
emeinhardt marked this conversation as resolved.
Show resolved Hide resolved
lockPatched = pkgs.runCommand "onix-lock-dev-shellHook-patched" { } ''
sed 's:--lock-file=/nix/store/.*/onix-lock-dev.json:--lock-file=./onix-lock-dev.json:' "${shellHook}" > "$out"
chmod +x "$out"
'';
in
pkgs.writeShellApplication {
name = "onix-lock-dev";
runtimeInputs = [ onix' ];
text = lockPatched;
};
in
rec {
formatter = pkgs.nixfmt-rfc-style;

packages.imandra-document = onixEnv.pkgs.imandra-document;
packages.default = onixEnv.pkgs.imandra-document;

packages.onix-lock = onixLock;
packages.onix-lock-dev = onixLockDev;
devShells.onixLock = pkgs.mkShell {
buildInputs = [
onix'
];
};

devShells.default = onixEnvDev.shell.overrideAttrs (
final: prev: {
buildInputs = prev.buildInputs ++ [
pkgs.ocamlformat_0_22_4
pkgs.dune_3
pkgs.ocaml
onix'
];
}
);

# Allows the default devshell to be cached
packages.devShell-default = devShells.default.inputDerivation;
}
);
}
Loading
Loading