git.iko.soy/rowtype-yoga/purescript-protobuf
on wip4.6.0 help sign in
176 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.writeScriptBin "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.writeScriptBin "conformance-purescript" ''
70 #!/usr/bin/env bash
71 ${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();"
72 '';
73 }
74 )
75 ];
76 });
78 in {
79 overlays = {
80 };
82 packages = forAllSystems (system:
83 let pkgs = nixpkgsFor.${system}; in {
84 protoc-gen-purescript = pkgs.protoc-gen-purescript;
85 conformance-purescript = pkgs.conformance-purescript;
86 protobuf_v3_9_2 = pkgs.protobuf_v3_9_2;
87 protobuf_v3_14_0 = pkgs.protobuf_v3_14_0;
88 protobuf_v3_15_8 = pkgs.protobuf_v3_15_8;
89 protobuf_v3_20_1 = pkgs.protobuf_v3_20_1;
90 protobuf_v3_21_0 = pkgs.protobuf_v3_21_0;
91 protobuf_v21_10 = pkgs.protobuf_v21_10;
92 protobuf_v23_2 = pkgs.protobuf_v23_2;
93 protobuf_v24_4 = pkgs.protobuf_v24_4;
94 protobuf_v28_2 = pkgs.protobuf_v28_2;
95 protobuf_local = pkgs.protobuf_local;
96 });
98 devShells = forAllSystems (system:
99 let pkgs = nixpkgsFor.${system}; in {
100 default = pkgs.mkShell {
101 name = "purescript-protobuf-devshell";
102 inputsFrom = builtins.attrValues self.packages.${system};
103 buildInputs = with pkgs; [
104 purs
105 spago-unstable
106 purs-tidy-bin.purs-tidy-0_10_0
107 purs-backend-es
108 purescript-language-server
109 nodejs
110 # If MacOS then we use the protobuf from nixpkgs.
111 # Else we use our own protobuf.
112 (if stdenv.isDarwin then protobuf else protobuf_local)
113 esbuild
114 protoc-gen-purescript
115 ];
117 # spago sources not working for whole project, TODO something like:
118 # export PURS_IDE_SOURCES=$(cd plugin;spago sources)
119 shellHook = ''
120 source <(spago --bash-completion-script `which spago`)
121 source <(node --completion-bash)
122 echo "PureScript Protobuf development environment"
123 protoc --version
124 echo -n "node "
125 node --version
126 echo -n "purs "
127 purs --version
128 echo -n "spago "
129 spago --version
130 echo ""
131 echo "To build the protoc compiler plugin, run:"
132 echo ""
133 echo " cd plugin; spago build"
134 echo ""
135 echo "To compile PureScript .purs files from .proto files, run for example:"
136 echo ""
137 echo " protoc --purescript_out=. google/protobuf/timestamp.proto"
138 echo ""'';
139 };
140 });
143 apps = forAllSystems (system:
144 let pkgs = nixpkgsFor.${system}; in {
145 protoc = {
146 type = "app";
147 program = "${pkgs.protobuf_local}/bin/protoc";
148 };
149 protoc-gen-purescript = {
150 type = "app";
151 program = "${pkgs.protoc-gen-purescript}/bin/protoc-gen-purescript";
152 };
153 conformance_test_runner = {
154 type = "app";
155 program = "${pkgs.protobuf_local}/bin/conformance_test_runner";
156 };
157 conformance-purescript = {
158 type = "app";
159 program = "${pkgs.conformance-purescript}/bin/conformance-purescript";
160 };
161 conformance =
162 let
163 conformance-run = pkgs.writeScriptBin "conformance" ''
164 set -e
165 set -x
166 ${pkgs.protobuf_local}/bin/conformance_test_runner --enforce_recommended ${pkgs.conformance-purescript}/bin/conformance-purescript
167 '';
168 in
169 {
170 type = "app";
171 program = "${conformance-run}/bin/conformance";
172 };
173 }
174 );
175 };