-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathflake.nix
More file actions
189 lines (180 loc) · 6.48 KB
/
Copy pathflake.nix
File metadata and controls
189 lines (180 loc) · 6.48 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
{
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: git submodule `typescript-go` commit.
Keep in sync via `_tools/update-flake-vendor-hash.sh`. */
typescript-go-src = {
url = "github:microsoft/typescript-go/acfaa5bcc8631d3c51ad65a8562a656c8d6a4bd5?submodules=1";
flake = false;
};
/* Source of truth: typescript-go's `_submodules/TypeScript` commit.
Keep in sync via `_tools/update-flake-vendor-hash.sh`. */
typescript-src = {
url = "github:microsoft/TypeScript/4d4f005c8541e0255a9d8791205fdce326e462bc";
flake = false;
};
};
outputs =
{
self,
nixpkgs,
nixpkgsUnstable,
typescript-src,
typescript-go-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-go) — `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: ./_tools/update-flake-vendor-hash.sh
Manual: set to lib.fakeHash, build, copy the reported hash.
*/
vendorHash = "sha256-tfmuo2BIN1Z8ArQMfeNdudngclWjWyIa3YtmOqrr3d8=";
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;
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-go"
];
};
patchedTypescriptGo = pkgs.applyPatches {
name = "patched-typescript-go-source";
src = typescript-go-src;
patches = builtins.map (name: ./. + "/_patches/${name}") sortedPatchFiles;
};
src = pkgs.runCommandNoCC "effect-tsgo-source" { } ''
mkdir source
cp -R ${rootSrc}/. source/
chmod -R u+w source
cp -R ${patchedTypescriptGo} source/typescript-go
chmod -R u+w source/typescript-go
mkdir -p source/typescript-go/_submodules
if [ -d source/typescript-go/_submodules/TypeScript ]; then
rmdir source/typescript-go/_submodules/TypeScript
fi
ln -s ${typescript-src} source/typescript-go/_submodules/TypeScript
cp -R source $out
chmod -R a-w $out
'';
buildGoModule = pkgsUnstable.buildGoModule.override { go = pkgsUnstable.go_1_26; };
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-go/internal/diagnostics
go run generate.go -diagnostics ./diagnostics_generated.go -loc ./loc_generated.go -locdir ./loc
)
export GOFLAGS="$_saved_goflags"
'';
subPackages = [ "typescript-go/cmd/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;
}
);
};
}