Skip to content

Commit 4de3fb5

Browse files
add spago completions, fix spago bundle name (#129)
1 parent 6ce382c commit 4de3fb5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

manifests/build-support/mkDerivation.nix

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
darwin,
1414
nodePackages,
1515
buildNpmPackage,
16+
installShellFiles,
17+
makeWrapper,
1618
}:
1719
version: source:
1820
let
@@ -29,6 +31,7 @@ let
2931
# build issues with Node 22+. Spago 0.93.45+ works with the standard nodejs.
3032
# See: https://github.com/purescript/registry-dev/blob/87c5900ff6fb7090cf2b085b7eb3f75371560522/nix/overlay.nix#L152
3133
isLegacySpago = isSpago && builtins.compareVersions version "0.93.45" < 0;
34+
3235
in
3336
# Simple tarball without dependencies - just extract and link
3437
if isSimpleTarball then
@@ -74,6 +77,8 @@ else
7477
spagoNativeBuildInputs = [
7578
nodePackages.node-gyp
7679
python3
80+
makeWrapper
81+
installShellFiles
7782
]
7883
++ lib.optionals stdenv.isDarwin [ darwin.cctools ];
7984
in
@@ -101,5 +106,21 @@ else
101106
"--omit=optional"
102107
];
103108

109+
# For spago: Replace the symlink with a wrapper that invokes node directly
110+
# with the script renamed via a symlink. This fixes spago displaying
111+
# "Usage: bundle.js" instead of "Usage: spago" (Node.js uses the script
112+
# path for the program name). Also generate shell completions.
113+
postInstall = lib.optionalString isSpago ''
114+
rm $out/bin/${name}
115+
ln -s $out/lib/node_modules/${name}/${js} $out/lib/node_modules/${name}/bin/${name}
116+
makeWrapper ${selectedNodejs}/bin/node $out/bin/${name} \
117+
--add-flags $out/lib/node_modules/${name}/bin/${name}
118+
119+
installShellCompletion --cmd ${name} \
120+
--bash <($out/bin/${name} --bash-completion-script $out/bin/${name}) \
121+
--zsh <($out/bin/${name} --zsh-completion-script $out/bin/${name}) \
122+
--fish <($out/bin/${name} --fish-completion-script $out/bin/${name})
123+
'';
124+
104125
meta = commonMeta;
105126
}

0 commit comments

Comments
 (0)