git.iko.soy/rowtype-yoga/purescript-protobuf
on master help sign in
175 lines 6.7 kB history raw
1{
2 description = "PureScript Protobuf";
4 inputs = {
5 nixpkgs.url = github:NixOS/nixpkgs/nixos-24.11;
6 flake-utils = {
7 url = "github:numtide/flake-utils";
8 };
9 purescript-overlay = {
10 url = "github:thomashoneyman/purescript-overlay";
11 inputs.nixpkgs.follows = "nixpkgs";
12 };
13 mkSpagoDerivation = {
14 url = "github:jeslie0/mkSpagoDerivation";
15 inputs.nixpkgs.follows = "nixpkgs";
16 };
17 };
19 outputs = { self, nixpkgs, ... }@inputs:
20 let
21 supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
23 forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
25 library-src = ./library/src;
27 nixpkgsFor = forAllSystems (system: import nixpkgs {
28 inherit system;
29 config = { };
30 overlays = builtins.attrValues self.overlays ++ [
31 inputs.purescript-overlay.overlays.default
32 inputs.mkSpagoDerivation.overlays.default
33 (prev: final: import ./nix/protobuf.nix final)
34 (prev: final: {
35 purescript-protobuf-library = prev.mkSpagoDerivation {
36 name = "purescript-protobuf-library";
37 src = ./library;
38 nativeBuildInputs = with prev; [ purs spago-unstable ];
39 buildPhase = "spago build";
40 installPhase = "mkdir $out; cp -r output/* $out/";
41 };
42 })
43 (prev: final: {
44 purescript-protobuf-plugin = prev.mkSpagoDerivation {
45 name = "purescript-protobuf-plugin";
46 src = ./plugin;
47 nativeBuildInputs = with prev; [ purs spago-unstable purs-backend-es esbuild];
48 buildPhase = ''
49 spago build --purs-args '${prev.purescript-protobuf-library.src}/src/**/*.purs'
50 '';
51 installPhase = "mkdir $out; cp -r output/* $out/";
52 };
53 })
54 (prev: final: {
55 purescript-protobuf-conformance = prev.mkSpagoDerivation {
56 name = "purescript-protobuf-conformance";
57 src = ./conformance;
58 nativeBuildInputs = with prev; [ purs spago-unstable purs-backend-es esbuild];
59 buildPhase = ''
60 spago build --purs-args '${prev.purescript-protobuf-library.src}/src/**/*.purs'
61 '';
62 installPhase = "mkdir $out; cp -r output/* $out/";
63 };
64 })
65 (prev: final: {
66 protoc-gen-purescript = prev.writeShellScriptBin "protoc-gen-purescript" ''
67 ${prev.nodejs}/bin/node --input-type=module -e "import {main} from '${final.purescript-protobuf-plugin}/Main/index.js'; main();"
68 '';
69 conformance-purescript = prev.writeShellScriptBin "conformance-purescript" ''
70 ${prev.nodejs}/bin/node --abort-on-uncaught-exception --trace-sigint --trace-uncaught --input-type=module -e "import {main} from '${final.purescript-protobuf-conformance}/Main/index.js'; main();"
71 '';
72 }
73 )
74 ];
75 });
77 in {
78 overlays = {
79 };
81 packages = forAllSystems (system:
82 let pkgs = nixpkgsFor.${system}; in {
83 protoc-gen-purescript = pkgs.protoc-gen-purescript;
84 conformance-purescript = pkgs.conformance-purescript;
85 protobuf_v3_9_2 = pkgs.protobuf_v3_9_2;
86 protobuf_v3_14_0 = pkgs.protobuf_v3_14_0;
87 protobuf_v3_15_8 = pkgs.protobuf_v3_15_8;
88 protobuf_v3_20_1 = pkgs.protobuf_v3_20_1;
89 protobuf_v3_21_0 = pkgs.protobuf_v3_21_0;
90 protobuf_v21_10 = pkgs.protobuf_v21_10;
91 protobuf_v23_2 = pkgs.protobuf_v23_2;
92 protobuf_v24_4 = pkgs.protobuf_v24_4;
93 protobuf_v28_2 = pkgs.protobuf_v28_2;
94 protobuf_local = pkgs.protobuf_local;
95 });
97 devShells = forAllSystems (system:
98 let pkgs = nixpkgsFor.${system}; in {
99 default = pkgs.mkShell {
100 name = "purescript-protobuf-devshell";
101 # inputsFrom = builtins.attrValues self.packages.${system};
102 buildInputs = with pkgs; [
103 purs
104 spago-unstable
105 purs-tidy-bin.purs-tidy-0_10_0
106 purs-backend-es
107 purescript-language-server
108 nodejs
109 # If MacOS then we use the protobuf from nixpkgs.
110 # Else we use our own protobuf.
111 (if stdenv.isDarwin then protobuf else protobuf_local)
112 esbuild
113 protoc-gen-purescript
114 ];
116 # spago sources not working for whole project, TODO something like:
117 # export PURS_IDE_SOURCES=$(cd plugin;spago sources)
118 shellHook = ''
119 source <(spago --bash-completion-script `which spago`)
120 source <(node --completion-bash)
121 echo "PureScript Protobuf development environment"
122 protoc --version
123 echo -n "node "
124 node --version
125 echo -n "purs "
126 purs --version
127 echo -n "spago "
128 spago --version
129 echo ""
130 echo "To build the protoc compiler plugin, run:"
131 echo ""
132 echo " cd plugin; spago build"
133 echo ""
134 echo "To compile PureScript .purs files from .proto files, run for example:"
135 echo ""
136 echo " protoc --purescript_out=. google/protobuf/timestamp.proto"
137 echo ""'';
138 };
139 });
142 apps = forAllSystems (system:
143 let pkgs = nixpkgsFor.${system}; in {
144 protoc = {
145 type = "app";
146 program = "${pkgs.protobuf_local}/bin/protoc";
147 };
148 protoc-gen-purescript = {
149 type = "app";
150 program = "${pkgs.protoc-gen-purescript}/bin/protoc-gen-purescript";
151 };
152 conformance_test_runner = {
153 type = "app";
154 program = "${pkgs.protobuf_local}/bin/conformance_test_runner";
155 };
156 conformance-purescript = {
157 type = "app";
158 program = "${pkgs.conformance-purescript}/bin/conformance-purescript";
159 };
160 conformance =
161 let
162 conformance-run = pkgs.writeShellScriptBin "conformance" ''
163 set -e
164 set -x
165 ${pkgs.protobuf_local}/bin/conformance_test_runner --enforce_recommended ${pkgs.conformance-purescript}/bin/conformance-purescript
166 '';
167 in
168 {
169 type = "app";
170 program = "${conformance-run}/bin/conformance";
171 };
172 }
173 );
174 };