Every new repl comes with a .replit
and a replit.nix
file that let you configure your repl to do just about anything in any language!
replit.nix
Every new repl is now a Nix repl, which means you can install any package available on Nix, and support any number of languages in a single repl. You can search for a list of available packages here.
The replit.nix
file should look something like the example below. The deps
array specifies which Nix packages you would like to be available in your environment.
{ pkgs }: {
deps = [
pkgs.cowsay
];
}
If you'd like to learn more about Nix, here are some great resources:
.replit
The .replit
file allows you to configure many options for your repl, most basic of which is the run
command.
Check out how to use the .replit
file to configure a repl to enable Clojure:
.replit
files follow the toml configuration format and look something like this:
# The command that is executed when the run button is clicked.
run = ["cargo", "run"]
# The default file opened in the editor.
entrypoint = "src/main.rs"
# Setting environment variables
[env]
FOO="foo"
# Packager configuration for the Universal Package Manager
# See https://github.com/replit/upm for supported languages.
[packager]
language = "rust"
[packager.features]
# Enables the package search sidebar
packageSearch = true
# Enabled package guessing
guessImports = false
# Per language configuration: language.<lang name>
[languages.rust]
# The glob pattern to match files for this programming language
pattern = "**/*.rs"
# LSP configuration for code intelligence
[languages.rust.languageServer]
start = ["rust-analyzer"]
In the code above, the strings in the array assigned to run
are executed in order in the shell whenever you hit the "Run" button.
The language
configuration option helps the IDE understand how to provide features like packaging and code intelligence.
And the [languages.rust]
pattern
option is configured so that all files ending with .rs
are treated as Rust files. The name is user-defined and doesn't have any special meaning, we could have used [languages.rs]
instead.
We can now set up a language server specifically for Rust. Which is what we do with the next configuration option: [languages.rust.languageServer]
. Language servers add smart features to your editor like code intelligence, go-to-definition, and documentation on hover.
Since repls are fully configurable, you're not limited to just one language. For example, you could install Clojure and its language server using replit.nix
, add a [languages.clojure]
configuration option to the above .replit
file that matched all Clojure files and have code intelligence enabled for both languages in the same repl.
.replit
referenceA Command
can either be a string or a list of strings. If the Command
is a string ("node index.js"
), it will be executed via sh -c "<Command>"
. If the Command is a list of strings (["node", "index.js"]
), it will be directly executed with the list of strings passed as arguments. When possible, it is preferred to pass a list of strings.
run
Command
entrypoint
string
onBoot
Command
compile
Command
run
command. Only for compiled languages like C, C++, and Java.audio
boolean
true
.language
string
[env]
VIRTUAL_ENV = "/home/runner/${REPL_SLUG}/venv"
interpreter
command
[string]
run
command (i.e. interpreter
command will run instead of the run
command).prompt
[byte]
[0xEE, 0xA7]
.[unitTest]
language
string
java
, python
, and nodejs
.[packager]
afterInstall
Command
ignoredPaths
[string]
ignoredPackages
[string]
language
string
[packager.features]
packageSearch
true
, enables a package search panel in the sidebar.guessImports
true
, UPM will attempt to guess which packages need to be installed prior to running the repl.[languages.<language name>]
pattern
string
**/*.js
)syntax
string
[languages.<language name>.languageServer]
start
Command
[nix]
channel
string
[debugger]