nix-community / dream2nix

Simplified nix packaging for various programming language ecosystems [maintainer=@DavHau]
https://dream2nix.dev
MIT License
1.03k stars 126 forks source link

[nodejs] Unable to build node app with dream2nix #552

Open MrFoxPro opened 1 year ago

MrFoxPro commented 1 year ago

I'm trying to build node package using flake-parts and dream2nix:

dream2nix.inputs.web_node = {
  source = ./web_node;
  projects.web_node = {name, ...}: {
    inherit name;
    # relPath = "";
    subsystem = "nodejs";
    translator = "package-json";
    builder = "strict-builder";
  };
};
packages = config.dream2nix.outputs.web_node.packages;

after running nix run .#resolveImpure, nix build .#web_node and nix flake show produces error:

error:
       … while evaluating the attribute 'optionalValue.value'

         at /nix/store/xpnpp1sq0gmzf72r0iy2ky6r4h4i6vvb-source/lib/modules.nix:800:5:

          799|
          800|     optionalValue =
             |     ^
          801|       if isDefined then { value = mergedValue; }

       … while evaluating a branch condition

         at /nix/store/xpnpp1sq0gmzf72r0iy2ky6r4h4i6vvb-source/lib/modules.nix:801:7:

          800|     optionalValue =
          801|       if isDefined then { value = mergedValue; }
             |       ^
          802|       else {};

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'web_node' missing

       at /nix/store/8c2qq8hx2pkd7bahgy2xvwk99dmbl2ki-source/src/subsystems/nodejs/builders/strict-builder/default.nix:258:36:

          257|         (name: version: {
          258|           "${name}"."${version}" = allPackages."${name}"."${version}";
             |                                    ^
          259|         })

Probably because of wrong path resolving?

I made simple example of unuccessful attempt to build app with dream2nix (repro): https://github.com/MrFoxPro/attempt-to-build-js-with-dream2nix

woile commented 1 year ago

I'm having exactly the same issue. And I've been doing exactly the same steps haha. I wonder if there's some setting we are missing, I wasn't able to find much docs.

I'm on a Mac bookpro

woile commented 1 year ago

I kind of solve it by removing the projects chunk. I get another error now.

Try nix flake show (it should fail, almost lists the packages)

Remove:

- projects.web_node = {name, ...}: {
-    inherit name;
-    # relPath = "";
-    subsystem = "nodejs";
-    translator = "package-json";
-    builder = "strict-builder";
-  };

And let nix2dream detect the nodejs automatically. Run nix flake show again and observe, you should see the package web_node.

Now when trying to build: nix build .#web_node (in your case) I get some impure error that I cannot fix with nix build .#resolveImpure

Hope it helps

MrFoxPro commented 1 year ago

I think it's related to relPath, because some people report that it's working when setup with project.toml