Skip to content

Commit 6f2a01e

Browse files
committed
Move the compiler/codegen/frontend to flake parts
1 parent 7b93d25 commit 6f2a01e

File tree

9 files changed

+356
-359
lines changed

9 files changed

+356
-359
lines changed

api/.envrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
use flake ..#dev-protos
1+
use flake ..#dev-api

api/build.nix

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,62 @@
1-
{ pkgs, pbnix-lib, commonTools, shellHook }:
2-
rec {
3-
devShell = pkgs.mkShell {
4-
name = "protos-env";
5-
buildInputs = [
6-
pkgs.protobuf
7-
pkgs.haskellPackages.proto-lens-protoc
8-
pkgs.protoc-gen-doc
9-
] ++ builtins.attrValues commonTools;
1+
self@{ inputs, ... }:
2+
{
3+
perSystem = { pkgs, system, config, ... }:
4+
let
5+
pbnix-lib = inputs.protobufs-nix.lib.${system};
6+
in
7+
rec {
108

11-
inherit shellHook;
12-
};
9+
devShells.dev-api = pkgs.mkShell {
10+
name = "protos-env";
11+
buildInputs = [
12+
pkgs.protobuf
13+
pkgs.haskellPackages.proto-lens-protoc
14+
pkgs.protoc-gen-doc
15+
]; # ++ builtins.attrValues commonTools;
1316

14-
packages = {
15-
lambda-buffers-lang-hs-pb = pbnix-lib.haskellProto {
16-
inherit pkgs;
17-
src = ./.;
18-
proto = "lang.proto";
19-
cabalPackageName = "lambda-buffers-lang-pb";
20-
};
17+
shellHookd = ''
18+
export LC_CTYPE=C.UTF-8;
19+
export LC_ALL=C.UTF-8;
20+
export LANG=C.UTF-8;
21+
${config.pre-commit.installationScript}
22+
'';
23+
};
2124

22-
lambda-buffers-compiler-hs-pb = pbnix-lib.haskellProto {
23-
inherit pkgs;
24-
src = ./.;
25-
proto = "compiler.proto";
26-
cabalBuildDepends = [ packages.lambda-buffers-lang-hs-pb ];
27-
cabalPackageName = "lambda-buffers-compiler-pb";
28-
};
25+
packages = {
26+
lambda-buffers-lang-hs-pb = pbnix-lib.haskellProto {
27+
inherit pkgs;
28+
src = ./.;
29+
proto = "lang.proto";
30+
cabalPackageName = "lambda-buffers-lang-pb";
31+
};
2932

30-
lambda-buffers-codegen-hs-pb = pbnix-lib.haskellProto {
31-
inherit pkgs;
32-
src = ./.;
33-
proto = "codegen.proto";
34-
cabalBuildDepends = [ packages.lambda-buffers-lang-hs-pb ];
35-
cabalPackageName = "lambda-buffers-codegen-pb";
36-
};
33+
lambda-buffers-compiler-hs-pb = pbnix-lib.haskellProto {
34+
inherit pkgs;
35+
src = ./.;
36+
proto = "compiler.proto";
37+
cabalBuildDepends = [ packages.lambda-buffers-lang-hs-pb ];
38+
cabalPackageName = "lambda-buffers-compiler-pb";
39+
};
40+
41+
lambda-buffers-codegen-hs-pb = pbnix-lib.haskellProto {
42+
inherit pkgs;
43+
src = ./.;
44+
proto = "codegen.proto";
45+
cabalBuildDepends = [ packages.lambda-buffers-lang-hs-pb ];
46+
cabalPackageName = "lambda-buffers-codegen-pb";
47+
};
3748

38-
lambda-buffers-api-docs = pkgs.stdenv.mkDerivation {
39-
src = ./.;
40-
name = "lambdabuffers-api-docs";
41-
buildInputs = [
42-
pkgs.protobuf
43-
];
44-
buildPhase = ''
45-
mkdir $out;
46-
protoc --plugin=${pkgs.protoc-gen-doc}/bin/protoc-gen-doc lang.proto compiler.proto codegen.proto --doc_out=$out --doc_opt=markdown,api.md;
47-
'';
49+
lambda-buffers-api-docs = pkgs.stdenv.mkDerivation {
50+
src = ./.;
51+
name = "lambdabuffers-api-docs";
52+
buildInputs = [
53+
pkgs.protobuf
54+
];
55+
buildPhase = ''
56+
mkdir $out;
57+
protoc --plugin=${pkgs.protoc-gen-doc}/bin/protoc-gen-doc lang.proto compiler.proto codegen.proto --doc_out=$out --doc_opt=markdown,api.md;
58+
'';
59+
};
60+
};
4861
};
49-
};
5062
}

extras/lbf-nix/build.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
overlayAttrs = {
1010
lbf-nix = {
11+
lbfBuild = import ./lbf-build.nix pkgs config.packages.lbf;
1112
lbfHaskell = import ./lbf-haskell.nix pkgs config.packages.lbf config.packages.lbg-haskell;
1213
lbfPreludeHaskell = import ./lbf-prelude-hs.nix pkgs config.packages.lbf config.packages.lbg-haskell;
1314
lbfPlutusHaskell = import ./lbf-plutus-hs-plutustx.nix pkgs config.packages.lbf config.packages.lbg-haskell;

extras/lbf-nix/lbf-build.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ let
7474
'';
7575
};
7676
in
77-
{ inherit buildOpts build; }
77+
{ inherit buildOpts build buildCall; }

flake.nix

Lines changed: 5 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
(import ./extras/build.nix)
2626
(import ./extras/lbf-nix/build.nix)
2727
(import ./libs/build.nix)
28+
(import ./api/build.nix)
29+
(import ./lambda-buffers-compiler/build.nix)
30+
(import ./lambda-buffers-codegen/build.nix)
31+
(import ./lambda-buffers-frontend/build.nix)
2832
(import ./runtimes/haskell/lbr-prelude/build.nix)
2933
(import ./runtimes/haskell/lbr-plutus/build.nix)
3034
(import ./runtimes/purescript/lbr-prelude/build.nix)
@@ -45,8 +49,6 @@
4549
let
4650
inherit self;
4751

48-
haskell-nix = pkgs.haskell-nix;
49-
5052
# pre-commit-hooks.nix
5153

5254
fourmolu = pkgs.haskell.packages.ghc924.fourmolu;
@@ -59,142 +61,7 @@
5961
inherit fourmolu;
6062
inherit apply-refact;
6163
};
62-
63-
shellHook = config.pre-commit.installationScript;
64-
65-
# Protos build
66-
67-
pbnix-lib = protobufs-nix.lib.${system};
68-
69-
protosBuild = import ./api/build.nix {
70-
inherit pkgs pbnix-lib commonTools shellHook;
71-
};
72-
73-
index-state = "2022-12-01T00:00:00Z";
74-
compiler-nix-name = "ghc925";
75-
76-
# Common build abstraction for the components.
77-
78-
buildAbstraction = { import-location, additional ? { } }:
79-
import import-location ({
80-
inherit pkgs compiler-nix-name index-state haskell-nix mlabs-tooling commonTools shellHook;
81-
} // additional);
82-
83-
# Common Flake abstraction for the components.
84-
85-
flakeAbstraction = component-name: component-name.hsNixProj.flake { };
86-
87-
# Compiler Build
88-
89-
compilerBuild = buildAbstraction {
90-
import-location = ./lambda-buffers-compiler/build.nix;
91-
additional = { inherit (protosBuild.packages) lambda-buffers-lang-hs-pb lambda-buffers-compiler-hs-pb lambda-buffers-codegen-hs-pb; };
92-
};
93-
compilerFlake = flakeAbstraction compilerBuild;
94-
95-
# Codegen Build
96-
97-
codegenBuild = buildAbstraction {
98-
import-location = ./lambda-buffers-codegen/build.nix;
99-
additional = {
100-
inherit (protosBuild.packages) lambda-buffers-lang-hs-pb lambda-buffers-compiler-hs-pb lambda-buffers-codegen-hs-pb;
101-
lambda-buffers-compiler = ./lambda-buffers-compiler;
102-
};
103-
};
104-
codegenFlake = flakeAbstraction codegenBuild;
105-
106-
# Frontend Build
107-
108-
frontendBuild = buildAbstraction {
109-
import-location = ./lambda-buffers-frontend/build.nix;
110-
additional = {
111-
inherit (protosBuild.packages) lambda-buffers-lang-hs-pb lambda-buffers-compiler-hs-pb lambda-buffers-codegen-hs-pb;
112-
lambda-buffers-compiler = ./lambda-buffers-compiler;
113-
inherit (clis) lbc lbg lbg-haskell lbg-purescript;
114-
};
115-
};
116-
frontendFlake = flakeAbstraction frontendBuild;
117-
118-
# LambdaBuffers CLIs
119-
120-
clis = rec {
121-
lbf-pure = frontendFlake.packages."lambda-buffers-frontend:exe:lbf";
122-
lbc = compilerFlake.packages."lambda-buffers-compiler:exe:lbc";
123-
lbg = codegenFlake.packages."lambda-buffers-codegen:exe:lbg";
124-
lbg-haskell = pkgs.writeShellScriptBin "lbg-haskell" ''
125-
${lbg}/bin/lbg gen-haskell $@
126-
'';
127-
lbg-purescript = pkgs.writeShellScriptBin "lbg-purescript" ''
128-
${lbg}/bin/lbg gen-purescript $@
129-
'';
130-
lbf = pkgs.writeShellScriptBin "lbf" ''
131-
export LB_CODEGEN=${lbg-haskell}/bin/lbg-haskell;
132-
export LB_COMPILER=${lbc}/bin/lbc;
133-
${lbf-pure}/bin/lbf $@
134-
'';
135-
lbf-to-haskell = pkgs.writeShellScriptBin "lbf-to-haskell" ''
136-
export LB_COMPILER=${lbc}/bin/lbc;
137-
138-
${lbf-pure}/bin/lbf build --gen ${lbg-haskell}/bin/lbg-haskell $@
139-
'';
140-
lbf-to-haskell-prelude = pkgs.writeShellScriptBin "lbf-to-haskell-prelude" ''
141-
export LB_COMPILER=${lbc}/bin/lbc;
142-
143-
${lbf-pure}/bin/lbf build --import-path ${./libs/lbf-prelude} \
144-
--gen-class Prelude.Eq --gen-class Prelude.Json \
145-
--gen ${lbg-haskell}/bin/lbg-haskell $@
146-
'';
147-
lbf-to-purescript = pkgs.writeShellScriptBin "lbf-to-purescript" ''
148-
export LB_COMPILER=${lbc}/bin/lbc;
149-
150-
${lbf-pure}/bin/lbf build --gen ${lbg-purescript}/bin/lbg-purescript $@
151-
'';
152-
lbf-to-purescript-prelude = pkgs.writeShellScriptBin "lbf-to-purescript-prelude" ''
153-
export LB_COMPILER=${lbc}/bin/lbc;
154-
155-
${lbf-pure}/bin/lbf build --import-path ${./libs/lbf-prelude} \
156-
--gen-class Prelude.Eq --gen-class Prelude.Json \
157-
--gen ${lbg-purescript}/bin/lbg-purescript $@
158-
'';
159-
160-
};
161-
162-
# LambdaBuffers environment
163-
164-
lbEnv = pkgs.mkShell {
165-
name = "lambdabuffers-env";
166-
packages = builtins.attrValues clis;
167-
};
168-
169-
# Utilities
170-
renameAttrs = rnFn: pkgs.lib.attrsets.mapAttrs' (n: value: { name = rnFn n; inherit value; });
17164
in
172-
rec
173-
{
174-
# Standard flake attributes
175-
packages = protosBuild.packages
176-
// compilerFlake.packages
177-
// frontendFlake.packages
178-
// codegenFlake.packages
179-
// clis;
180-
181-
devShells = rec {
182-
dev-protos = protosBuild.devShell;
183-
dev-compiler = compilerFlake.devShell;
184-
dev-frontend = frontendFlake.devShell;
185-
dev-codegen = codegenFlake.devShell;
186-
lb = lbEnv;
187-
};
188-
189-
# nix flake check
190-
checks = devShells //
191-
packages //
192-
renameAttrs (n: "check-${n}") (
193-
compilerFlake.checks //
194-
frontendFlake.checks //
195-
codegenFlake.checks
196-
);
197-
198-
};
65+
{ };
19966
};
20067
}

0 commit comments

Comments
 (0)