Use Nix with Node@v20 & [email protected] in nixpacks.toml and railway.toml
Hi! 👋 I'm trying to configure a Node.js project with Nix on Railway. I have both
railway.toml
and nixpacks.toml
files set up, but I'm not sure if I'm correctly defining the Nix config path. Here's my current setup:
railway.toml:
nixpacks.toml:
Is this the correct way to specify the Nix configuration path in railway.toml
? And is my nixpacks.toml
set up correctly for a Node.js/Yarn project? Any guidance would be appreciated! 🙏
---
P.S. I already read https://docs.railway.app/guides/config-as-code62 Replies
Project ID:
cba0b597-8dda-49ec-abd1-d50886e024be
cba0b597-8dda-49ec-abd1-d50886e024be
Railway logs:
Hello,
yes
nixpacksConfigPath
is correct, but its also redundant since that is the default value.
You also cant set environment variables in a railway.toml file, you would want to set them on your service in the UI.
nodejs@20
is not a valid package.
nixPkgs = ['nodejs@20', 'yarn']
is not needed, node 20 will be used automatically if your engines.node
field in the package.json specifies it, and yarn will be used if you have a yarn lock file.
Corepack will install the set version of yarn for you if you have it set in the packageManager
field in the package.json
Doesn't do anything
You already set this in your railway.toml
-
with all that said -
- set the engines.node
field in your package.json to 20
- set the packageManager
field in your package.json to [email protected]
- remove the nixpacks.toml file, it is redundant in this context.
- set the needed variables in the service variables tab.
- use this railway.toml file -
How can I split
railway.toml
for different apps of my monorepo (like web and server)?
The docs recommend to use railway.toml
in root directory, I was thinking to put in apps/web/
and apps/server
Thanks Bordy for the detailed explanation!!
With your suggestion, I got this:
My settings:
isolated or shared monorepo?
do you not have a yarn lock file?
I have it. It's already in git
Shared. My root
package.json
looks like:
for shared -- you wouldn't want to be setting a root directly in the service settings
put each railway.toml in the subdirectory though, and then set the location with the
Railway Config File
setting in the service settingsTo my
xiroi-apps/web/package.json
, I added:
Then xiroi-apps/web/railway.toml
is:
Logs error:
P.S. My intention is to use a paid plan of Railway when I launch my web & app.thats great, i hope we can get you up and running, but for that i would greatly appreciate if you made sure to read the information im giving you 🙂
^
Ohhh, it's below Source Repo. I missed the underlined text 😁
No success. This is my "web" service settings:
- Root directory:
/xiroi-apps/web
- Railway config file: xiroi-apps/web/railway.toml
Logs:
you wouldn't want to be setting a root directly in the service settings
hahah I'm little confused. My initial config hadn't the root directory in the Web service.
My current config is Railway Config File
xiroi-apps/web/railway.toml
. I still cannot build it.
*I'm skipping Server service for now.would you mind if i pull your code, it will help me to understand what you have going on
Yeah, no problem. Let me know what you need for that
your permission is sufficient
in all this messing about somehow the providers option got emptied, add node back to it
Initially I deleted it because my (incorrect) Nix config
"npm": "please-use-yarn"
lolGreat Brody!
Everything is building, except for one monorepo package. I'll dig into that one.
The last 1-2 years is quite common to use monorepos. I'd add cases to https://docs.railway.app/tutorials/deploying-a-monorepo for people
easier said than done unfortunately, your issues are incredibly specific to what you have already tried
😅
I didn't know I was unique 😁
your current build command is
yarn build
and your start command is yarn start
shouldnt you be using workspace specific commands?Because
railway.toml
is already in the frontend app (xiroi-apps/web/railway.toml
with package.json's name @xiroi/apps-web
), I guess it runs from the same directory xiroi-apps/web
, instead of yarn workspace @xiroi/apps-web build
that I run from the root directory.your root directory is
/
thus the scripts from the root directory are used.
you want to be in the root directory, but you need to be using workspace specific build and start commandsThat was it.
The build was successful, Brody!
For the deployment, what Railway config do you recommend?
Logs
lemme look
well the deploy failed -
after you fix that, you will need to read this - https://docs.railway.app/guides/fixing-common-errors#application-failed-to-respond
and now you will need this - https://docs.railway.app/guides/public-networking#provider-specific-instructions
Great!
I'm searching where UI library Tamagui breaks
just noticed you are running a dev server via
vite
In /web?
yeah
The first time hosting with Vite.
server
field is for local development, you run it with vite
. preview
fields with vite preview
question, are you fixed on the .toml file, or can we move to a .json file? you would get a much better dx with a railway.json file since it has the schema
we will need to use caddy, ill get you setup, just working out a plan of attack
Ohhh cool, .toml is done.
you got it, give me a few mins and ill come up with a plan to get you running with a production web server
About the Tamagui issue. I can build and run the web locally with
vite preview
on http://localhost:4173
.i dont think we need to worry about that, that error does not appear in the build logs
and its not going to appear in the deploy logs after we only have caddy running
we wont be using most of its features, railway handles https for us, we just need a user friendly http server
A note: my web can work without my server, only needs Supabase (auth) and Powersync (db sync) connections. The rest is a local-first approach.
sounds good
does your frontend depend on another workspace other than
shared-utils-logging
?Ohh, good finding.
"build": "yarn workspace @xiroi/shared-utils-logging build && tsc && vite build"
is a past config. I gonna replace it for tsc && vite build
so is the frontend just depending on types from other packages?
Yes
Pushed the commit about deletion of this
this nixpacks stuff really annoying, how do you feel about a dockerfile?
Very comfortable. nixpacks' packages were really difficult when I experimented with them
No docker compose, only dockerfile?
only Dockerfile, ill write one for you
sorry this is taking so long, got it mostly running but yarn is still running in the background for some reason
put these files in the web folder
you'll also need to change the config file path to use the .json extension now
this going from yarn running caddy, to just caddy when i switched to the dockerfile, ~250mb before
250 mb before? With this new config, it will be smaller and faster to build?
Good job! Now build time reduced from +3min to 2min
yeah faster builds since less nixpacks stuff, and faster deploys, since now the final image basically only contains the caddy binary and your dist folder
you would likely have a better idea than me -
This happened in the localhost and just needed to refresh in a new tab... But apparently not working in production
I mark this ticket as SOLVED. Amazing help, Brody!
Say to the team that you're providing next level support 🪄
thank you, hopefully this support is worth an upgrade to Pro? 🙂
I'll see the demand the first months of the launch next month, and adjust the paid plans accordingly. I'm confidence I can grow with Railway, after exploring many options.
And because it's a consumer web & app, hopefully the demand will high
i wish you the best of luck then!