-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathpackage.nix
More file actions
68 lines (58 loc) · 1.69 KB
/
Copy pathpackage.nix
File metadata and controls
68 lines (58 loc) · 1.69 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
{
lib,
stdenvNoCC,
bun,
versionCheckHook,
# Not in nixpkgs — pass bun2nix.packages.${system}.default from the flake.
bun2nix,
}:
let
packageJson = lib.importJSON ./package.json;
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./package.json
./bun.lock
./src
];
};
in
stdenvNoCC.mkDerivation {
pname = packageJson.name;
inherit (packageJson) version;
inherit src;
nativeBuildInputs = [ bun2nix.hook ];
bunDeps = bun2nix.fetchBunDeps {
bunNix = ./nix/bun.nix;
};
# The published bin is src/index.ts run under bun — no bundle step.
dontUseBunBuild = true;
# Same as the hook's per-platform defaults, plus --production to keep
# devDependencies out of the runtime closure.
bunInstallFlags = [
"--linker=isolated"
"--production"
]
++ lib.optionals stdenvNoCC.hostPlatform.isDarwin [ "--backend=symlink" ];
# postinstall regenerates bun.nix, which is pointless (and fails) in
# the sandbox.
dontRunLifecycleScripts = true;
installPhase = ''
runHook preInstall
mkdir -p $out/share/ax $out/bin
cp -r src node_modules package.json $out/share/ax/
substituteInPlace $out/share/ax/src/index.ts \
--replace-fail "#!/usr/bin/env bun" "#!${bun}/bin/bun"
chmod +x $out/share/ax/src/index.ts
ln -s $out/share/ax/src/index.ts $out/bin/ax
runHook postInstall
'';
doInstallCheck = true;
nativeInstallCheckInputs = [ versionCheckHook ];
meta = {
inherit (packageJson) description homepage;
license = lib.getLicenseFromSpdxId packageJson.license;
mainProgram = builtins.head (builtins.attrNames packageJson.bin);
platforms = import ./nix/systems.nix;
};
}