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

Adding devShells to play with generated schema code for Haskell's Prelude and Plutus Prelude #122

Merged
merged 3 commits into from
Oct 24, 2023
Merged
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
153 changes: 151 additions & 2 deletions libs/build.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Foundational .lbf packages
# TODO(bladyjoker): Make packages that actually try and compile.
_:
jaredponn marked this conversation as resolved.
Show resolved Hide resolved
{ inputs, ... }:
{
perSystem = { pkgs, config, ... }: {

Expand Down Expand Up @@ -41,7 +41,13 @@ _:
imports = [ ./lbf-prelude ];
files = [ "Plutus/V1.lbf" "Plutus/V2.lbf" ];
classes = [ "Prelude.Eq" "Prelude.Json" "Plutus.V1.PlutusData" ];
dependencies = [ "lbf-prelude" ];
dependencies =
[
"lbf-prelude"
# TODO(jaredponn): Investigate why `lbr-plutus` is _not_
# being automatically included as a dependency.
"lbr-plutus"
jaredponn marked this conversation as resolved.
Show resolved Hide resolved
];
configs = [ ../lambda-buffers-codegen/data/haskell-prelude-base.json ../lambda-buffers-codegen/data/haskell-plutus-plutustx.json ];
};

Expand All @@ -57,6 +63,149 @@ _:

};

# The following devShells allow one to conveniently play with some of the
# above schemas
devShells = {
dev-prelude-haskell =
# Note:
# `lbf-prelude-haskell` (defined above
# `packages.lbf-prelude-haskell`) essentially generates a cabal
# project from the `./Prelude.lbf` schema; and the following uses
# `haskell.nix` to convert the `.cabal` project into a dev shell.
# This is a dev shell which provides
# - ghc with `lbf-prelude-haskell` package (and its dependencies)
# - the CLI application (`lbf-prelude-to-haskell`) to compile `.lbf`
# schemas
let
project = { lib, ... }: {
src = config.packages.lbf-prelude-haskell;

name = "lbf-prelude-haskell";

inherit (config.settings.haskell) index-state compiler-nix-name;

extraHackage = [
"${config.packages.lbr-prelude-haskell-src}"
"${config.packages.lbf-prelude-haskell}"
];

modules = [
(_: {
packages = {
allComponent.doHoogle = true;
allComponent.doHaddock = true;

# Enable strict compilation
lbf-prelude.configureFlags = [ "-f-dev" ];
};
})
];

shell = {

withHoogle = true;

exactDeps = true;

nativeBuildInputs = config.settings.shell.tools
++ [ config.packages.lbf-prelude-to-haskell ];

# Note: the `additional` (contrast to `packages`) attribute
# includes the dependencies + the package itself. See:
# https://input-output-hk.github.io/haskell.nix/reference/library.html#shellfor
# This *must* be the name of the autogenerated cabal package from
# `lbf-prelude-haskell`
additional = ps: [ ps.lbf-prelude ];

tools = {
cabal = { };
haskell-language-server = { };
};

shellHook = lib.mkForce config.settings.shell.hook;
};
};
hsNixFlake = (pkgs.haskell-nix.cabalProject' [
inputs.mlabs-tooling.lib.mkHackageMod
inputs.mlabs-tooling.lib.moduleMod
project
]).flake { };
in
hsNixFlake.devShell;

dev-plutustx =
# Note:
# Similarly to `dev-prelude-haskell`, `packages.lbf-plutus-haskell`
# essentially generates a cabal project from the `*.lbf` schemas; and
# the following uses `haskell.nix` to convert the `.cabal` project into
# a dev shell.
# This is a dev shell which provides
# - ghc with `lbf-plutus-haskell` package (and its dependencies)
# - the CLI application (`lbf-plutus-to-haskell`) to compile `.lbf`
# schemas.
#
# Note:
# This is mostly duplicated code from `dev-prelude-haskell`
let
project = { lib, ... }: {
src = config.packages.lbf-plutus-haskell;

name = "lbf-plutus-haskell";

inherit (config.settings.haskell) index-state compiler-nix-name;

extraHackage = [
"${config.packages.lbr-prelude-haskell-src}"
"${config.packages.lbf-prelude-haskell}"
"${config.packages.lbr-plutus-haskell-src}"
"${config.packages.lbf-plutus-haskell}"
];

modules = [
(_: {
packages = {
allComponent.doHoogle = true;
allComponent.doHaddock = true;

# Enable strict compilation
lbf-plutus.configureFlags = [ "-f-dev" ];
};
})
];

shell = {

withHoogle = true;

exactDeps = true;

nativeBuildInputs = config.settings.shell.tools
++ [
# We include both the Prelude and Plutus
# frontend. Perhaps, we should _only_ include the
# Plutus frontend, but it doesn't hurt to include both.
config.packages.lbf-prelude-to-haskell
config.packages.lbf-plutus-to-haskell
];

additional = ps: [ ps.lbf-plutus ];

tools = {
cabal = { };
haskell-language-server = { };
};

shellHook = lib.mkForce config.settings.shell.hook;
};
};
hsNixFlake = (pkgs.haskell-nix.cabalProject' [
inputs.mlabs-tooling.lib.mkHackageMod
inputs.mlabs-tooling.lib.moduleMod
project
]).flake { };
in
hsNixFlake.devShell;
};
};
}