git.iko.soy/rowtype-yoga/purescript-protobuf
on v2.1.2 help sign in
62 lines 1.7 kB history raw
1# Derivation which provides `protoc-gen-purescript` on the PATH.
2#
3# To try it out, `nix-shell ./nix/demo.nix`, then
4#
5# protoc --purescript_out=path_to_output file.proto
6#
7{ pkgs ? import ./nix/pkgs.nix {} }:
9let
10 node2NixFiles = srcPath:
11 pkgs.stdenv.mkDerivation {
12 name = "node2NixFiles";
13 nativeBuildInputs = with pkgs; [ nodejs node2nix.package ];
14 src = srcPath;
15 unpackPhase = ''
16 cp $src/package.json $src/package-lock.json .
17 '';
18 buildPhase = ''
19 node2nix -l package-lock.json
20 '';
21 installPhase = ''
22 mkdir $out
23 cp node-env.nix node-packages.nix default.nix $out/
24 cp package.json package-lock.json $out/
25 '';
26 };
28 protobufNixNode = import (node2NixFiles ./.) { inherit pkgs; };
29 spagoPkgs = import ./nix/spago-packages.nix { inherit pkgs; };
30in
32pkgs.stdenv.mkDerivation {
33 name = "purescript-protobuf-generator";
34 buildInputs = [
35 spagoPkgs.installSpagoStyle
36 spagoPkgs.buildSpagoStyle
37 ];
38 nativeBuildInputs = with pkgs; [
39 purs
40 easy-ps.spago
41 ];
42 src = ./.;
43 unpackPhase = ''
44 cp $src/spago.dhall .
45 cp $src/packages.dhall .
46 cp -r $src/src .
47 cp -r $src/plugin .
48 cp -r ${protobufNixNode.nodeDependencies}/lib/node_modules .
49 install-spago-style
50 '';
51 buildPhase = ''
52 build-spago-style "./src/**/*.purs" "./plugin/**/*.purs"
53 '';
54 installPhase = ''
55 mkdir -p $out/bin
56 mv output $out/
57 cp -r node_modules $out/
58 echo "node -e \"require('$out/output/ProtocPlugin.Main/index.js').main()\"" >> $out/bin/protoc-gen-purescript
59 chmod +x $out/bin/protoc-gen-purescript
60 '';
61 LC_ALL = "C.UTF-8";