spago2nix icon indicating copy to clipboard operation
spago2nix copied to clipboard

More beginner friendly and complete example setup, please

Open magthe opened this issue 4 years ago • 4 comments

I'm struggling with setting up a derivation for my project and I think it'd be useful to have a beginner friendly (complete) example. Or maybe you have some public project using spago2nix that you can point to?

This is what I have at the moment:

{ pkgs ? import <nixpkgs> { }) }:

with pkgs;

let spagoPkgs = import ./spago-packages.nix { inherit pkgs; };

in stdenv.mkDerivation rec {
  pname = "my-frontend";
  src = lib.cleanSource ./.;
  version = "0.1";
  buildInputs = []; # what to put here??
  buildPhase = ''
    ${spagoPkgs.installSpagoStyle} # fails because it's a directory???
    ${spagoPkgs.buildSpagoStyle}
    ${spagoPkgs.buildFromNixStore}
  '';
  installPhase = ''
    echo "what would an install phase look like? 'spago bundle-app'?"
    echo "hello" > "$out/hello"
  '';
}

and it results in

❯ nix-build
these derivations will be built:
  /nix/store/snqbfnfiimbwmxx49sv52jcs3ixvxlhm-my-frontend-0.1.drv
building '/nix/store/snqbfnfiimbwmxx49sv52jcs3ixvxlhm-my-frontend-0.1.drv'...
unpacking sources
unpacking source archive /nix/store/1yyr076qh70rmkqh8s717q0sg7d48y0h-source
source root is source
patching sources
configuring
no configure script, doing nothing
building
/nix/store/dj40kjgp5lhs55v4hc47vyrarhq4qycz-stdenv-linux/setup: line 1309: /nix/store/cdpd8vclmd9iji26qq0pd8jyd2syhndx-install-spago-style: Is a directory
builder for '/nix/store/snqbfnfiimbwmxx49sv52jcs3ixvxlhm-my-frontend-0.1.drv' failed with exit code 126
error: build of '/nix/store/snqbfnfiimbwmxx49sv52jcs3ixvxlhm-my-frontend-0.1.drv' failed

magthe avatar Aug 10 '21 09:08 magthe

After asking for help on the PureScript Discourse I've ended up with the following

{ pkgs ? import <nixpkgs> { }) }:

with pkgs;

let spagoPkgs = import ./spago-packages.nix { inherit pkgs; };

in stdenv.mkDerivation rec {
  pname = "hu-frontend";
  src = lib.cleanSource ./.;
  version = "0.1";

  buildInputs = [
    spagoPkgs.installSpagoStyle
    spagoPkgs.buildSpagoStyle
    spagoPkgs.buildFromNixStore
    purescript
    spago
  ];

  unpackPhase = ''
    cp $src/{packages,spago}.dhall .
    cp -r $src/src .
    install-spago-style
  '';

  buildPhase = ''
    build-spago-style ./src/*.purs
    spago bundle-app --no-build --no-install
  '';

  installPhase = ''
    install -D -m644 ./index.js $out/srv/hu-frontend.js
  '';
}

It works locally but is very different from the instructions in the project's README. Are the instructions simply outdated?

magthe avatar Aug 13 '21 05:08 magthe

Thank you for leaving that here, I also had major troubles getting this to work, but with your template it's working!

pmiddend avatar Nov 21 '21 08:11 pmiddend

Is there a complete solution that allows calling spago2nix from nix?

klntsky avatar Jan 13 '22 09:01 klntsky

Also, I'm getting [error] Directory "/" is not accessible. Permissions {readable = True, writable = False, executable = False, searchable = True} from spago on spago bundle-app --no-build --no-install step.

EDIT: the culprit was global spago cache. spago --global-cache skip helped

klntsky avatar Jan 13 '22 10:01 klntsky