justinwoo / spago2nix

Generate a derivation of (old) Spago dependencies, and use them to install them into the directory structure used by Spago.
MIT License
42 stars 23 forks source link

Can't run inside of Nix build shell (bad interpreter) #4

Open chekoopa opened 5 years ago

chekoopa commented 5 years ago

Trying to call spago2nix inside of configurePhase of derivation, got this:

warning: dumping very large path (> 256 MiB); this may run out of memory
these derivations will be built:
  /nix/store/s6vqpr9j8r041nbpdsg1i8yz0w6brspb-ips3-main-ui-1.0.drv
building '/nix/store/s6vqpr9j8r041nbpdsg1i8yz0w6brspb-ips3-main-ui-1.0.drv'...
unpacking sources
unpacking source archive /nix/store/9y146s79ik9a43rjw26av5dsa01g4ipx-ui
source root is ui
patching sources
configuring
hello?
/nix/store/9nw4wgs4ffkj6cxrgiar5hp6kkg2bf9x-spago2nix/bin/spago2nix: /nix/store/9nw4wgs4ffkj6cxrgiar5hp6kkg2bf9x-spago2nix/bin/.spago2nix-wrapped: /usr/bin/env: bad interpreter: No such file or directory
/nix/store/9nw4wgs4ffkj6cxrgiar5hp6kkg2bf9x-spago2nix/bin/spago2nix: line 3: /nix/store/9nw4wgs4ffkj6cxrgiar5hp6kkg2bf9x-spago2nix/bin/.spago2nix-wrapped: Success
builder for '/nix/store/s6vqpr9j8r041nbpdsg1i8yz0w6brspb-ips3-main-ui-1.0.drv' failed with exit code 127
error: build of '/nix/store/s6vqpr9j8r041nbpdsg1i8yz0w6brspb-ips3-main-ui-1.0.drv' failed

Seems that there's node missing in the $PATH.

chekoopa commented 5 years ago

Partly resolved by not running spago2nix as an app, preferring a Nix-generated script instead.

buildPhase = let spagoPkgs = import ./spago-packages.nix { inherit pkgs; };
  in '' 
    ${spagoPkgs.installSpagoStyle}
    ${spagoPkgs.buildSpagoStyle}
  '';
justinwoo commented 5 years ago

Could try to look at what causes some of the issues, but yeah, better to just not have to call spago2nix and use plain nix instead when using this for an actual build.

paulyoung commented 5 years ago

I ran into the following when trying to build in a Nix sandbox (macOS was fine) and it seems like the same issue as above.

...
building
/nix/store/63karsgdg7fm3q0if4zfd7apbd8ac1ci-stdenv-linux/setup: /nix/store/la80wr5yqk6v135jczypqsgma0c9anv9-install-spago-style: /usr/bin/env: bad interpreter: No such file or directory

This worked for me:

let removeHashBang = drv: drv.overrideAttrs (oldAttrs: {
  buildCommand = builtins.replaceStrings ["#!/usr/bin/env"] [""] oldAttrs.buildCommand;
}); in
    buildPhase = ''
-      ${spagoPackages.installSpagoStyle}
+      ${removeHashBang spagoPackages.installSpagoStyle}
-      ${spagoPackages.buildSpagoStyle} "src/**/*.purs" "test/**/*.purs"
+      ${removeHashBang spagoPackages.buildSpagoStyle} "src/**/*.purs" "test/**/*.purs"
      purs bundle './output/*/*.js' --module Main --main Main --output ${exeName}
    '';
justinwoo commented 5 years ago

should we just remove that shebang in general? might not be an issue

justinwoo commented 5 years ago

oops

paulyoung commented 5 years ago

My NixOS and Darwin builds both work without it

tbenst commented 4 years ago

removeHashBang also works for me on NixOS, broken without. Thanks for the tip!

justinlovinger commented 4 years ago

Removing the hash-bang fixes it in nix-build but breaks the shell when running a phase like eval $checkPhase in a nix-shell. Replacing the hash-bang with #!/bin/sh seems to fix it everywhere.

For convenience

fixHashBang = drv: drv.overrideAttrs (oldAttrs: {
  buildCommand = builtins.replaceStrings ["#!/usr/bin/env bash"] ["#!/bin/sh"] oldAttrs.buildCommand;
});

Unless there is a reason to not use #!/bin/sh, I recommend replacing #!/usr/bin/env bash with #!/bin/sh.

justinwoo commented 4 years ago

Yes, that is probably fine with me. Especially considering that we do not need any glob pattern handling in the actual scripts

justinwoo commented 4 years ago

Please make a PR with whatever solution pleases you.