-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrates Purescript prelude stack to flake-parts
- Loading branch information
1 parent
4acc0a0
commit 5e5c9d0
Showing
20 changed files
with
294 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# TODO(bladyjoker): Using overlayAttrs here as a hack to share functions -.- Do this properly. | ||
{ inputs, ... }: { | ||
imports = [ | ||
inputs.flake-parts.flakeModules.easyOverlay # Adds perSystem.overlayAttrs | ||
]; | ||
perSystem = { pkgs, config, ... }: | ||
{ | ||
|
||
overlayAttrs = { | ||
extras = { | ||
purescriptFlake = import ./flake-purescript.nix pkgs; | ||
haskellData = import ./haskell-data.nix pkgs; | ||
}; | ||
}; | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Build .lbf schemas that use LB Plutus (and by extension LB Prelude) package and targets Purescript's CTL library. | ||
pkgs: lbf: lbg-purescript: lbfPurescriptOpts: | ||
let | ||
utils = import ./utils.nix pkgs; | ||
|
||
lbfPurs = import ./lbf-prelude-purescript.nix pkgs lbf lbg-purescript; | ||
lbfPurescriptOptsForPlutus = utils.overrideAttrs | ||
{ | ||
imports = { | ||
default = [ ]; | ||
override = libs: libs ++ [ ../../libs/lbf-plutus ]; | ||
}; | ||
dependencies = { | ||
default = [ ]; | ||
override = deps: deps ++ [ "lbf-plutus" ]; | ||
}; | ||
classes = { | ||
default = [ ]; | ||
override = cls: cls ++ [ "Plutus.V1.PlutusData" ]; | ||
}; | ||
configs = { | ||
default = [ ]; | ||
override = cfgs: cfgs ++ [ ../../lambda-buffers-codegen/data/purescript-plutus-ctl.json ]; | ||
}; | ||
} | ||
lbfPurescriptOpts; | ||
in | ||
lbfPurs lbfPurescriptOptsForPlutus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Build .lbf schemas that use LB Prelude package and targets Purescript's prelude (and friends) library. | ||
pkgs: lbf: lbg-purescript: lbfPurescriptOpts: | ||
let | ||
utils = import ./utils.nix pkgs; | ||
|
||
lbfPurs = import ./lbf-purescript.nix pkgs lbf lbg-purescript; | ||
lbfPurescriptOptsForPrelude = utils.overrideAttrs | ||
{ | ||
imports = { | ||
default = [ ]; | ||
override = libs: libs ++ [ ../../libs/lbf-prelude ]; | ||
}; | ||
dependencies = { | ||
default = [ ]; | ||
override = deps: deps ++ [ "lbf-prelude" ]; | ||
}; | ||
classes = { | ||
default = [ ]; | ||
override = cls: cls ++ [ "Prelude.Eq" "Prelude.Json" ]; | ||
}; | ||
configs = { | ||
default = [ ]; | ||
override = cfgs: cfgs ++ [ ../../lambda-buffers-codegen/data/purescript-prelude-base.json ]; | ||
}; | ||
} | ||
lbfPurescriptOpts; | ||
|
||
in | ||
lbfPurs lbfPurescriptOptsForPrelude |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,84 @@ | ||
# Base API for constructing Purescript packages given .lbf schemas | ||
|
||
# Nixpkgs | ||
pkgs: | ||
# LambdaBuffers Frontend | ||
lbf: | ||
# LambdaBuffers Purescript Codegen | ||
lbg-purescript: | ||
{ | ||
# Nixpkgs | ||
pkgs | ||
, # Source that is passed to `lbf` as the `--import-path` flag and used to find `files`. | ||
# Examples: src = ./api | ||
src | ||
, # Additional sources that are passed to `lbf` as the `--import-path` flag. | ||
# Examples: imports = [ lbf-prelude ] | ||
imports ? [ ] | ||
, # .lbf files in `src` to compile and codegen. | ||
# Examples: files = [ "Foo.lbf" "Foo/Bar.lbf" ] | ||
files | ||
# Classes for which to generate implementations for. | ||
, classes ? [ "Prelude.Eq" "Prelude.Json" ] | ||
, # TODO(bladyjoker): Dependencies to include in the `build` output | ||
# examples: dependencies = [ "lbf-prelude" "lbr-prelude" ] | ||
dependencies ? [ ] | ||
, # Package name. | ||
# Examples: name = "lbf-myproject" | ||
name | ||
, # Package version. | ||
# Examples: version = "0.1.0.0" | ||
version ? "0.1.0.0" | ||
}: | ||
let | ||
utils = import ./utils.nix pkgs; | ||
in | ||
pkgs.stdenv.mkDerivation { | ||
inherit src version; | ||
pname = name; | ||
outputs = [ "out" "build" ]; | ||
buildInputs = [ | ||
pkgs.cabal-install | ||
lbf | ||
pkgs.jq | ||
]; | ||
buildPhase = '' | ||
mkdir autogen | ||
mkdir .work | ||
lbf build ${utils.mkFlags "import-path" imports} ${utils.mkFlags "gen-class" classes} \ | ||
--work-dir .work \ | ||
--gen ${lbg-purescript}/bin/lbg-purescript \ | ||
--gen-dir autogen \ | ||
${builtins.concatStringsSep " " files} | ||
|
||
cat autogen/build.json | ||
''; | ||
lbfPurescriptOpts = | ||
{ | ||
# Source that is passed to `lbf` as the `--import-path` flag and used to find `files`. | ||
# Examples: src = ./api | ||
src | ||
, # Additional sources that are passed to `lbf` as the `--import-path` flag. | ||
# Examples: imports = [ lbf-prelude ] | ||
imports ? [ ] | ||
, # .lbf files in `src` to compile and codegen. | ||
# Examples: files = [ "Foo.lbf" "Foo/Bar.lbf" ] | ||
files | ||
# Classes for which to generate implementations for (default lbf-prelude classes). | ||
, classes ? [ ] | ||
, # Dependencies to include in the Cabal's `build-depends` stanza. | ||
# examples: dependencies = [ "lbf-prelude" ] | ||
dependencies ? [ ] | ||
, configs ? [ ] | ||
, # Name of the package and also the name of the Cabal package. | ||
# Examples: name = "lbf-myproject" | ||
name | ||
, # Version of the package and also the version of the Cabal package. | ||
# Examples: version = "0.1.0.0" | ||
version ? "0.1.0.0" | ||
}: { inherit src imports files classes dependencies configs name version; }; | ||
|
||
lbf-build = import ./lbf-build.nix pkgs lbf; | ||
|
||
lbfBuild = opts: with (lbfPurescriptOpts opts); | ||
lbf-build.build | ||
{ | ||
inherit src; | ||
opts = { | ||
inherit files; | ||
import-paths = imports; | ||
gen = "${lbg-purescript}/bin/lbg-purescript"; | ||
gen-classes = classes; | ||
gen-dir = "autogen"; | ||
gen-opts = builtins.map (c: "--config=${c}") configs; # WARN(bladyjoker): If I put quotes here everything breaks. | ||
work-dir = ".work"; | ||
}; | ||
}; | ||
|
||
installPhase = '' | ||
mkdir -p $out/src; | ||
cp -r autogen/* $out/src | ||
mv autogen/build.json $build; | ||
''; | ||
} | ||
build = opts: with (lbfPurescriptOpts opts); | ||
let | ||
lbfBuilt = lbfBuild opts; | ||
in | ||
pkgs.stdenv.mkDerivation { | ||
inherit src version; | ||
pname = name; | ||
outputs = [ "out" "buildjson" ]; | ||
buildInputs = [ | ||
pkgs.cabal-install | ||
pkgs.jq | ||
]; | ||
buildPhase = '' | ||
ln -s ${lbfBuilt} autogen; | ||
ln -s ${lbfBuilt.workdir} .work-dir; | ||
ln -s ${lbfBuilt.buildjson} build.json; | ||
''; | ||
|
||
installPhase = '' | ||
cp build.json $buildjson; | ||
echo "Dependencies collected" | ||
cat $buildjson; | ||
mkdir -p $out/src; | ||
cp -r autogen/* $out/src | ||
echo "Files generated" | ||
find $out/; | ||
''; | ||
}; | ||
in | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.