Repository navigation
bun: init configHook & fetchDeps - #376299
eveeifyeve wants to merge 3 commits into
Conversation
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as outdated.
This comment was marked as outdated.
5b658cf to
fac0e2a
Compare
winterqt
left a comment
There was a problem hiding this comment.
To even begin reviewing this, this needs to be properly split up into multiple commits; ideally, the Bun upgrade would be done in a separate PR entirely.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
a72a721 to
30e4175
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Merged |
|
The FODs produced are not reproducible. The build fails if you do not have the FOD as it reports a different hash. |
RossSmyth
left a comment
There was a problem hiding this comment.
Think very carefully about the public API. What should be able to be overriden? What shouldn't be? Making the public API as small as possible for the MVP is good because expanding it later is not a breaking change, while reducing it is.
Also giving this a try, the FODs are not reproducible as noted above.
| dontConfigure = args'.dontConfigure or true; | ||
| dontFixup = args'.dontFixup or true; | ||
|
|
||
| inherit outputHash outputHashAlgo; |
There was a problem hiding this comment.
Please actually think about this review instead of saying that is is complicated. It is making it more future-proof.
For this I have the check with other apps that use bun and see if it's globally producing There is also some known issues I am trying to fix before this like in the configHook it's not unpacking the tar correctly. |
The dd command is just writing 4 bytes at offset 96 in the file. Which does fit very nicely with my diff where I found the difference at 0x60. This would be valid as long as we assume that the position of the timestamp is always at that static offset and that we are dealing with a 4 byte little endian encoded unix timestamp. Considering that there were 4 trailing 0 bytes, we might be dealing with an 8 byte value. We definitely need to look into the binary format. Also I don't expect the second command restoring the date to really work since it seems to try to read the current date via the date command. |
| # `bunDeps` should be a tarball | ||
| unpackFile "$bunDeps" | ||
| bunDepsCopy="$(realpath "$(stripHash "$bunDeps")")" | ||
|
|
||
| echo "Configuring bun store" | ||
|
|
||
| HOME=$(mktemp -d) | ||
| BUN_INSTALL_CACHE_DIR=$(mktemp -d) | ||
| export HOME BUN_INSTALL_CACHE_DIR | ||
|
|
||
| cp -Tr "$bunDepsCopy" "$BUN_INSTALL_CACHE_DIR" | ||
| chmod -R +w "$BUN_INSTALL_CACHE_DIR" |
There was a problem hiding this comment.
Why exactly are we creating 2 copies of the unpacked FOD? Couldn't we just unpack into a temp dir and point BUN_INSTALL_CACHE_DIR at it?
There was a problem hiding this comment.
It needs to first unpack the deps to $bunDeps and then next line stripes the hash before it can be copied to the BUN_INSTALL_CACHE_DIR.
There was a problem hiding this comment.
Hold on, aren't we unpacking from bunDeps to the current working directory? The location of the folder is then stored in bunDepsCopy where the content is then copied to Bun_install_cache_Dir.
This seems a bit unnecessarily complicated.
Why not something like this:
HOME=$(mktemp -d)
pushd $(mktemp - d)
unpackFile "$bunDeps"
export BUN_INSTALL_CACHE_DIR="$(realpath "$(stripHash "$bunDeps")")"
popd
There was a problem hiding this comment.
It supposed to be unpacking to $bunDeps. The reason as to why it's not is because it doesn't have a root dir. Please have a look at @getchoo review if your unsure.
There was a problem hiding this comment.
There was a problem hiding this comment.
Hold on, aren't we unpacking from bunDeps to the current working directory? The location of the folder is then stored in bunDepsCopy where the content is then copied to Bun_install_cache_Dir.
This seems a bit unnecessarily complicated.
Why not something like this:
HOME=$(mktemp -d) pushd $(mktemp - d) unpackFile "$bunDeps" export BUN_INSTALL_CACHE_DIR="$(realpath "$(stripHash "$bunDeps")")" popd
@kuflierl Does that even work?
| fi | ||
|
|
||
| # `bunDeps` should be a tarball | ||
| unpackFile "$bunDeps" |
There was a problem hiding this comment.
Known problem: This is not unpacking to $bunDeps which is not correct in fetcher.
|
I couldn't find anything similar posted in this PR, so reposting it for visibility
Originally posted in #510466 (comment) |
|
hi, I tried this on my own bun project (starmie-cli) which is a small CLI with just Env: nixpkgs at A couple of things I ran into.
bunDeps = bun.fetchDeps {
inherit (finalAttrs) pname version src;
hash = "..."; # clear this and generate a new one
};If you write it like that the build runs without network access and bun fails immediatly: The derivation produced by Switching to Probably either map Once the fetch part works, the configHook fails with: Same symptom as #3632939109 I think. The hook does: unpackFile "$bunDeps"
bunDepsCopy="$(realpath "$(stripHash "$bunDeps")")"
...
cp -Tr "$bunDepsCopy" "$BUN_INSTALL_CACHE_DIR"But the tarball is built with Two ways out I can think of:
I went with the second one locally by inlining the configHook logic in a custom Reproducibility looked fine on the same machine. Ran the dependencies tarball three times (deleted the output between runs) and once via Also, pokescope's dependency tree doesn't include oh and also, the docs show bunInstallFlags = [ "--shamefully-hoist" ];
bunDeps = bun.fetchDeps {
inherit (finalAttrs) bunInstallFlags;
};But in Flake I used for the test: https://github.com/luvcie/starmie-cli/tree/spike/bun-fetchdeps |
|
I will be working on this again, thanks for everyone patience. I am working on a script in rust to handle the fetching which is what I assume @hsjobeki means for splitting the FOD part. Overall later on IMO, It would be good to ideally integrate this support into prefetch-npm-deps, but that is a separate topic and should be done in another pr/issue. |
|
@eveeifyeve do you need help? Do you know if the Bun v1.4.0 rewrite in Rust would break anything? |
I should be alright, however we can jump in a matrix call about this if you want? I will be home around 10am AEDT.
It helps more than anything. As we can refer some of the type to bun's crates. |
There was a problem hiding this comment.
Would it be wise to move all this upstream to pkgs/build-support/node instead of a folder in bun?
There was a problem hiding this comment.
While I can't say anything authoritatively, the yarn hooks are a relatively new addition that ended up there. You might be able to find more information by looking at the PR history for them.
|
in addition to bun's offline deps support the new v1.4.4 has a cache pack/unpack command which may solve some of the hash-churn issues |
Co-authored-by: Winter <[email protected]> Co-authored-by: Seth Flynn <[email protected]> Co-authored-by: kuflierl <[email protected]> Assisted-by: qwen/qwen3-coder-30b-a3b-instruct Assisted-by: z-ai/glm-5.3-flash
There was a problem hiding this comment.
Thanks for contributing to the documentation.
Follow the documentation style guide, especially:
- Show, don’t tell. Start with a minimal working example. Explain after the code.
- Avoid meta-commentary. Don’t write "This section explains how to…".
- Use present tense, imperative mood, and active voice. For example: "Run the command," not "The user should run the following command."
- Avoid vague references like "this" when the referent is unclear. Write "This command creates a folder," not "This will create a folder."
- Be direct. Avoid "should", "might", "typically", and "usually".
- Cut filler words like "simply", "just", "easily", and "basically". Use "to" instead of "in order to".
For larger changes, such as adding or removing whole sections, ask the NixOS documentation team for review.
The problem still occurs when you update bun. |
I had an AI figure this out for one of my projects a while back. Using bun v1.4.4, and the
the pack/unpack round-trip makes the dependencies byte-reproducible the sanitizer rewrites the symlinks to be relative paths instead: i had the same AI extract it from my personal project and make a small POC using opencode's dependency tree not sure how this fits into the existing work, but i figured i would share a POC for at least the dependency reprod part this does require bun 1.4.4 for the |
DuskyElf
left a comment
There was a problem hiding this comment.
Reviewed head 4029d42. I did not build this locally. The PR is a draft, doc/redirects.json conflicts with master, and the current nixpkgs run fails Eval on all three systems at the merge commit, so there is no clean build signal yet.
The main thing I would fix first is the split between the fetcher and the hook. prefetch-bun-deps writes an npm registry mirror (<package>/manifest.json plus <package>/-/<tarball>). bunConfigHook copies that tree into BUN_INSTALL_CACHE_DIR and runs bun install --offline. Bun's cache holds extracted name@version directories, not packuments (global cache docs). The HTTP server that could serve the mirror is in src/main.rs (handle_connection and route), but TcpListener is only imported and no listener is started. The two halves do not connect. The bun pm cache pack and unpack route in the latest comment could replace much of this custom fetcher.
Smaller findings:
bun-config-hook.shrunspatchShebangs node_modules/{*,.*}. Bash expands.*to.and.., so this also patches the whole source tree one level up.src/main.rsacceptssha384-integrity strings inintegrity(), butverify_sri()handles only sha512 and sha1. A sha384 lockfile entry fails late with "unsupported SRI algorithm".hooks/default.nixpassesbunInstallFlags,preBunInstall,osandcputhroughfetchDeps, but the fetcher only runsprefetch-bun-deps. The docs claimpreBunInstallruns in both hooks, which is not true.--shamefully-hoistin the docs is a pnpm flag.hooks/default.nixpropagatesprefetch-bun-depsfromconfigHook, so every package using bun builds a Rust binary it never runs. Only the fetcher needs it.opencode/package.nixandopencode-desktop/package.nixstill havehash = ""; Nix reports a hash mismatch until those are filled in.
I can look again once the conflict and hashes are settled.
There was a problem hiding this comment.
Some small tweaks I noticed.
Regarding cache pm, I can say from experience with bun2nix that if you use a custom program to manipulate the cache, you should be prepared for it to break on updates and require fixing relatively often. If the cache pm commands work then those would likely be less of a maintenance burden. The only downside I can see is that if upstream breaks those commands, there may not be an easy fix/it may require blocking a bun update till a further release or something like that.
Edit to prevent pings: As long as you're good with the maintenance required it's a non issue as far as I'm concerned, just wanted to give my 2c
|
|
||
| bunDeps = bun.fetchDeps { | ||
| inherit (finalAttrs) pname version src; | ||
| hash = "..."; # clear this and generate a new one |
There was a problem hiding this comment.
If this is left completely empty, shouldn't nix assume a fake hash? Or does that only apply to certain fetchers?
There was a problem hiding this comment.
If this is left completely empty, shouldn't nix assume a fake hash? Or does that only apply to certain fetchers?
I'm pretty certain that some fetchers require one to provide fake hash because they don't assume that for an empty field.
| If you require changing a Bun configuration setting (such as `--dry-run` or similar), | ||
| set `preBunInstall` to the right commands to run. For example: | ||
|
|
||
| ```nix | ||
| { | ||
| preBunInstall = '' | ||
| --dry-run | ||
| ''; | ||
| bunDeps = bun.fetchDeps { | ||
| inherit (finalAttrs) preBunInstall; | ||
| #... | ||
| }; | ||
| } | ||
| ``` | ||
|
|
||
| In this example, `preBunInstall` will be run by both `bun.configHook` and by the `bun.fetchDeps` builder. | ||
|
|
There was a problem hiding this comment.
This seems weird to me. preBunInstall sounds like it's defining an entire phase, not arguments passed to specific commands. Shouldn't this be named something else and utilize __structuredattrs?
There was a problem hiding this comment.
Using convention from other packages, this could be something like extraBunFlags?
The application i bundle with the |
It's not that there is a chance for it upon a new bun release to become reproducible and invalidate the cache, see #376299 (comment) for more info. |
Adds
bun.fetchDeps&bun.configHookto bun and updates bun to 1.2.Blocked by Mic92/nix-update#557 for nix-update-script's.
This pr will lead up to the building bun from source.
NOTE: If you have something to say in this pr please think about if it's spam, off-topic, has already been said (which may have a comment about why I have resolved it) or would be preferred to be a message in matrix, before commenting as this pr. As this pr is becoming big with a lot of people subscribed and I am trying to keep it organized, maintained and not ping heavy.
All related issues that it closes:
closes #335534
closes #255890
closes #414837
closes #424038
This work is semi sponsored by DigitalBrewStudios.
Things done
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.