Skip to content

[WIP] deno.fetchDeps: init#358252

Closed
pluiedev wants to merge 3 commits intoNixOS:masterfrom
pluiedev:push-qmztkqutxutr
Closed

[WIP] deno.fetchDeps: init#358252
pluiedev wants to merge 3 commits intoNixOS:masterfrom
pluiedev:push-qmztkqutxutr

Conversation

@pluiedev
Copy link
Member

This PR is like #326003, but considerably more minimal and based on Deno 2.0.

I believe the other PR is doing way too much than what is strictly necessary at this point, and a more composable design with hooks and dependency fetchers is more in line with what Nixpkgs is gravitating towards with tools like cargo-tauri and pnpm.

Note that the closure size with Deno deps might be considerably bigger than the same dependencies fetched with either fetchNpmDeps and pnpm.fetchDeps, due to the lack of a content-addressible mechanism. fetchNpmDeps has its own code that generates a content-addressible closure but I'm a) not exactly sure how it works and b) how it is restored to a normal node_modules structure, and pnpm is designed around CA stores as a core design. Still, this is possibly a future problem to solve.

Marking as draft for now as there's some more polishing that can be done for the scripts, and maybe a build/install hook should be added like the other PR.

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/)
  • 25.05 Release Notes (or backporting 24.11 and 25.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.

Copy link
Member

@winterqt winterqt left a comment

Choose a reason for hiding this comment

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

This will break the FODs almost instantly if Deno changes anything in how they pull deps, and also is probably not reproducible between platforms when platform-specific dependencies are used.

Does Deno have a flag that can mitigate at least the second issue?

@pluiedev
Copy link
Member Author

This will break the FODs almost instantly if Deno changes anything in how they pull deps, and also is probably not reproducible between platforms when platform-specific dependencies are used.

Does Deno have a flag that can mitigate at least the second issue?

I at least have tested this on aarch64-linux and x86_64-linux, and it seems to work just fine. As for the former issue, I believe we could do what pnpm did and just pin Deno versions

@pluiedev pluiedev changed the title deno.fetchDeps: init [WIP] deno.fetchDeps: init Nov 22, 2024
@ofborg ofborg bot requested a review from 06kellyjac November 23, 2024 17:57
@ofborg ofborg bot added 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Nov 23, 2024
@Scrumplex
Copy link
Member

I'd suggest opening an issue upstream and establish some reproducibility guarantees (if upstream is willing)

@pluiedev
Copy link
Member Author

I'd suggest opening an issue upstream and establish some reproducibility guarantees (if upstream is willing)

The author of the previous PR has already made upstream incorporate a number of reproducibility guarantees. Now I'm just testing whether it is completely reliable just yet

@pluiedev
Copy link
Member Author

pluiedev commented Nov 23, 2024

I've been experimenting with how the API should look like for an application that uses Deno, and this is what I've come up with for now:

{
  lib,
  stdenv,
  fetchFromGitHub,
  deno,
  jq,
}:
stdenv.mkDerivation (finalAttrs: {
  pname = "studio-pack-generator";
  version = "0.5.12";

  src = fetchFromGitHub {
    owner = "jersou";
    repo = "studio-pack-generator";
    rev = "v0.5.12";
    hash = "sha256-pfrF/jydpLF5o3aacQ33o5/kUcXooXTb3+ggX7+u+3s=";
  };

  nativeBuildInputs = [ 
    jq 
    deno.setupHook 
    deno.compileHook 
  ];
  
  denoEntrypoints = [ "studio_pack_generator.ts" ];

  denoDeps = deno.fetchDeps {
    inherit (finalAttrs) pname src denoEntrypoints;
    hash = "sha256-UFR3oiJspzRYQni4o5yhi00kufpckTmWdAilR62e+xk=";
  };

  denoCompileFlags = [
    "--allow-all"
    "--unstable"
  ];
})

A couple of design notes:

  • No buildDenoApplication of any sort since Deno can be used in a lot of different contexts, including as a task runner, a package manager, or a fully fledged flamework for an application. A modular approach would be better here.

  • deno.setupHook would prepare the Deno cache and copy the vendored node_modules/ and vendor/ directories to the source root

  • deno.compileHook would run deno compile --cached-only --vendor --node-modules-dir <denoCompileFlags> <entrypoints> and then mark built files as stripExclude to avoid removing all the embedded JS code within "compiled" binaries

  • Perhaps more hooks would be needed for, for example, running Deno tasks like deno task build

@pluiedev pluiedev force-pushed the push-qmztkqutxutr branch 2 times, most recently from b9620db to 851689f Compare November 24, 2024 09:29
Adds a simple setup hook that would add any fetched Deno deps to the
node_modules folder at the root source directory.
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. and removed 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Nov 25, 2024
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 31, 2024
@antholeole
Copy link

Hello! I tried this PR out to build a deno package and unfortunately ran into errors. I'm trying out deno for the first time with this PR so this may be user error.

Here's the commit that tries this package: antholeole/home-server@8cb9a50

when building nix build .#server, I get the following error:

Error getting response at https://registry.npmjs.org/@tldraw%2fstate for package "@tldraw/state": An npm specifier not found in cache: "@tldraw/state", --cached-only is specified.

I may attempt to debug further but leaving this here for future readers.

As for the API this is very usable and easy, thanks for the work you did here.

@MattSturgeon MattSturgeon mentioned this pull request May 1, 2025
13 tasks
@pluiedev pluiedev mentioned this pull request May 23, 2025
13 tasks
@pluiedev
Copy link
Member Author

Superseded by #407434

@pluiedev pluiedev closed this Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants