Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More beginner friendly and complete example setup, please #48

Open
magthe opened this issue Aug 10, 2021 · 4 comments
Open

More beginner friendly and complete example setup, please #48

magthe opened this issue Aug 10, 2021 · 4 comments

Comments

@magthe
Copy link

magthe commented Aug 10, 2021

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
Copy link
Author

magthe commented Aug 13, 2021

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?

@pmiddend
Copy link

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

@klntsky
Copy link

klntsky commented Jan 13, 2022

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

@klntsky
Copy link

klntsky commented Jan 13, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants