-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathflake.nix
166 lines (155 loc) · 5.96 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
{
description = "PureScript Protobuf";
inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixos-24.05;
flake-utils = {
url = "github:numtide/flake-utils";
};
purescript-overlay = {
url = "github:thomashoneyman/purescript-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
mkSpagoDerivation = {
url = "github:jeslie0/mkSpagoDerivation";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, ... }@inputs:
let
supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
library-src = ./library/src;
nixpkgsFor = forAllSystems (system: import nixpkgs {
inherit system;
config = { };
overlays = builtins.attrValues self.overlays ++ [
inputs.purescript-overlay.overlays.default
inputs.mkSpagoDerivation.overlays.default
(prev: final: import ./nix/protobuf.nix final)
(prev: final: {
purescript-protobuf-library = prev.mkSpagoDerivation {
name = "purescript-protobuf-library";
src = ./library;
nativeBuildInputs = with prev; [ purs spago-unstable ];
buildPhase = "spago build";
installPhase = "mkdir $out; cp -r output/* $out/";
};
})
(prev: final: {
purescript-protobuf-plugin = prev.mkSpagoDerivation {
name = "purescript-protobuf-plugin";
src = ./plugin;
nativeBuildInputs = with prev; [ purs spago-unstable purs-backend-es esbuild];
buildPhase = ''
spago build --purs-args '${prev.purescript-protobuf-library.src}/src/**/*.purs'
'';
installPhase = "mkdir $out; cp -r output/* $out/";
};
})
(prev: final: {
purescript-protobuf-conformance = prev.mkSpagoDerivation {
name = "purescript-protobuf-conformance";
src = ./conformance;
nativeBuildInputs = with prev; [ purs spago-unstable purs-backend-es esbuild];
buildPhase = ''
spago build --purs-args '${prev.purescript-protobuf-library.src}/src/**/*.purs'
'';
installPhase = "mkdir $out; cp -r output/* $out/";
};
})
(prev: final: {
protoc-gen-purescript = prev.writeScriptBin "protoc-gen-purescript" ''
${prev.nodejs}/bin/node --input-type=module -e "import {main} from '${final.purescript-protobuf-plugin}/Main/index.js'; main();"
'';
conformance-purescript = prev.writeScriptBin "conformance-purescript" ''
#!/usr/bin/env bash
${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();"
'';
}
)
];
});
in {
overlays = {
};
packages = forAllSystems (system:
let pkgs = nixpkgsFor.${system}; in {
protoc-gen-purescript = pkgs.protoc-gen-purescript;
conformance-purescript = pkgs.conformance-purescript;
protobuf_v28_2 = pkgs.protobuf_v28_2;
protobuf = pkgs.protobuf_v28_2;
});
devShells = forAllSystems (system:
let pkgs = nixpkgsFor.${system}; in {
default = pkgs.mkShell {
name = "purescript-protobuf-devshell";
inputsFrom = builtins.attrValues self.packages.${system};
buildInputs = with pkgs; [
purs
spago-unstable
purs-tidy-bin.purs-tidy-0_10_0
purs-backend-es
purescript-language-server
nodejs
protobuf
esbuild
protoc-gen-purescript
];
# spago sources not working, TODO
shellHook = ''
source <(spago --bash-completion-script `which spago`)
source <(node --completion-bash)
export PURS_IDE_SOURCES=$(spago sources --package protobuf)
echo "PureScript Protobuf development environment"
protoc --version
echo -n "node "
node --version
echo -n "purs "
purs --version
echo -n "spago "
spago --version
echo ""
echo "To build the protoc compiler plugin, run:"
echo ""
echo " cd plugin; spago build"
echo ""
echo "To compile PureScript .purs files from .proto files, run for example:"
echo ""
echo " protoc --purescript_out=. google/protobuf/timestamp.proto"
echo ""'';
};
});
apps = forAllSystems (system:
let pkgs = nixpkgsFor.${system}; in {
protoc = {
type = "app";
program = "${pkgs.protobuf}/bin/protoc";
};
protoc-gen-purescript = {
type = "app";
program = "${pkgs.protoc-gen-purescript}/bin/protoc-gen-purescript";
};
conformance_test_runner = {
type = "app";
program = "${pkgs.protobuf}/bin/conformance_test_runner";
};
conformance-purescript = {
type = "app";
program = "${pkgs.conformance-purescript}/bin/conformance-purescript";
};
conformance =
let
conformance-run = pkgs.writeScriptBin "conformance" ''
set -e
set -x
${pkgs.protobuf}/bin/conformance_test_runner --enforce_recommended ${pkgs.conformance-purescript}/bin/conformance-purescript
'';
in
{
type = "app";
program = "${conformance-run}/bin/conformance";
};
}
);
};
}