Skip to content

Commit

Permalink
Polish + transition towards nix run over Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
emeinhardt committed Nov 18, 2024
1 parent b83118d commit 3d6fc96
Show file tree
Hide file tree
Showing 5 changed files with 367 additions and 28 deletions.
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ clean:
watch:
@dune build @all -w

onix-lock:
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
onix lock ./imandra-document.opam --resolutions="ocaml-system=5.2.0,ocaml-lsp-server" --with-test=true --lock-file ./onix-lock-dev.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

1 change: 1 addition & 0 deletions flake.lock

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

88 changes: 67 additions & 21 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,100 @@
nixpkgs.url = "nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";

onix.url = "github:rizo/onix";
onix.inputs.nixpkgs.follows = "nixpkgs";
onix = {
url = "github:rizo/onix/3740a2beb84bc21860385f8bbb0d5f557842de03";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, flake-utils, onix }@inputs:
flake-utils.lib.eachDefaultSystem (system:
outputs =
{
self,
nixpkgs,
flake-utils,
onix,
}@inputs:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
onix' = onix.packages.${system}.latest;
opamFiles = [
compilerVersion = "5.2.0";
opamFiles = [
./imandra-document.opam
];
onixEnv = onix'.env {
path = ./.;
roots = opamFiles;
lock = ./onix-lock.json;
deps = { "ocaml-system" = "*"; };
deps = {
"ocaml-system" = compilerVersion;
};
};
onixEnvDev = onix'.env {
path = ./.;
roots = opamFiles;
lock = ./onix-lock-dev.json;
deps = {
"ocaml-system" = "*";
"ocaml-system" = compilerVersion;
"ocaml-lsp-server" = "*";
"utop" = "*";
};
};

in rec {
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::' "${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;
lockPatched = pkgs.runCommand "onix-lock-dev-shellHook-patched" { } ''
sed 's:--lock-file=/nix/store/.*/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;

devShells.onixLock = pkgs.mkShell {
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'
];
});
devShells.default = onixEnvDev.shell.overrideAttrs (
final: prev: {
buildInputs = prev.buildInputs ++ [
pkgs.ocamlformat_0_22_4
pkgs.dune_3
pkgs.ocaml
onix'
];
}
);

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

0 comments on commit 3d6fc96

Please sign in to comment.