Skip to content

Convert elm-review from node2nix to buildNpmPackage#351767

Closed
zupo wants to merge 2 commits intoNixOS:masterfrom
teamniteo:elm_buildNpmPackage/elm-review
Closed

Convert elm-review from node2nix to buildNpmPackage#351767
zupo wants to merge 2 commits intoNixOS:masterfrom
teamniteo:elm_buildNpmPackage/elm-review

Conversation

@zupo
Copy link
Contributor

@zupo zupo commented Oct 27, 2024

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@zupo
Copy link
Contributor Author

zupo commented Oct 27, 2024

@hsjobeki: here's the diff we worked on today. As I was preparing the commit I noticed some elm packages have already been ported to buildNpmPackage, so I have re-written our stuff to look like the existing packages. Funnily enough, now I get a different error:

error: builder for '/nix/store/n04nqsnyr1qmz37475bz4hxlmwqgvd5m-elm-review-2.12.0.drv' failed with exit code 1;
       last 23 log lines:
       > Running phase: unpackPhase
       > unpacking source archive /nix/store/ry807l4bg0s77ymsx01baw7rqvi6d2bc-source
       > source root is source
       > Running phase: patchPhase
       > Executing npmConfigHook
       > Configuring npm
       > Validating consistency between /private/tmp/nix-build-elm-review-2.12.0.drv-0/source/package-lock.json and /nix/store/agijrxfmrmqcasr4aydq46m53cnqg3bs-elm-review-2.12.0-npm-deps/package-lock.json
       > \Installing dependencies
       > npm error code EJSONPARSE
       > npm error path /private/tmp/nix-build-elm-review-2.12.0.drv-0/source/package.json
       > npm error JSON.parse Expected double-quoted property name in JSON at position 879 while parsing near ".../run.sh record)\",\n  },\n  \"repository\": {..."
       > npm error JSON.parse Failed to parse JSON data.
       > npm error JSON.parse Note: package.json must be actual JSON, not just JavaScript.

Which is strange, as I don't see what the problem is with package.json, neither does my JSON validator.

@zupo zupo mentioned this pull request Oct 27, 2024
"create-elm-app",
"elm-optimize-level-2",
"elm-pages",
"elm-review",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ./pkgs/development/node-packages/remove-attr.py elm-review to also remove it from node-packages.nix.
And you should add an entry to pkgs/development/node-packages/aliases.nix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran this, and it doesn't seem to do anything. No output, no error, no changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked pkgs/development/node-packages/aliases.nix and I don't see other elm packages listed there (besides elm-test)? Why does elm-review need to be listed and others not? Should I add others as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want nodePackages.elm-review to remain an alias after we remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran this, and it doesn't seem to do anything.

Maybe the entry still needs to exist in node-packages.json for the script to work? I'm sure the Python script isn't too hard to read.

dontNpmBuild = true;

