Guillem
Guillem
Explore posts from servers
RRailway
Created by Guillem on 10/24/2024 in #✋|help
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:
[build]
builder = "nixpacks"
nixpacksConfigPath = "nixpacks.toml"
buildCommand = "yarn workspace @my-app build"
watchPatterns = [
"apps/web/src/**",
"apps/web/vite.config.mts",
"packages/**"
]

[deploy]
startCommand = "yarn workspace @my-app preview"
healthcheckPath = "/"
healthcheckTimeout = 180
restartPolicyType = "ON_FAILURE"
restartPolicyMaxRetries = 3

[environments.staging.services.environment]
NODE_ENV = "production"
VITE_DATABASE_NAME = "database_staging"
VITE_DEBUG_ENABLED = "false"
VITE_HOST_NAME = "https://example.com"
VITE_SYNC_URL = "https://sync.example.com"
VITE_SERVER_HOST_NAME = "https://api.example.com"

[environments.staging.variables]
NODE_VERSION = "20"
YARN_VERSION = "4.3.1"
[build]
builder = "nixpacks"
nixpacksConfigPath = "nixpacks.toml"
buildCommand = "yarn workspace @my-app build"
watchPatterns = [
"apps/web/src/**",
"apps/web/vite.config.mts",
"packages/**"
]

[deploy]
startCommand = "yarn workspace @my-app preview"
healthcheckPath = "/"
healthcheckTimeout = 180
restartPolicyType = "ON_FAILURE"
restartPolicyMaxRetries = 3

[environments.staging.services.environment]
NODE_ENV = "production"
VITE_DATABASE_NAME = "database_staging"
VITE_DEBUG_ENABLED = "false"
VITE_HOST_NAME = "https://example.com"
VITE_SYNC_URL = "https://sync.example.com"
VITE_SERVER_HOST_NAME = "https://api.example.com"

[environments.staging.variables]
NODE_VERSION = "20"
YARN_VERSION = "4.3.1"
nixpacks.toml:
[phases.setup]
nixPkgs = ['nodejs@20', 'yarn']

[variables]
NODE_VERSION = "20"
YARN_VERSION = "4.3.1"

[phases.install]
cmds = [
"corepack enable",
"corepack prepare [email protected] --activate",
"yarn install"
]

[phases.build]
cmds = ["yarn workspace @my-app build"]
[phases.setup]
nixPkgs = ['nodejs@20', 'yarn']

[variables]
NODE_VERSION = "20"
YARN_VERSION = "4.3.1"

[phases.install]
cmds = [
"corepack enable",
"corepack prepare [email protected] --activate",
"yarn install"
]

[phases.build]
cmds = ["yarn workspace @my-app build"]
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-code
86 replies