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

If the HOME environment variable is not set, npm can't build #187

Open
a-h opened this issue Jul 19, 2023 · 0 comments
Open

If the HOME environment variable is not set, npm can't build #187

a-h opened this issue Jul 19, 2023 · 0 comments

Comments

@a-h
Copy link

a-h commented Jul 19, 2023

When building a web app inside a container, the $HOME variable is not set. NPM tries to write to the non-existent directory, and you get a EACCES: permission denied, mkdir '/homeless-shelter' error.

      app = nl2nix.v2.build {
        src = ./.;
        nodejs = pkgs.nodejs-18_x;
        buildCommands = [ "npm run build" ];
      };

Example logs:

trace: warning: [npmlock2nix] You are using the new v2 beta api. The interface isn't stable yet. Please report any issues at https://github.com/nix-community/npmlock2nix/issues
these 4 derivations will be built:
  /nix/store/bqmd5qx140xxbr4j02y07k54ri2i8743-app-nodejs-0.1.0.drv
  /nix/store/7pd87dr33nncigdm5gk83sjzd81qipmd-docker-layer-app.drv
  /nix/store/qgq0pmkdgpi65ngijx4cvxmwh79cwpsb-runtime-deps.drv
  /nix/store/cx930cb5wc2zy3rw8xgfzzm284m38y8p-docker-image-app.tar.gz.drv
building '/nix/store/bqmd5qx140xxbr4j02y07k54ri2i8743-app-nodejs-0.1.0.drv'...
app-nodejs> unpacking sources
app-nodejs> unpacking source archive /nix/store/j0ll9ipg4ipyyd4fcdrwyj3y8wdnnwbh-bnfw680ps3kma0rsx19a5n1qyb1qyv5k-source
app-nodejs> source root is bnfw680ps3kma0rsx19a5n1qyb1qyv5k-source
app-nodejs> patching sources
app-nodejs> configuring
app-nodejs> no configure script, doing nothing
app-nodejs> building
app-nodejs> npm verb cli /nix/store/mdgmqgbiqw30lygdn6q5pd6cvx4ialvb-nodejs-18.16.1/bin/node /nix/store/mdgmqgbiqw30lygdn6q5pd6cvx4ialvb-nodejs-18.16.1/bin/npm
app-nodejs> npm info using [email protected]
app-nodejs> npm info using [email protected]
app-nodejs> npm verb cache could not create cache: Error: EACCES: permission denied, mkdir '/homeless-shelter'
app-nodejs> npm verb logfile could not create logs-dir: Error: EACCES: permission denied, mkdir '/homeless-shelter'
app-nodejs> npm verb title npm run build
app-nodejs> npm verb argv "run" "build" "--loglevel" "verbose"
app-nodejs> npm verb logfile logs-max:10 dir:/homeless-shelter/.npm/_logs/2023-07-19T12_15_14_436Z-
app-nodejs> npm verb logfile could not be created: Error: ENOENT: no such file or directory, open '/homeless-shelter/.npm/_logs/2023-07-19T12_15_14_436Z-debug-0.log'
app-nodejs> npm verb logfile no logfile created
app-nodejs> 

Workaround

A workaround is to customise the buildCommands to set the $HOME directory as part of the build process.

      app = nl2nix.v2.build {
        src = ./.;
        nodejs = pkgs.nodejs-18_x;
        buildCommands = [ "HOME=$PWD" "npm run build" ];
      };

Possible solution

If HOME is set to something that's not writable, set a sensible default automatically?

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

1 participant