From e6fb64ebc4abf40d1ecef1de0df809ac54fc3b23 Mon Sep 17 00:00:00 2001 From: jared <> Date: Mon, 23 Oct 2023 23:58:17 -0600 Subject: [PATCH] Added `devShells`: `dev-prelude-haskell` and `dev-plutustx` for Conveniently playing around with some `.lbf` schemas in Haskell --- libs/build.nix | 145 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 144 insertions(+), 1 deletion(-) diff --git a/libs/build.nix b/libs/build.nix index 7b13b783..9667b0be 100644 --- a/libs/build.nix +++ b/libs/build.nix @@ -1,6 +1,6 @@ # Foundational .lbf packages # TODO(bladyjoker): Make packages that actually try and compile. -_: +{ inputs, ... }: { perSystem = { pkgs, config, ... }: { @@ -57,6 +57,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 + lbt-plutus-haskell.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 + lbt-plutus-haskell.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; + }; }; }