Skip to content

Commit 8980ca5

Browse files
author
jared
committed
Added devShells: dev-prelude-haskell and dev-plutustx for
conveniently playing around with some `.lbf` schemas in Haskell
1 parent 29e061b commit 8980ca5

File tree

1 file changed

+144
-1
lines changed

1 file changed

+144
-1
lines changed

libs/build.nix

Lines changed: 144 additions & 1 deletion
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

@@ -57,6 +57,149 @@ _:
5757

5858
};
5959

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

0 commit comments

Comments
 (0)