git.iko.soy/rowtype-yoga/purescript-protobuf
on v4.5.0 help sign in
173 lines 6.7 kB history raw
1{
2 description = "PureScript Protobuf";
4 # for mkSpagoDerivation
5 nixConfig.sandbox = "relaxed";
7 inputs = {
8 nixpkgs.url = github:NixOS/nixpkgs/nixos-24.05;
9 flake-utils = {
10 url = "github:numtide/flake-utils";
11 };
12 purescript-overlay = {
13 url = "github:thomashoneyman/purescript-overlay";
14 inputs.nixpkgs.follows = "nixpkgs";
15 };
16 mkSpagoDerivation = {
17 url = "github:jeslie0/mkSpagoDerivation";
18 inputs.nixpkgs.follows = "nixpkgs";
19 };
20 };
22 outputs = { self, nixpkgs, ... }@inputs:
23 let
24 supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
26 forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
28 library-src = ./library/src;
30 nixpkgsFor = forAllSystems (system: import nixpkgs {
31 inherit system;
32 config = { };
33 overlays = builtins.attrValues self.overlays ++ [
34 inputs.purescript-overlay.overlays.default
35 inputs.mkSpagoDerivation.overlays.default
36 (prev: final: import ./nix/protobuf.nix final)
37 (prev: final: {
38 purescript-protobuf-library = prev.mkSpagoDerivation {
39 name = "purescript-protobuf-library";
40 src = ./library;
41 nativeBuildInputs = with prev; [ purs spago-unstable ];
42 buildPhase = "spago build";
43 installPhase = "mkdir $out; cp -r output/* $out/";
44 };
45 })
46 (prev: final: {
47 purescript-protobuf-plugin = prev.mkSpagoDerivation {
48 name = "purescript-protobuf-plugin";
49 src = ./plugin;
50 nativeBuildInputs = with prev; [ purs spago-unstable purs-backend-es esbuild];
51 buildPhase = ''
52 spago build --purs-args '${prev.purescript-protobuf-library.src}/src/**/*.purs'
53 '';
54 # The bundled minified output is CommonJS, so we need to change the run script to run node with CommonJS?
55 # spago build --purs-args '${prev.purescript-protobuf-library.src}/**/*.purs'
56 # purs-backend-es bundle-app --no-build --platform node --minify --output-dir output --main ProtocPlugin.Main
57 # spago bundle --offline --pure --platform node --bundle-type app --minify --module ProtocPlugin.Main --purs-args '${prev.purescript-protobuf-library.src}/**/*.purs'
58 installPhase = "mkdir $out; cp -r output/* $out/";
59 };
60 })
61 (prev: final: {
62 purescript-protobuf-conformance = prev.mkSpagoDerivation {
63 name = "purescript-protobuf-conformance";
64 src = ./conformance;
65 nativeBuildInputs = with prev; [ purs spago-unstable purs-backend-es esbuild];
66 buildPhase = ''
67 spago build --purs-args '${prev.purescript-protobuf-library.src}/src/**/*.purs'
68 '';
69 installPhase = "mkdir $out; cp -r output/* $out/";
70 };
71 })
72 (prev: final: {
73 protoc-gen-purescript = prev.writeScriptBin "protoc-gen-purescript" ''
74 ${prev.nodejs}/bin/node --input-type=module -e "import {main} from '${final.purescript-protobuf-plugin}/ProtocPlugin.Main/index.js'; main();"
75 '';
76 conformance-purescript = prev.writeScriptBin "conformance-purescript" ''
77 #!/usr/bin/env bash
78 ${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();"
79 '';
80 }
81 )
82 ];
83 });
85 in {
86 overlays = {
87 };
89 packages = forAllSystems (system:
90 let pkgs = nixpkgsFor.${system}; in {
91 protoc-gen-purescript = pkgs.protoc-gen-purescript;
92 conformance-purescript = pkgs.conformance-purescript;
93 protobuf_v28_2 = pkgs.protobuf_v28_2;
94 protobuf = pkgs.protobuf_v28_2;
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 protobuf
110 esbuild
111 protoc-gen-purescript
112 ];
114 # spago sources not working, TODO
115 shellHook = ''
116 source <(spago --bash-completion-script `which spago`)
117 source <(node --completion-bash)
118 export PURS_IDE_SOURCES=$(spago sources --package protobuf)
119 echo "PureScript Protobuf development environment"
120 protoc --version
121 echo -n "node "
122 node --version
123 echo -n "purs "
124 purs --version
125 echo -n "spago "
126 spago --version
127 echo ""
128 echo "To build the protoc compiler plugin, run:"
129 echo ""
130 echo " cd plugin; spago build"
131 echo ""
132 echo "To compile PureScript .purs files from .proto files, run for example:"
133 echo ""
134 echo " protoc --purescript_out=. google/protobuf/timestamp.proto"
135 echo ""'';
136 };
137 });
140 apps = forAllSystems (system:
141 let pkgs = nixpkgsFor.${system}; in {
142 protoc = {
143 type = "app";
144 program = "${pkgs.protobuf}/bin/protoc";
145 };
146 protoc-gen-purescript = {
147 type = "app";
148 program = "${pkgs.protoc-gen-purescript}/bin/protoc-gen-purescript";
149 };
150 conformance_test_runner = {
151 type = "app";
152 program = "${pkgs.protobuf}/bin/conformance_test_runner";
153 };
154 conformance-purescript = {
155 type = "app";
156 program = "${pkgs.conformance-purescript}/bin/conformance-purescript";
157 };
158 conformance =
159 let
160 conformance-run = pkgs.writeScriptBin "conformance" ''
161 set -e
162 set -x
163 ${pkgs.protobuf}/bin/conformance_test_runner --enforce_recommended ${pkgs.conformance-purescript}/bin/conformance-purescript
164 '';
165 in
166 {
167 type = "app";
168 program = "${conformance-run}/bin/conformance";
169 };
170 }
171 );
172 };