mikesol / wagsi

A 100% browser-based interactive live audio coding environment.
Apache License 2.0
40 stars 3 forks source link

Installation: The prebuilt binary and `stack setup` both fail on NixOS. #8

Open JeffreyBenjaminBrown opened 2 years ago

JeffreyBenjaminBrown commented 2 years ago

I installed PureScript, npm and VSCode via the NixOS repo, and installed a few of the PureScript extensions from within VSCode. Here are the versions of some software on my system:

jeff@jbb-dell:wagsi$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.4
jeff@jbb-dell:wagsi$ stack --version
2.7.1 x86_64 hpack-0.34.4
jeff@jbb-dell:wagsi$ npm --version
6.14.15
jeff@jbb-dell:wagsi$ purs --version
0.14.0
jeff@jbb-dell:wagsi$ git log    # the version of Wagsi I checked out
commit 80932edacacf9d3e1c5012d59e5ebcc7d34288eb (HEAD -> main, origin/main, origin/HEAD)

When I try to open a shell in VSCode I get the error The terminal process failed to launch: Path to shell executable "bash" is not a file or a symlink. (Is anyone using wagsi in Emacs? I'd prefer that to VSCode.) So I ran npm install && npm start from a separate terminal application (Konsole), whereupon I got this:

jeff@jbb-dell:wagsi$ npm install && npm start
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

> purescript@0.14.3 postinstall /home/jeff/code/music/wagsi/node_modules/purescript
> install-purescript --purs-ver=0.14.3

✔ Check if a prebuilt 0.14.3 binary is provided for linux
✔ Download the prebuilt PureScript binary (6s)
✖ Verify the prebuilt binary works correctly
  /home/jeff/code/music/wagsi/node_modules/purescript/purs.bin --version
  Error: spawn /home/jeff/code/music/wagsi/node_modules/purescript/purs.bin ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:467:16)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
▬ Save the downloaded binary to the npm cache directory

↓ Fallback: building from source

✔ Check if 'stack' command is available
        2.7.1 found at /run/current-system/sw/bin/stack
✔ Download the PureScript 0.14.3 source (2s)
✖ Ensure the appropriate GHC is installed (396ms)
  stack setup
  Error: Command failed with exit code 1 (EPERM): stack --allow-different-user setup
    at makeError (/home/jeff/code/music/wagsi/node_modules/execa/lib/error.js:59:11)
    at handlePromise (/home/jeff/code/music/wagsi/node_modules/execa/index.js:112:26)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
▬ Build a binary from source
▬ Save the built binary to the npm cache directory

npm WARN tailwindcss@2.1.2 requires a peer of autoprefixer@^10.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN wagsi@ No repository field.
npm WARN wagsi@ No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! purescript@0.14.3 postinstall: `install-purescript --purs-ver=0.14.3`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the purescript@0.14.3 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/jeff/.npm/_logs/2021-10-09T18_13_51_013Z-debug.log
jeff@jbb-dell:wagsi$
JeffreyBenjaminBrown commented 2 years ago

The line npm ERR! purescript@0.14.3 postinstall:install-purescript --purs-ver=0.14.3` makes it look like npm wants purescript version 0.14.3. Meanwhile wagsi'spackage.jsonappears to want"purescript": "^0.14.2"`. But neither is packaged for NixOS -- 21.05 (the latest stable branch) has 0.14.0, and unstable has 0.14.4.

Should I try to get it (hard), or is is it possible I could just change some dependency specifications to say 0.14.0 and it would work?

mikesol commented 2 years ago

Hi @JeffreyBenjaminBrown ! Sorry I'm late to getting to this - you are the first person to have filed an issue on this repo (congrats! :confetti_ball: ). I'll set up notifications to give more speedy replies and I'll look into this straight away.

JeffreyBenjaminBrown commented 2 years ago

Sweet, thanks Mike!

mikesol commented 2 years ago

Could you try out wagsi using emacs? Theoretically it should work via https://github.com/purescript-emacs/psc-ide-emacs, although I've never tried it. If it works, I'll rewrite the README in a more editor-agnostic way.

