R
Railway7mo ago
Liam

Running a Bun + pnpm Application on Railway

Hi! I have a monorepo where I use pnpm + turborepo for repo & package managment. One of the apps in the repository, a discord bot, uses bun as its runtime, but still uses pnpm for the actual package installation. Any idea how I can go about getting this working w/ nixpacks / railway? Thanks!
Solution:
or just use 1.0.23 on railway, add nixpkgsArchive = 'e99651a836b162b48fbf4195e0c8d3028b6b32a8' below your [phases.setup]
Jump to solution
54 Replies
Percy
Percy7mo ago
Project ID: bc172a5f-caaa-4872-a59d-62201654b4f6
Liam
Liam7mo ago
bc172a5f-caaa-4872-a59d-62201654b4f6
Brody
Brody7mo ago
I'd probably go about writing a custom nixpacks plan for that specific app where I would have a file like bot.nixpacks.toml with all the applicable configurations https://nixpacks.com/docs/configuration/file and then the NIXPACKS_CONFIG_FILE service variable set to name of my nixpacks file so that the custom build plan is only used for the bot services
Liam
Liam7mo ago
Got it, so would I want the nixpacks file to be at the root of the repo?
Brody
Brody7mo ago
correct
Liam
Liam7mo ago
Also, I am new to nixpacks config stuff. Does this seem like a good starting point?
[phases.setup]
nixPkgs = ['...', 'bun']

[phases.build]
cmds = ['pnpm install']

[start]
cmd = 'pnpm run start'
[phases.setup]
nixPkgs = ['...', 'bun']

[phases.build]
cmds = ['pnpm install']

[start]
cmd = 'pnpm run start'
Not really sure how my custom root for the service comes into play here
Liam
Liam7mo ago
No description
Brody
Brody7mo ago
does any of the code in that folder access code outside of that folder? aka a shared monorepo
Liam
Liam7mo ago
Yes, it accesses some shared packages in the /packages/ directory
Brody
Brody7mo ago
yeah looks decent, replace with the applicable bun build and start commands, also add an install phase with the applicable bun command then setting the root directory to what you have would only copy in what's in that set directory meaning your bot code can't import something from directories elsewhere, it would need to be set to the root directory and that's where your custom bot.nixpacks.toml would live
Liam
Liam7mo ago
Got it got it, have went ahead and done that, running into the following error during build:
No description
Brody
Brody7mo ago
I thought you wanted to use bun for the install, build, and start commands, looks like you're still using pnpm there. for your install, build, and start commands in the custom build plan you would need to use commands that run in a set directory, so that for example your install command only installs the packages that the bot app requires
Liam
Liam7mo ago
Yep, sorry for the miscommunication! I am only using bun for a runtime. Currently I now have the service root set as just the root of the monorepo. Are you saying that pnpm install in the root would not work? On my local machine, pnpm handles monorepo stuffs so running pnpm install at root installs for all packages & apps.
Brody
Brody7mo ago
okay only bun for runtime but pnpm for package management, got it! yes pnpm install ran in the root will install all packages for all apps, but we only want to install the packages the bot needs, pnpm provides an applicable flag or argument of some sort to do such a thing but I don't know it off the top of my head
Liam
Liam7mo ago
I can't find the command for chaining multiple packages / apps together in one command, but giving this a shot
[phases.setup]
nixPkgs = ['...', 'bun']

[phases.build]
cmds = ['pnpm install --filter db', 'pnpm install --filter config', 'pnpm install --filter bot']

[start]
cmd = 'pnpm run start --filter bot'
[phases.setup]
nixPkgs = ['...', 'bun']

[phases.build]
cmds = ['pnpm install --filter db', 'pnpm install --filter config', 'pnpm install --filter bot']

[start]
cmd = 'pnpm run start --filter bot'
Want results from more Discord servers?
Add your server