Skip to content

Commit 9b3132b

Browse files
authored
Merge pull request #122 from mlabs-haskell/jared/114-leftovers-haskell-dev-shell
Adding `devShells` to play with generated schema code for Haskell's Prelude and Plutus Prelude
2 parents 29e061b + 5cd920c commit 9b3132b

File tree

1 file changed

+151
-2
lines changed

1 file changed

+151
-2
lines changed

libs/build.nix

Lines changed: 151 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Foundational .lbf packages
22
# TODO(bladyjoker): Make packages that actually try and compile.
3-
_:
3+
{ inputs, ... }:
44
{
55
perSystem = { pkgs, config, ... }: {
66

@@ -41,7 +41,13 @@ _:
4141
imports = [ ./lbf-prelude ];
4242
files = [ "Plutus/V1.lbf" "Plutus/V2.lbf" ];
4343
classes = [ "Prelude.Eq" "Prelude.Json" "Plutus.V1.PlutusData" ];
44-
dependencies = [ "lbf-prelude" ];
44+
dependencies =
45+
[
46+
"lbf-prelude"
47+
# TODO(jaredponn): Investigate why `lbr-plutus` is _not_
48+
# being automatically included as a dependency.
49+
"lbr-plutus"
50+
];
4551
configs = [ ../lambda-buffers-codegen/data/haskell-prelude-base.json ../lambda-buffers-codegen/data/haskell-plutus-plutustx.json ];
4652
};
4753

@@ -57,6 +63,149 @@ _:
5763

5864
};
5965

66+
# The following devShells allow one to conveniently play with some of the
67+
# above schemas
68+
devShells = {
69+
dev-prelude-haskell =
70+
# Note:
71+
# `lbf-prelude-haskell` (defined above
72+
# `packages.lbf-prelude-haskell`) essentially generates a cabal
73+
# project from the `./Prelude.lbf` schema; and the following uses
74+
# `haskell.nix` to convert the `.cabal` project into a dev shell.
75+
# This is a dev shell which provides
76+
# - ghc with `lbf-prelude-haskell` package (and its dependencies)
77+
# - the CLI application (`lbf-prelude-to-haskell`) to compile `.lbf`
78+
# schemas
79+
let
80+
project = { lib, ... }: {
81+
src = config.packages.lbf-prelude-haskell;
82+
83+
name = "lbf-prelude-haskell";
84+
85+
inherit (config.settings.haskell) index-state compiler-nix-name;
86+
87+
extraHackage = [
88+
"${config.packages.lbr-prelude-haskell-src}"
89+
"${config.packages.lbf-prelude-haskell}"
90+
];
91+
92+
modules = [
93+
(_: {
94+
packages = {
95+
allComponent.doHoogle = true;
96+
allComponent.doHaddock = true;
97+
98+
# Enable strict compilation
99+
lbf-prelude.configureFlags = [ "-f-dev" ];
100+
};
101+
})
102+
];
103+
104+
shell = {
105+
106+
withHoogle = true;
107+
108+
exactDeps = true;
109+
110+
nativeBuildInputs = config.settings.shell.tools
111+
++ [ config.packages.lbf-prelude-to-haskell ];
112+
113+
# Note: the `additional` (contrast to `packages`) attribute
114+
# includes the dependencies + the package itself. See:
115+
# https://input-output-hk.github.io/haskell.nix/reference/library.html#shellfor
116+
# This *must* be the name of the autogenerated cabal package from
117+
# `lbf-prelude-haskell`
118+
additional = ps: [ ps.lbf-prelude ];
119+
120+
tools = {
121+
cabal = { };
122+
haskell-language-server = { };
123+
};
124+
125+
shellHook = lib.mkForce config.settings.shell.hook;
126+
};
127+
};
128+
hsNixFlake = (pkgs.haskell-nix.cabalProject' [
129+
inputs.mlabs-tooling.lib.mkHackageMod
130+
inputs.mlabs-tooling.lib.moduleMod
131+
project
132+
]).flake { };
133+
in
134+
hsNixFlake.devShell;
135+
136+
dev-plutustx =
137+
# Note:
138+
# Similarly to `dev-prelude-haskell`, `packages.lbf-plutus-haskell`
139+
# essentially generates a cabal project from the `*.lbf` schemas; and
140+
# the following uses `haskell.nix` to convert the `.cabal` project into
141+
# a dev shell.
142+
# This is a dev shell which provides
143+
# - ghc with `lbf-plutus-haskell` package (and its dependencies)
144+
# - the CLI application (`lbf-plutus-to-haskell`) to compile `.lbf`
145+
# schemas.
146+
#
147+
# Note:
148+
# This is mostly duplicated code from `dev-prelude-haskell`
149+
let
150+
project = { lib, ... }: {
151+
src = config.packages.lbf-plutus-haskell;
152+
153+
name = "lbf-plutus-haskell";
154+
155+
inherit (config.settings.haskell) index-state compiler-nix-name;
156+
157+
extraHackage = [
158+
"${config.packages.lbr-prelude-haskell-src}"
159+
"${config.packages.lbf-prelude-haskell}"
160+
"${config.packages.lbr-plutus-haskell-src}"
161+
"${config.packages.lbf-plutus-haskell}"
162+
];
163+
164+
modules = [
165+
(_: {
166+
packages = {
167+
allComponent.doHoogle = true;
168+
allComponent.doHaddock = true;
169+
170+
# Enable strict compilation
171+
lbf-plutus.configureFlags = [ "-f-dev" ];
172+
};
173+
})
174+
];
175+
176+
shell = {
177+
178+
withHoogle = true;
179+
180+
exactDeps = true;
181+
182+
nativeBuildInputs = config.settings.shell.tools
183+
++ [
184+
# We include both the Prelude and Plutus
185+
# frontend. Perhaps, we should _only_ include the
186+
# Plutus frontend, but it doesn't hurt to include both.
187+
config.packages.lbf-prelude-to-haskell
188+
config.packages.lbf-plutus-to-haskell
189+
];
190+
191+
additional = ps: [ ps.lbf-plutus ];
192+
193+
tools = {
194+
cabal = { };
195+
haskell-language-server = { };
196+
};
197+
198+
shellHook = lib.mkForce config.settings.shell.hook;
199+
};
200+
};
201+
hsNixFlake = (pkgs.haskell-nix.cabalProject' [
202+
inputs.mlabs-tooling.lib.mkHackageMod
203+
inputs.mlabs-tooling.lib.moduleMod
204+
project
205+
]).flake { };
206+
in
207+
hsNixFlake.devShell;
208+
};
60209
};
61210
}
62211

0 commit comments

Comments
 (0)