The flow should be the same in emacs as in vscode, namely npm install && npm start, then navigating to localhost:8080 and editing the file src/LiveCodeHere/Wagged.purs.

JeffreyBenjaminBrown commented 2 years ago

If I'm unable to run npm install && npm run in Bash, should I have reason to expect it to work in Emacs?

mikesol commented 2 years ago

Could you edit package.json, remove spago & purescript and see if it works? The only issue is that if purs is at 0.14.0 in your nix distro it could have a couple bugs that would prevent compilation, but it's possible that 0.14.0 works out-of-the-box.

Would you be ok using nix-shell if I included a shell.nix file? I can write separate install instructions for that path if it's easier.

JeffreyBenjaminBrown commented 2 years ago

Progress! I installed Spago (via my NixOS config files), removed the two lines you mentioned from package.json, and was able to get this far:


jeff@jbb-dell:wagsi$ npm install && npm run
npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

> wagsi@ postinstall /home/jeff/code/music/wagsi
> spago install && spago build

spago: 
Error: Connection establishment took too long

URL: https://github.com/purescript/package-sets/releases/download/psc-0.14.1-20210419/packages.dhall

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! wagsi@ postinstall: `spago install && spago build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the wagsi@ postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/jeff/.npm/_logs/2021-10-12T16_53_29_807Z-debug.log
jeff@jbb-dell:wagsi$ 

(If this avenue should prove fruitless we can try the nix-shell route next. It'll take some learning from me; I've never done anything interesting in a nix-shell.)

JeffreyBenjaminBrown commented 2 years ago

I see a nixpkgs commit that I can plunder to modify my own nixpkgs fork to bump Purescript to 0.14.3. If you think that's the problem I'm running into now, let me know and I'll do it.

mikesol commented 2 years ago

My nix-foo is at white-belt level, so it's hard for me to know if the bug is coming from the nix setup or spago or something else entirely. My guess would be that the bug here is from spago and not purescript, asspagodeals with package-sets whereaspurescriptdoesn't.spago` is having trouble downloading a package set from GitHub, which may mean that GitHub was down at the moment you were downloading the file? Seems like a long shot, but if you re-run then that can test that hypothesis.

If it keeps stalling there, I can try the nix-shell route: it's what we use for purescript registry development and it has served us well so far.

JeffreyBenjaminBrown commented 2 years ago

I just tried again. I was able to view Github in the browser immediately before and after, and I successfully performed git pull on Wagsi, but I got the same connection timeout error.

JeffreyBenjaminBrown commented 2 years ago

Would it matter that my Spago is at version 0.20.2?

mikesol commented 2 years ago

The spago version shouldn't matter. I just updated the repo with a default.nix file. So, theoretically, the following should work assuming that nix-shell is an available command on your machine (ie your PATH points to some directory where nix-shell lives):

nix-shell
# then once in the shell
npm install && npm start

Lemme know if that works for you!

JeffreyBenjaminBrown commented 2 years ago

Ahh, so close!

Using nix-shell, npm install from Bash seems to have worked, although it skipped some dependencies:

[nix-shell:~/code/music/wagsi]$ npm install
npm WARN tailwindcss@2.1.2 requires a peer of autoprefixer@^10.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN wagsi@ No repository field.
npm WARN wagsi@ No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

audited 1029 packages in 4.635s

65 packages are looking for funding
  run `npm fund` for details

found 64 vulnerabilities (45 moderate, 16 high, 3 critical)
  run `npm audit fix` to fix them, or `npm audit` for details

[nix-shell:~/code/music/wagsi]$

And I seem to have successfully installed (via NixOS config scripts) psc-ide for Emacs. But my understanding is that that's just Emacs tooling for using psc-ide, rather than being psc-ide itself. When I search nixpkgs for psc-ide the only plausible candidate is haskellPackages.psc-ide, but that's marked as broken and won't install.

mikesol commented 2 years ago

Indeed, I think we're really close! The skipping dependency stuff is npm skipping over node-only stuff, which is fine as the build is for the browser.

