Skip to content

Commit

Permalink
Merge pull request #122 from mlabs-haskell/jared/114-leftovers-haskel…
Browse files Browse the repository at this point in the history
…l-dev-shell

Adding `devShells` to play with generated schema code for Haskell's Prelude and Plutus Prelude
  • Loading branch information
jaredponn authored Oct 24, 2023
2 parents 29e061b + 5cd920c commit 9b3132b
Showing 1 changed file with 151 additions and 2 deletions.
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.
_:
{ 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"
];
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;
};
};
}

0 comments on commit 9b3132b

Please sign in to comment.