meta = {
changelog = "https://github.com/jfmengels/node-elm-review/blob/v${src.rev}/CHANGELOG.md";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
changelog = "https://github.com/jfmengels/node-elm-review/blob/v${src.rev}/CHANGELOG.md";
changelog = "https://github.com/jfmengels/node-elm-review/blob/${src.rev}/CHANGELOG.md";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is correct. ignore this recommendation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src.rev already contains the leading v

@ofborg ofborg bot requested a review from turboMaCk October 28, 2024 06:09
@ofborg ofborg bot added 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Oct 28, 2024
Copy link
Member

@turboMaCk turboMaCk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash the commits into a single one with usual commit message. After that I think we can merge this change.

Thanks a lot for revisiting it.

@zupo zupo force-pushed the elm_buildNpmPackage/elm-review branch from fd650e2 to af4690b Compare October 29, 2024 09:09
@zupo
Copy link
Contributor Author

zupo commented Oct 29, 2024

Suggested fixes applied.

@hsjobeki the error is now the same as during NixCon hackday:

       > Running phase: unpackPhase
       > unpacking source archive /nix/store/ry807l4bg0s77ymsx01baw7rqvi6d2bc-source
       > source root is source
       > Running phase: patchPhase
       > Executing npmConfigHook
       > Configuring npm
       > Validating consistency between /private/tmp/nix-build-elm-review-2.12.0.drv-0/source/package-lock.json and /nix/store/agijrxfmrmqcasr4aydq46m53cnqg3bs-elm-review-2.12.0-npm-deps/package-lock.json
       > Installing dependencies
       > npm warn deprecated @types/chalk@2.2.0: This is a stub types definition for chalk (https://github.com/chalk/chalk). chalk provides its own type definitions, so you don't need @types/chalk installed!
       > npm error code ENOTCACHED
       > npm error request to https://registry.npmjs.org/yocto-queue failed: cache mode is 'only-if-cached' but no cached response is available.
       > npm error Log files were not written due to an error writing to the directory: /nix/store/agijrxfmrmqcasr4aydq46m53cnqg3bs-elm-review-2.12.0-npm-deps/_logs
       > npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
       >
       > ERROR: npm failed to install dependencies

@zupo
Copy link
Contributor Author

zupo commented Oct 29, 2024

Please squash the commits into a single one with usual commit message. After that I think we can merge this change.

Thanks a lot for revisiting it.

I'd love it for this to be the case, but the package doesn't build (yet!). I'll squash when it does.

Also, I'm happy to apply the things I learn in this PR to other elm packages too.

@ofborg ofborg bot requested a review from turboMaCk October 29, 2024 12:01
@hsjobeki
Copy link
Contributor

Suggested fixes applied.

@hsjobeki the error is now the same as during NixCon hackday:

       > Running phase: unpackPhase
       > unpacking source archive /nix/store/ry807l4bg0s77ymsx01baw7rqvi6d2bc-source
       > source root is source
       > Running phase: patchPhase
       > Executing npmConfigHook
       > Configuring npm
       > Validating consistency between /private/tmp/nix-build-elm-review-2.12.0.drv-0/source/package-lock.json and /nix/store/agijrxfmrmqcasr4aydq46m53cnqg3bs-elm-review-2.12.0-npm-deps/package-lock.json
       > Installing dependencies
       > npm warn deprecated @types/chalk@2.2.0: This is a stub types definition for chalk (https://github.com/chalk/chalk). chalk provides its own type definitions, so you don't need @types/chalk installed!
       > npm error code ENOTCACHED
       > npm error request to https://registry.npmjs.org/yocto-queue failed: cache mode is 'only-if-cached' but no cached response is available.
       > npm error Log files were not written due to an error writing to the directory: /nix/store/agijrxfmrmqcasr4aydq46m53cnqg3bs-elm-review-2.12.0-npm-deps/_logs
       > npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
       >
       > ERROR: npm failed to install dependencies

I'll try to debug this tomorrow.

@dotlambda
Copy link
Member

npm error request to https://registry.npmjs.org/yocto-queue failed: cache mode is 'only-if-cached' but no cached response is available.

The yocto-queue entry in upstream's package-lock.json is missing values for resolved and integrity. Upstream needs to regenerate their lock file.

@zupo
Copy link
Contributor Author

zupo commented Oct 29, 2024

npm error request to https://registry.npmjs.org/yocto-queue failed: cache mode is 'only-if-cached' but no cached response is available.

The yocto-queue entry in upstream's package-lock.json is missing values for resolved and integrity. Upstream needs to regenerate their lock file.

Is there a workaround if they don't do it?

@dotlambda
Copy link
Member

Is there a workaround if they don't do it?

Vendor the lock file.

@hsjobeki
Copy link
Contributor

hsjobeki commented Oct 31, 2024

@zupo I validated the ca-cache. It seems not all packages are installed. Maybe due to missing integrity hashes as mentioned. (Didn't dive into the rust code there.)

Workaround without vendoring in my mind: Create a fixed output derivation for node_modules?

You could try to install dependencies with npm natively and pass the generated node_modules to your package.
Trusting npm itself to be reproducible and properly lock the dependencies.
You can then pass this as npmDeps. Since you dont need any other logic you can disable build and configure phases and copy the node_modules manually (maybe symlinking would also work?)

But this might be potentially unstable? But could also be fine. There are cases where the registry randomly gives u other reponses, in which case both methods should fail.

Both solutions have pro and cons so it might be up for the node ecosystem maintainers to decide what they prefer.
I guess @dotlambda already pointed that he would prefer a vendored lockfile.

@dotlambda
Copy link
Member

The first step is opening an upstream issue or PR for regenerating the lock file.

@turboMaCk
Copy link
Member

turboMaCk commented Oct 31, 2024

I would first check if it's not fixed already in HEAD upstream. Using commit like this or later jfmengels/node-elm-review@de899d2

@zupo zupo mentioned this pull request Feb 15, 2025
13 tasks
@zupo
Copy link
Contributor Author

zupo commented Feb 15, 2025

Work continues in #382294.

@zupo zupo closed this Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants