purescript-halogen / purescript-halogen-template

Template project for getting started with Halogen
Apache License 2.0
128 stars 56 forks source link

`npm install` fails on NixOS (Error: purescript@0.14.0 postinstall) #30

Closed srid closed 3 years ago

srid commented 3 years ago

The error message unfortunately is not totally clear on the cause of the crash, but I can't seem to use this template on NixOS following the README instructions.

1782 verbose stack Error: purescript@0.14.0 postinstall: `install-purescript --purs-ver=0.14.0`
1782 verbose stack Exit status 1
1782 verbose stack     at EventEmitter.<anonymous> (/nix/store/6mbng3dq3q28r5mi4p58dkig9j2v348h-nodejs-12.21.0/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
1782 verbose stack     at EventEmitter.emit (events.js:314:20)
1782 verbose stack     at ChildProcess.<anonymous> (/nix/store/6mbng3dq3q28r5mi4p58dkig9j2v348h-nodejs-12.21.0/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
1782 verbose stack     at ChildProcess.emit (events.js:314:20)
1782 verbose stack     at maybeClose (internal/child_process.js:1022:16)
1782 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
1783 verbose pkgid purescript@0.14.0
1784 verbose cwd /home/srid/code/purescript-halogen-template
1785 verbose Linux 5.11.2
1786 verbose argv "/nix/store/6mbng3dq3q28r5mi4p58dkig9j2v348h-nodejs-12.21.0/bin/node" "/home/srid/.nix-profile/bin/npm" "install"
1787 verbose node v12.21.0
1788 verbose npm  v6.14.11
1789 error code ELIFECYCLE
1790 error errno 1
1791 error purescript@0.14.0 postinstall: `install-purescript --purs-ver=0.14.0`
1791 error Exit status 1
1792 error Failed at the purescript@0.14.0 postinstall script.
1792 error This is probably not a problem with npm. There is likely additional logging output above.
1793 verbose exit [ 1, true ]
srid commented 3 years ago

If I put spago in the nix-shell:

image

srid commented 3 years ago

Using the following shell.nix,

{ pkgs ? import <nixpkgs> {} }:
let
  easy-ps = import ./dep/easy-purescript-nix { inherit pkgs; };
in 
  pkgs.mkShell {
    buildInputs = [
      easy-ps.purs-0_14_0
      easy-ps.psc-package
      easy-ps.spago
      # `npm install` builds PS using its stack.yml which is on lts-13.26 (ghc 8.6.5)
      pkgs.stack
      pkgs.haskell.compiler.ghc865
    ];
  }

I get (the log file has nothing useful):

image

thomashoneyman commented 3 years ago

If you’re using a Nix shell for the compiler and Spago then I would remove the PureScript and spago dependencies from the package.json file.

thomashoneyman commented 3 years ago

I’m not exactly sure why PureScript fails to build, but that wouldn’t be specific to this template.

srid commented 3 years ago

Ah, right, I should have taken a peek at package.json.

So it looks like with my shell.nix, I can just use spago build (or npm run-script build) followed by npm run-script serve (after manually installing parcel, which isn't available in nixpkgs or easy-purescript-nix). That worked for me ... though I'm not 100% clear what Nix workflow Nix'ers use for this project, and PureScript web projects in general.

thomashoneyman commented 3 years ago

My understanding is that folks either:

  1. Run the entire build through Nix, where tools like yarn2nix and spago2nix generate derivations for NPM / PureScript dependencies, or
  2. Run the build through Nix in CI or production, but run local builds using a shell.nix for PureScript dev dependencies with a hook to install NPM dependencies.

We can keep discussing, but I'm going to close the issue as this isn't an error specific to this template but rather to PureScript installation on NixOS generally.