Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ All in one fast & easy-to-use tool. Instead of 1,000 node_modules for develo
curl -fsSL https://bun.sh/install | bash
```

### Nix

There is a `default.nix` file bundled with Bun's source. This could eventually be brought to Nixpkgs, but for now, you can run and install it like any other nix package.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to pass a url to nix? If so, I could get the default.nix package up on bun.sh

Choose a reason for hiding this comment

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

You can build a remote expressions to an extent yeah

https://nixos.org/manual/nix/stable/command-ref/nix-build.html

With nix 3.0 & flakes you can easily do something like

nix build github:Jarred-Summer/bun
There's probably a way to set up a domain name but not played with it


Before using it, change `bun_install` on line 11 to wherever you'd like Bun to store it's cache.

## Benchmarks

**CSS**: [Bun is 14x faster](./bench/hot-module-reloading/css-stress-test) than Next.js at hot reloading CSS. TODO: compare Vite
Expand Down
31 changes: 31 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{ stdenv
, autoPatchelfHook
, fetchurl
, openssl
, unzip
, pkgs
, ... }:
let
version = "0.0.52";
checksum = "88k0RW6/X/CudqExRwnbfzpKcxHJ3BvtvX2dIudqU+A=";
bun_install = "/home/<whatever>/.bun"; # Set this to where you want bun's cache
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to fill this in with the current user's home directory instead of manually editing?

Copy link
Author

Choose a reason for hiding this comment

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

It could be $HOME/.bun, I just forget if that will evaluate to the root's home directory or the user's (since the package might be built with superuser permissions). I'm pretty sure it's the user's though

Choose a reason for hiding this comment

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

getEnv can be used for this, I believe:

Suggested change
bun_install = "/home/<whatever>/.bun"; # Set this to where you want bun's cache
bun_install = "{builtins.getEnv "HOME"}/.bun";

https://nixos.org/manual/nix/stable/expressions/builtins.html#builtins-getEnv

Choose a reason for hiding this comment

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

Just wrap with escaped $ so it evaluates when ran rather than in the build

in stdenv.mkDerivation {
pname = "bun";
version = version;
src = fetchurl {
url = "https://github.com/Jarred-Sumner/bun-releases-for-updater/releases/download/bun-v${version}/bun-linux-x64.zip";
sha256 = checksum;
};
sourceRoot = ".";
unpackCmd = "unzip bun-linux-x64.zip";
dontConfigure = true;
dontBuild = true;
nativeBuildInputs = [ pkgs.makeWrapper autoPatchelfHook ];
buildInputs = [ unzip openssl stdenv.cc.cc.lib ];

installPhase = "install -D ./bun-linux-x64/bun $out/bin/bun";
postInstall = ''
wrapProgram "$out/bin/bun" \
--prefix BUN_INSTALL : ${bun_install}
'';
}