If you're able to install https://github.com/purescript-emacs/psc-ide-emacs in emacs, then the only thing left should be pointing it to the purs executable. In nix-shell, I think you can use whereis purs or which purs to find this path (it'll be something long and incomprehensible in a nix directory). This can be used to set the psc-ide-purs-executable setting: https://github.com/purescript-emacs/psc-ide-emacs/blob/ce97d719458ea099b40c02f05b6609601c727e66/psc-ide.el#L73. There are a few other settings in there that may be useful (I've never used it so I'm not familiar with the config). You can also ping folks on the PreScript Discord #help-tools channel - there are several emacs users there.

Let me know if that works!

JeffreyBenjaminBrown commented 2 years ago

Maybe progress?

At this point I've installed:

    *** NixOS packages
        purescript
        spago
        nodejs
    *** Emacs packages (also installed via NixOS)
        psci
        purescript-mode
        psc-ide

Searching for purs gives different results in and out of the Nix shell. Outside the Nix shell, it's only in one place:

    jeff@jbb-dell:build$ whereis purs
    purs: /nix/store/665asszpkhysxn8kwf5s8i7s5m2lddsd-system-path/bin/purs

From within the Nix shell, that path is listed too, but before it is listed a different one:

    [nix-shell:~/code/music/wagsi]$ whereis purs
    purs: /nix/store/74w0lcb3h9h55zlb19cai2n3asgjhy1i-purescript-v0.14.4/bin/purs
          /nix/store/665asszpkhysxn8kwf5s8i7s5m2lddsd-system-path/bin/purs

It looks like that first one, /nix/store/74w..., points to 0.14.4, and that it's the right one to use. But I get the same Spago timeout error regardless of which one I use.

From within the Nix shell, I can start Emacs in Bash, using emacs -nw. After doing that I can run M-x customize to temporarily (for that session only) customize psc-ide-purs-executable, like you suggest. I've tried setting that to the path to 0.14.4 listed above, or to the standard one. In both cases I get a Spago timeout error. In fact I get the same error even if I disregard the Nix shell, instead starting Emacs in an X window.

For completeness, here are the errors I get under those three scenarios -- in the Nix shell with new purs path, in the Nix shell with the old purs path, and in X (outside of the Nix shell) with the old purs path. I'm pretty sure they're exactly the same, with the exception of listing slightly different URLs in the last line of the SPAGO ERRORS buffers. That line varies depending on the version of purs pointed to.

I suspect the below is way more information than you need, but just in case it's of interest, the text below is org-formatted. Thus if you want, you can view it in any editor that recognizes org-mode. I believe VSCode does. That way you can fold and unfold headings and subheadings by pressing TAB.

*** from Emacs in Bash in the Nix shell
**** with `psc-ide-purs-executable` = "/nix/store/74w0lcb3h9h55zlb19cai2n3asgjhy1i-purescript-v0.14.4/bin/purs"
***** *Backtrace*
      Debugger entered--Lisp error: (error "Error executing spago")
    signal(error ("Error executing spago"))
    error("Error executing spago")
    psc-ide--parse-globs("*SPAGO SOURCES*" "*SPAGO ERRORS*" (("cmd" . "spago") ("args" "sources")))
    psc-ide--spago-globs()
    psc-ide-server-use-package-manager-globs()
    psc-ide--server-start-globs()
    psc-ide-server-start("~/code/music/wagsi/")
    funcall-interactively(psc-ide-server-start "~/code/music/wagsi/")
    call-interactively(psc-ide-server-start nil nil)
    command-execute(psc-ide-server-start)
***** *SPAGO ERRORS*
      spago:
      Error: Connection establishment took too long

      URL: https://github.com/purescript/package-sets/releases/download/psc-0.14.1-20210419/packages.dhall
