vimPlugins.peek-nvim: build JS#403252
Conversation
|
Looking upstream, it seems the package is described by "imports": {
"node:punycode": "https://deno.land/x/punycode/punycode.js"
},Elsewhere in deno's docs, it is mentioned that dependency locks are configured by the I was hoping something relevant would be in https://nixos.org/manual/nixpkgs/unstable/#language-javascript, however I can't see any mention of Searching nixpkgs's github for EDIT: another related PR: #358252 |
|
Looks like in addition to needing deno at compile time, it is also needs to be on the PATH at runtime... Upstream runs its binary using deno too: https://github.com/toppair/peek.nvim/blob/5820d937d5414baea5f586dc2a3d912a74636e5b/lua/peek/app.lua#L40-L45 cmd = vim.list_extend({
'deno',
'task',
'--quiet',
'run',
}, args)However it still needs to have been built; even if If |
|
@GaetanLepage I've made some progress on this; it's a little ugly, but we can patch how the plugin runs its This probably isn't the correct approach, but it's hard to avoid patching when the plugin is hard-coded to run it's exe via deno in a very specific way 😕 Diff
diff --git a/pkgs/applications/editors/vim/plugins/overrides.nix b/pkgs/applications/editors/vim/plugins/overrides.nix
index 72db22346c62..8a87296b70e8 100644
--- a/pkgs/applications/editors/vim/plugins/overrides.nix
+++ b/pkgs/applications/editors/vim/plugins/overrides.nix
@@ -9,6 +9,7 @@
fetchpatch,
fetchurl,
neovimUtils,
+ wrapNeovimUnstable,
replaceVars,
symlinkJoin,
# Language dependencies
@@ -2744,17 +2745,28 @@ in
];
};
- peek-nvim = super.peek-nvim.overrideAttrs {
- nativeBuildInputs = [ deno ];
+ peek-nvim = super.peek-nvim.overrideAttrs (old: {
- buildPhase = ''
- runHook preBuild
-
- deno task --quiet build:fast
+ # Patch peek-nvim to run using nixpkgs deno
+ # This means end-users have to build peek-nvim the first time they use it...
+ patches = [
+ (replaceVars ./patches/peek-nvim/cmd.patch {
+ DENO = lib.getExe deno;
+ })
+ ];
- runHook postBuild
- '';
- };
+ passthru = old.passthru // {
+ example = wrapNeovimUnstable neovim-unwrapped {
+ plugins = [ self.peek-nvim ];
+ luaRcContent = ''
+ require("peek").setup({})
+ vim.api.nvim_create_user_command("PeekOpen", require("peek").open, {})
+ vim.api.nvim_create_user_command("PeekClose", require("peek").close, {})
+ '';
+ # wrapperArgs = "--prefix PATH : ${lib.makeBinPath [ deno ]}";
+ };
+ };
+ });
persisted-nvim = super.persisted-nvim.overrideAttrs {
nvimSkipModules = [
diff --git a/pkgs/applications/editors/vim/plugins/patches/peek-nvim/cmd.patch b/pkgs/applications/editors/vim/plugins/patches/peek-nvim/cmd.patch
new file mode 100644
index 000000000000..1fd0a6c39b0b
--- /dev/null
+++ b/pkgs/applications/editors/vim/plugins/patches/peek-nvim/cmd.patch
@@ -0,0 +1,38 @@
+diff --git a/app/src/main.ts b/app/src/main.ts
+index c82d914..e8542f3 100644
+--- a/app/src/main.ts
++++ b/app/src/main.ts
+@@ -73,7 +73,7 @@ async function init(socket: WebSocket) {
+ const onListen: Deno.ServeOptions['onListen'] = ({ hostname, port }) => {
+ const serverUrl = `${hostname.replace('0.0.0.0', 'localhost')}:${port}`;
+ logger.info(`listening on ${serverUrl}`);
+- const webview = new Deno.Command('deno', {
++ const webview = new Deno.Command('@DENO@', {
+ cwd: dirname(fromFileUrl(Deno.mainModule)),
+ args: [
+ 'run',
+diff --git a/lua/peek/app.lua b/lua/peek/app.lua
+index af5148e..5e67563 100644
+--- a/lua/peek/app.lua
++++ b/lua/peek/app.lua
+@@ -38,10 +38,17 @@ function module.setup()
+ end
+
+ cmd = vim.list_extend({
+- 'deno',
+- 'task',
+- '--quiet',
++ '@DENO@',
+ 'run',
++ '--allow-read',
++ '--allow-write',
++ '--allow-net',
++ '--allow-env',
++ '--allow-run',
++ '--no-check',
++ '--allow-import',
++ '--no-lock',
++ '../../app/src/main.ts',
+ }, args)
+ end
+
This skips the build step entirely, instead running from source and downloading deps at runtime. This isn't ideal, but should at least work until we have a sane way to build it in nixpkgs 😕 |
|
Thanks a lot @MattSturgeon! I included your latest patch and put you as a co-author. |
|
05c01de to
7e75da2
Compare
MattSturgeon
left a comment
There was a problem hiding this comment.
Need to check this actually works in practice, but the diff looks good.
Co-authored-by: Matt Sturgeon <matt@sturgeon.me.uk>
|
I can't get this to work with my neovim setup. I call https://docs.deno.com/api/deno/~/Deno.mainModule The server cannot locate the const webview = new Deno.Command('deno', {
cwd: dirname(fromFileUrl(Deno.mainModule)),
args: [
'run',
'--quiet',
'--allow-read',
'--allow-write',
'--allow-env',
'--allow-net',
'--allow-ffi',
'--unstable',
'--no-check',
'webview.js',
`--url=${new URL('index.html', Deno.mainModule).href}`,
`--theme=${__args['theme']}`,
`--serverUrl=${serverUrl}`,
],
stdin: 'null',
}); async function findFile(url: string) {
const path = new URL(url).pathname.replace(/^\//, '') || 'index.html';
for (const base of [Deno.mainModule, 'file:']) {
const openUrl = new URL(path, base)
try {
return await Deno.open(openUrl);
} catch (_) { /**/ }
}
}But beyond that issue, I don't get how this is going to work because the build step is still missing? |
Thanks for testing!
Am I understanding that the only issue is the URL is relative to I would've expected the index.html file to be in
Is building actually necessary? Does it do anything beyond converting the typescript to javascript? I don't see how we'll get a solution for building without something like #358252. I guess, as it's only one dependency, we could fetch that dependency manually and trick Personally, I'm unfamiliar with this plugin, and deno more generally. |
|
The build step (done by |
Things done
Currently, using
peek.nvimfails with:We should be building the JS in the
buildPhase.Upstream explains that it should be:
but this requires internet access.
So instead, we should fetch the dependencies before hand.
I am not sure about how to do that though.
cc @MattSturgeon @Lurgrif
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.