Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
191 lines (182 loc) · 6.44 KB
/
Copy pathflake.nix
File metadata and controls
191 lines (182 loc) · 6.44 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
{
description = "Self-contained Effect Language Service (TypeScript-Go)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
nixpkgsUnstable.url = "github:NixOS/nixpkgs/nixos-unstable";
/* Source of truth: the next profile in `_packages/tsgo/upstream.json`. */
typescript-src = {
url = "github:microsoft/TypeScript/6161772c1370bdd4a82f808e6823bd755eb1870d";
flake = false;
};
};
outputs =
{
self,
nixpkgs,
nixpkgsUnstable,
typescript-src,
}:
let
lib = nixpkgs.lib;
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
/*
Go module vendor hash for buildGoModule (proxyVendor mode).
proxyVendor is required because this project has deps with
mixed-case module paths (Microsoft/go-winio vs microsoft/
TypeScript/tsc) — `go work vendor` produces different directory
layouts on case-sensitive (Linux) vs case-insensitive (macOS)
filesystems. The download cache uses `!` escaping for uppercase
letters, making it deterministic across both.
Refresh: pnpm exec repoctl flake update
Manual: set to lib.fakeHash, build, copy the reported hash.
*/
vendorHash = "sha256-2Uj8bkfazW5ydzg6yFtkBW/7BneU45RGsQ1D/s4UjcE=";
forAllSystems =
f: lib.genAttrs supportedSystems (system: f system (import nixpkgs { inherit system; }));
in
{
packages = forAllSystems (
system: pkgs:
let
root = toString ./.;
pkgsUnstable = import nixpkgsUnstable { inherit system; };
patchEntries = builtins.readDir ./_patches/typescript;
patchFiles = builtins.filter (
name: patchEntries.${name} == "regular" && lib.hasSuffix ".patch" name
) (builtins.attrNames patchEntries);
sortedPatchFiles = builtins.sort builtins.lessThan patchFiles;
rootSrc = lib.cleanSourceWith {
src = ./.;
filter =
path: type:
let
pathString = toString path;
relPath = if pathString == root then "" else lib.removePrefix "${root}/" pathString;
topLevel = if relPath == "" then "" else builtins.head (lib.splitString "/" relPath);
in
lib.cleanSourceFilter path type
&& !builtins.elem topLevel [
".direnv"
".git"
".repos"
"build"
"built"
"coverage"
"node_modules"
"tmp"
"typescript"
"typescript-go"
];
};
patchedTypeScript = pkgs.applyPatches {
name = "patched-typescript-source";
src = typescript-src;
patches = builtins.map (name: ./. + "/_patches/typescript/${name}") sortedPatchFiles;
nativeBuildInputs = [ pkgs.git ];
# Apply with git, like `repoctl submodules setup`, so both paths agree.
patchPhase = ''
runHook prePatch
for patch in $patches; do
git apply --binary "$patch"
done
runHook postPatch
'';
};
src = pkgs.runCommandNoCC "effect-tsgo-source" { } ''
mkdir source
cp -R ${rootSrc}/. source/
chmod -R u+w source
cp -R ${patchedTypeScript} source/typescript
chmod -R u+w source/typescript
cp -R source $out
chmod -R a-w $out
'';
buildGoModule = pkgsUnstable.buildGoModule.override { go = pkgsUnstable.go_1_27; };
tsgo = buildGoModule {
pname = "effect-tsgo";
version = "0.0.0";
inherit src vendorHash;
proxyVendor = true;
env = {
CGO_ENABLED = "0";
GOWORK = "auto";
};
/* Prevent codegen (preBuild) from leaking into the goModules
derivation — generate.go imports internal/repo which panics
when compiled with -trimpath. */
overrideModAttrs = _: { preBuild = ""; };
preBuild = ''
# Codegen needs repo path detection; temporarily remove -trimpath
_saved_goflags="$GOFLAGS"
export GOFLAGS="''${GOFLAGS//-trimpath/}"
(
cd typescript/tsc/internal/diagnostics
export GOWORK=off
go run generate.go -diagnostics ./diagnostics_generated.go -loc ./loc_generated.go -locdir ./loc \
-locproject ../../../tools/LocProject.json -locsource ./diagnosticMessages.generated.json
)
export GOFLAGS="$_saved_goflags"
'';
subPackages = [ "typescript/tsc/cmd/tsc" ];
postInstall = ''
mv $out/bin/tsc $out/bin/tsgo
'';
ldflags = [
"-s"
"-w"
];
doCheck = false;
};
effectTsgo = pkgs.symlinkJoin {
name = "effect-tsgo";
paths = [ tsgo ];
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
# tsgo shells out to npm for typings acquisition in LSP mode.
wrapProgram $out/bin/tsgo \
--prefix PATH : ${lib.makeBinPath [ pkgs.nodejs ]}
makeWrapper $out/bin/tsgo $out/bin/effect-tsgo \
--add-flags "--lsp --stdio"
'';
meta = {
description = "Self-contained Effect Language Service binary built on TypeScript-Go";
license = lib.licenses.mit;
mainProgram = "effect-tsgo";
platforms = supportedSystems;
};
};
in
{
default = effectTsgo;
effect-tsgo = effectTsgo;
inherit tsgo;
}
);
apps = forAllSystems (
system: _pkgs:
let
package = self.packages.${system}.effect-tsgo;
in
{
default = {
type = "app";
program = "${package}/bin/effect-tsgo";
};
effect-tsgo = {
type = "app";
program = "${package}/bin/effect-tsgo";
};
}
);
checks = forAllSystems (
system: _pkgs: {
inherit (self.packages.${system}) effect-tsgo;
}
);
};
}