**** with `psc-ide-purs-executable` = "/nix/store/665asszpkhysxn8kwf5s8i7s5m2lddsd-system-path/bin/purs"
***** *Backtrace*
      Debugger entered--Lisp error: (error "Error executing spago")
    signal(error ("Error executing spago"))
    error("Error executing spago")
    psc-ide--parse-globs("*SPAGO SOURCES*" "*SPAGO ERRORS*" (("cmd" . "spago") ("args" "sources")))
    psc-ide--spago-globs()
    psc-ide-server-use-package-manager-globs()
    psc-ide--server-start-globs()
    psc-ide-server-start("~/code/music/wagsi/")
    funcall-interactively(psc-ide-server-start "~/code/music/wagsi/")
    call-interactively(psc-ide-server-start nil nil)
    command-execute(psc-ide-server-start)
***** *SPAGO ERRORS*
      spago:
      Error: Connection establishment took too long

      URL: https://github.com/purescript/package-sets/releases/download/psc-0.14.1-20210419/packages.dhall
*** from Emacs in X
    This is outside the Nix shell,
    so I didn't bother trying to customize the path to `purs`.
**** *Backtrace* buffer
     Debugger entered--Lisp error: (error "Error executing spago")
       signal(error ("Error executing spago"))
       error("Error executing spago")
       psc-ide--parse-globs("*SPAGO SOURCES*" "*SPAGO ERRORS*" (("cmd" . "spago") ("args" "sources")))
       psc-ide--spago-globs()
       psc-ide-server-use-package-manager-globs()
       psc-ide--server-start-globs()
       psc-ide-server-start("~/code/music/wagsi/")
       funcall-interactively(psc-ide-server-start "~/code/music/wagsi/")
       call-interactively(psc-ide-server-start nil nil)
       command-execute(psc-ide-server-start)
**** *SPAGO ERRORS* buffer
     spago:
     Error: The remote host took too long to respond
     URL: https://github.com/purescript/package-sets/releases/download/psc-0.14.1-20210419/packages.dhall
mikesol commented 2 years ago

This is super helpful, thanks! I will chat with a couple people from the PS community and will hopefully have more info soon.

JeffreyBenjaminBrown commented 2 years ago

Thanks, Mike!

thomashoneyman commented 2 years ago

I don't use emacs, so I hope I'm still useful -- here are a couple things that may help:

