Nixpacks
Kinsta uses Nixpacks, an open-source project maintained by Railway, to automatically create your application’s container image based on your repository. Nixpacks are scripts that are run when your application is deployed to install dependencies for your application and configure your environment. Nixpacks use less resources and support 20+ languages.
If you currently use Buildpacks or a Dockerfile, you can change this to Nixpacks within the Build environment option in application settings (Settings > Build > Change environment).
Supported languages
Nixpacks supports the following languages:
- Clojure
- Cobol
- Crystal
- C#/.NET
- Dart
- Deno
- Elixir
- F#
- Go
- Haskell
- Java
- Lunatic
- Node.js
- PHP
- Python
- Rust
- Swift
- Scala
- Zig
To use a different language version, set the version in your application’s files.
When using Nixpacks, there usually isn’t a need to choose or add different providers for the build because they are automatically detected. If additional providers are needed for the application, you can define those in a Nixpacks configuration file.
If you want to use a language that is not a supported Nixpacks or buildpacks language, you must use a Dockerfile.
Configure Nixpacks
Some applications require no configuration, but some require specialized commands and options to run, such as:
Environment variables — You may need to set certain environment variables to run your application.
Processes — Kinsta can automatically detect your web process command. You can change this if required, and you can define additional processes.
Processes in a Procfile — You may want to define your processes in a Procfile within your application’s code.
Configure builds
By adding a nixpacks.toml
file to your repository, you can customize the final Docker image generated by Nixpacks. This configuration file allows you to specify additional providers, install extra packages, customize your build commands, override the start command, and even define new build phases, giving you greater control over the build process and the resulting image.
For more information about how to configure the nixpacks.toml
file, refer to Nixpack’s documentation.
Nixpacks binary directories
With Nixpacks, the binary directories may differ from the default binary directories for the application language. The following table shows the binary directories used for some of the most common languages:
Language | Directory |
---|---|
Node.js | /nix/var/nix/profiles/default/bin/node |
Ruby | /nix/var/nix/profiles/default/bin/ruby |
Python | /nix/var/nix/profiles/default/bin/python |
Java | /nix/var/nix/profiles/default/bin/java |
Scala | Scala doesn’t have a specific default binary path like some other compiled languages. When you compile a Scala program, it generates bytecode that runs on the Java Virtual Machine (JVM).
The compiled Scala classes are typically stored in a directory structure that mirrors the package structure of your code. This is similar to how Java classes are organized. By default, when you compile a Scala source file, the compiled .class files will be placed in the same directory as the source code (within a subdirectory structure based on the package declarations). If needed, you can install Scala’s runtime tools using a Dockerfile instead of using a Nixpack. |
PHP | /nix/var/nix/profiles/default/bin/php |
Go | Go doesn’t have a specific default binary path like some other compiled languages. When you compile a Go program, the resulting binary executable is typically placed in the same directory as your source code by default.
If needed, you can install Go’s runtime tools using a Dockerfile instead of using a Nixpack. |
Set a Nixpack’s language version
When you use Nixpacks, if you do not specify a version in your application’s code, the Nixpack will use the latest available version. If you want to use a different language version for your application, you’ll need to set the version in your application’s files or, depending on the language, with an environment variable.
The available methods for setting the version vary by language. Below, we’ve included examples for the most common languages.
Go
To specify your Go version, include the following in your application’s go.mod file:
go 1.18
Java
To specify your Java version, set the NIXPACKS_JDK_VERSION
environment variable and make sure the variable is available during the build process.
If you’re using Gradle, to specify the version, set the NIXPACKS_GRADLE_VERSION
environment variable and make sure the variable is available during the build process.
Node.js
To specify your Node.js version, do one of the following:
Include the following in your application’s package.json file:
"engines": {
"node": "18"
}
Or, set the NIXPACKS_NODE_VERSION
environment variable and make sure the variable is available during the build process.
PHP
To specify your PHP version, include the following in your application’s composer.json file:
{
"require": {
"php": "8.2"
}
}
Python
To specify your Python version, do one of the following:
- Include the following in your application’s runtime.txt file:
python-3.10.6
- Include the following in a .python-version file in your repository:
3.10.6
- Set the
NIXPACKS_PYTHON_VERSION
environment variable and make sure the variable is available during the build process.
Ruby
To specify your Ruby version, include the version in a .ruby-version file in your application, for example:
3.0.6
Scala
To specify your Scala version, include the following in your application’s build.sbt file:
scalaVersion := "3.2.2"