nwolverson commented 2 years ago
  spago:
 �[1;31mError�[0m: Connection establishment took too long

URL: https://github.com/purescript/package-sets/releases/download/psc-0.14.1-20210419/packages.dhall

This looks like some kind of proxy or network issue.

I'd recommend looking at resolving the issue while running spago directly first. I'd

  1. check you can curl that URL in the same shell; if so
  2. run spago -v install to see if you get the same error
  3. Check proxy environment variables. I'm not actually sure if spago respects http(s)_proxy env vars, it will be downloading the .dhall file via the dhall haskell library but it may need to explicitly configure that
  4. run network trace and see what's going on
JeffreyBenjaminBrown commented 2 years ago

Thanks for the help! Life is busy lately; sorry for the delay.

When I curl that URL I don't get a file, just this:

<html><body>You are being <a href="https://github-releases.githubusercontent.com/69126177/622bf380-a0e3-11eb-8796-a20f68ff6664?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20211018%2Fus-east-1%2Fs3%2Faws4_request&amp;X-Amz-Date=20211018T022921Z&amp;X-Amz-Expires=300&amp;X-Amz-Signature=26986acbe713593d40f65b2c8c01149ea0f58276cb7dbe5ff1189ce2c1cd99a7&amp;X-Amz-SignedHeaders=host&amp;actor_id=0&amp;key_id=0&amp;repo_id=69126177&amp;response-content-disposition=attachment%3B%20filename%3Dpackages.dhall&amp;response-content-type=application%2Foctet-stream">redirected</a>.</body></html>

By contrast, when I put the same URL into a browser, it brings up a Save As window.

mikesol commented 2 years ago

I've posted an issue on the spago project - maybe they've seen this before: https://github.com/purescript/spago/issues/825

JeffreyBenjaminBrown commented 2 years ago

Subscribed, thanks.

mikesol commented 2 years ago

Fabrizio gave a few good ideas here: https://github.com/purescript/spago/issues/825#issuecomment-947543496

mikesol commented 2 years ago

The next step once it works is:

npm install --no-optional && npm start

Eventually a browser should pop up!

mikesol commented 2 years ago

@JeffreyBenjaminBrown , are you still having this issue?

JeffreyBenjaminBrown commented 2 years ago

It almost works! When I run npm install && npm start it now installs, and brings up a browser tab with, eventually, a start audio button to click. When I click that some more text appears but I don't hear anything. I haven't started Qjackctl (I assume it's not needed) and I'm able to get sound on Youtube.

I assume the reason it's working is that nixpkgs is more up to date now. I upgraded to NixOS 21.11 recently. In case it's of interest to some future NixOS user, my configuration is here.

mikesol commented 2 years ago

Sweet, you're a stone's throw away from audio! A couple questions:

Thanks! We're close to getting it to work!

JeffreyBenjaminBrown commented 2 years ago

Oh hi there :)

If I open up the Javascript console from the Wagsi browser tab, then before pressing start I see these errors:

Found an initial wag 🐶
index.js:29 Found initial code 📦
log.js:24 [HMR] Waiting for update signal from WDS...
foreign.js:2 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
exports.context @ foreign.js:2
:8080/favicon.ico:1 Failed to load resource: the server responded with a status of 404 (Not Found)
index.js:49 [WDS] Hot Module Replacement enabled.
index.js:53 [WDS] Live Reloading enabled.
DevTools failed to load source map: Could not load content for webpack://wagsi/node_modules/sockjs-client/dist/sockjs.js.map: HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME

When I then press start I see nothing new in the console, and no other indication of error, but I hear nothing.

From the first site you posted, "make white noise" sure as hell worked: https://mdn.github.io/webaudio-examples/audio-buffer/ From the second one you posted, "drone with delay" also worked. https://mikesol.github.io/wagsi/#Drone%20with%20delay

mikesol commented 2 years ago

That is an error we used to get but haven't for a while. Have you git-pulled the most recent changes? Also, could you let me know what browser(s) you're using? All of the major ones should theoretically work, but there could be some issues I've overlooked. Thanks!

JeffreyBenjaminBrown commented 2 years ago

Thanks!

I redefined node to be the package `nodejs-17_x" and rebuilt my system. Now things seem pretty up to date:

jeff@jbb-dell:wagsi$ npm --version
8.3.0
jeff@jbb-dell:wagsi$ spago --version
0.20.2
jeff@jbb-dell:wagsi$ purs --version
0.14.5
jeff@jbb-dell:wagsi$ git remote -v
origin  https://github.com/mikesol/wagsi (fetch)
origin  https://github.com/mikesol/wagsi (push)
jeff@jbb-dell:wagsi$ git log
commit 9bb64f29b9ccf464c2d639e622d590ad3f5971a7 (HEAD -> main, origin/main, origin/HEAD)
Author: Mike Solomon <mike@wavr.so>
Date:   Sun Jan 16 19:35:23 2022 +0200

    Resets wagsi

And now wagsi won't build:

jeff@jbb-dell:wagsi$ npm install && npm start
npm WARN old lockfile
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'amqplib@0.5.2',
npm WARN EBADENGINE   required: { node: '>=0.8 <=9' },
npm WARN EBADENGINE   current: { node: 'v17.3.1', npm: '8.3.0' }
npm WARN EBADENGINE }

up to date, audited 1098 packages in 39s

73 packages are looking for funding
  run `npm fund` for details

57 vulnerabilities (2 low, 47 moderate, 4 high, 4 critical)

To address issues that do not require attention, run:
  npm audit fix

To address all issues possible (including breaking changes), run:
  npm audit fix --force

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.
npm notice
npm notice New patch version of npm available! 8.3.0 -> 8.3.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.3.1
npm notice Run npm install -g npm@8.3.1 to update!
npm notice

> start
> spago install && spago build && webpack serve --mode=development --open

sh: line 1: /home/jeff/code/music/wagsi/node_modules/.bin/spago: No such file or directory

I can't remember which browser it opened in when it opened, before I rebuilt my system, but it was probably Brave. My browsers are Brave, Chrome and FIrefox.