Replit does not support Dockerfiles directly. Instead, it uses Nix for environment customization through two files: replit.nix for system-level packages and .replit for runtime configuration. You add system dependencies like ffmpeg, ImageMagick, or specific language versions by listing them in replit.nix, and configure run commands, ports, and environment variables in .replit. This gives you Docker-like environment control without writing Dockerfiles.
Customize Your Replit Environment with Nix Instead of Docker
This tutorial explains how to create tailored development environments in Replit using Nix, which replaces Docker as the system-level package manager. You will learn to edit replit.nix to add system dependencies, configure .replit for custom run commands and environment variables, and troubleshoot common Nix errors. This guide is for developers who need specific system packages, language versions, or build tools that are not included in Replit's default environment.
Prerequisites
- A Replit account (any plan)
- A Replit App where you need custom system packages
- Basic understanding of what system-level dependencies are (compilers, libraries, CLI tools)
- Familiarity with the Replit workspace (file tree, Shell, Run button)
- No prior Nix experience required
Step-by-step guide
Reveal hidden configuration files
Reveal hidden configuration files
The replit.nix and .replit files are hidden by default in the file tree. Click the three-dot menu (vertical dots) at the top of the file tree panel and select 'Show hidden files.' You should now see .replit and replit.nix in your project root alongside your source code. If replit.nix does not exist yet, you will create it in the next step. The .replit file should already exist with basic configuration.
Expected result: Hidden files are visible in the file tree. You can see .replit and potentially replit.nix in the project root.
Create or edit replit.nix to add system packages
Create or edit replit.nix to add system packages
The replit.nix file defines which system-level packages are available in your environment. This is equivalent to the RUN apt-get install lines in a Dockerfile. Open replit.nix (or create it if it does not exist) and define a deps array listing the packages you need. Each package uses the pkgs. prefix followed by the Nix package name. Search for available packages at search.nixos.org/packages to find the exact names. Common packages include language runtimes, database clients, image processing tools, and build compilers.
1{ pkgs }: {2 deps = [3 pkgs.nodejs-20_x4 pkgs.python3115 pkgs.ffmpeg6 pkgs.imagemagick7 pkgs.postgresql_168 pkgs.redis9 pkgs.curl10 pkgs.jq11 ];12}Expected result: The replit.nix file is saved with your package list. The packages are not installed yet; that happens when you restart the Shell.
Reload the Nix environment
Reload the Nix environment
After modifying replit.nix, you need to restart the Shell for Nix to pick up the changes and install the new packages. Type 'exit' in the Shell tab and press Enter. Replit will close the current Shell session, rebuild the Nix environment with your new packages, and open a fresh Shell. This process can take 30 seconds to several minutes depending on how many packages you added. Watch the Shell output for any error messages during the rebuild.
1# Type this in Shell to restart and rebuild the Nix environment:2exitExpected result: The Shell restarts and the new packages are available. You can verify by running the package commands, such as 'ffmpeg --version' or 'python3 --version'.
Configure the .replit file for custom runtime behavior
Configure the .replit file for custom runtime behavior
The .replit file controls how your app runs, similar to a docker-compose.yml file. Open .replit and configure the entrypoint, run command, deployment settings, port mappings, and environment variables. The run command executes when you click the Run button. You can chain multiple commands with && or run multiple processes with & and wait. Environment variables can be set under [run.env] for development or in Secrets for sensitive values.
1entrypoint = "src/main.py"2run = "pip install -r requirements.txt && python src/main.py"34[nix]5channel = "stable-24_05"67[run.env]8PYTHONPATH = "${REPL_HOME}/src"9FLASK_ENV = "development"1011[deployment]12run = ["sh", "-c", "python src/main.py"]13build = ["sh", "-c", "pip install -r requirements.txt"]14deploymentTarget = "cloudrun"1516[[ports]]17localPort = 500018externalPort = 801920hidden = [".config", "__pycache__", ".git", "venv"]Expected result: Pressing Run executes your custom command chain. The environment variables are available in your application. The Preview pane shows your app on the configured port.
Add packages via the quick Nix shortcut in .replit
Add packages via the quick Nix shortcut in .replit
For simple package additions, you can skip editing replit.nix entirely and use the [nix] packages shortcut in your .replit file. This is faster for adding one or two packages but does not support advanced Nix expressions. List packages under [nix] packages as an array of strings. This approach and replit.nix are complementary; packages from both sources are installed.
1[nix]2channel = "stable-24_05"3packages = ["cowsay", "htop", "tree"]Expected result: After restarting Shell with 'exit,' the quick-added packages are available. Run 'cowsay hello' or 'htop' to verify.
Run multiple processes simultaneously
Run multiple processes simultaneously
Docker Compose often runs multiple services (server, worker, database) together. In Replit, you can achieve the same by using a compound run command in .replit. Use the & operator to run processes in the background and 'wait' to keep the main process alive. This is useful for running a frontend dev server alongside a backend API, or an application alongside a background worker.
1# Run a Flask API and a React frontend simultaneously2run = "python api/server.py & cd frontend && npm start & wait"Expected result: Both processes start when you click Run. The Console shows output from all processes interleaved. You can access each process on its configured port.
Troubleshoot common Nix errors
Troubleshoot common Nix errors
The most common Nix error is 'nix error: building nix env: exit status 1,' often with output trimmed to the last 20 lines. This usually means a package name is wrong, the Nix channel is too old for the requested package, or an unfree package is being used without being enabled. To debug, check the error output in Shell, verify package names at search.nixos.org/packages, try updating the channel in .replit, and look for diagnostic info by running 'cat /run/replit/env/error' in Shell.
1# Diagnose Nix environment errors2cat /run/replit/env/error34# Check which Nix packages are currently installed5nix-env -q67# Search for a package name locally8nix-env -qaP | grep -i ffmpegExpected result: You can identify the root cause of Nix build failures and fix them by correcting package names, updating the channel, or finding alternative packages.
Complete working example
1# replit.nix - System-level environment configuration2# This is Replit's equivalent of a Dockerfile for system packages.3# Search for packages at: https://search.nixos.org/packages45{ pkgs }: {6 deps = [7 # Language runtimes8 pkgs.nodejs-20_x9 pkgs.python31110 pkgs.python311Packages.pip1112 # Language tools13 pkgs.nodePackages.typescript-language-server14 pkgs.nodePackages.prettier1516 # Database clients17 pkgs.postgresql_161819 # Media processing20 pkgs.ffmpeg21 pkgs.imagemagick2223 # Build tools24 pkgs.gcc25 pkgs.gnumake26 pkgs.pkg-config2728 # CLI utilities29 pkgs.curl30 pkgs.jq31 pkgs.tree32 pkgs.htop3334 # Native library dependencies35 # (needed by some npm packages with native bindings)36 pkgs.libuuid37 pkgs.zlib38 ];39}Common mistakes when using Docker with Replit
Why it's a problem: Using wrong package names (e.g., pkgs.nodejs instead of pkgs.nodejs-20_x)
How to avoid: Search for the exact package name at search.nixos.org/packages. Nix package names follow specific conventions that differ from apt or brew.
Why it's a problem: Forgetting to restart Shell after editing replit.nix
How to avoid: Type 'exit' in Shell and press Enter after every change to replit.nix. The environment only rebuilds on Shell restart.
Why it's a problem: Using an outdated Nix channel that does not include newer packages
How to avoid: Update the channel in .replit to a recent stable version like 'stable-24_05'. Older channels may not have newer package versions available.
Why it's a problem: Installing too many large packages and running out of storage
How to avoid: Check your storage usage in the Resources panel. Remove packages you do not need. Starter plans have only 2 GiB, which fills quickly with large packages.
Why it's a problem: Trying to use a Dockerfile or docker-compose.yml in Replit
How to avoid: Replit does not support Docker. Translate your Dockerfile's apt-get install commands to Nix package equivalents in replit.nix, and your CMD/ENTRYPOINT to the run command in .replit.
Best practices
- Always verify Nix package names at search.nixos.org/packages before adding them to replit.nix
- Use a stable Nix channel (like stable-24_05) rather than unstable to avoid breaking changes
- Run 'exit' in Shell after every replit.nix change to rebuild the environment
- Keep replit.nix lean with only the packages you actually need since they count against storage quota
- Use the .replit [nix] packages shortcut for quick one-off CLI tools and replit.nix for complex dependencies
- Set non-sensitive environment variables in [run.env] in .replit and sensitive ones in Tools > Secrets
- Run 'cat /run/replit/env/error' to diagnose Nix build failures when error output is truncated
- Test your Nix configuration changes in development before deploying, as the same environment applies in production
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I need to set up a Replit environment that has Node.js 20, Python 3.11, ffmpeg for video processing, and PostgreSQL. In Docker I would write a Dockerfile, but Replit uses Nix. Help me create the replit.nix and .replit configuration files with the correct package names.
Configure the replit.nix file for this project. I need the following system packages: Node.js 20, ffmpeg, ImageMagick, and the PostgreSQL client. Also update .replit to set the correct run command and add a [run.env] section with NODE_ENV=development.
Frequently asked questions
No. Replit does not support Docker or Dockerfiles. Instead, use replit.nix for system-level packages and .replit for runtime configuration. The replit.nix file serves a similar purpose to the RUN commands in a Dockerfile.
Nix is a package manager that creates reproducible, isolated environments. Replit uses it because it allows deterministic builds where every user gets the exact same system packages, regardless of when they run the project. This is similar to Docker's reproducibility but integrated directly into the Replit platform.
Search for packages at search.nixos.org/packages. Enter the tool name (like 'ffmpeg' or 'nodejs') and the search results show the exact Nix package name to use in your replit.nix file. Always use the pkgs. prefix when adding packages.
Yes. Nix packages consume storage from your plan's allocation. However, Replit maintains a large pre-built cache of common packages that installs faster and may not count fully against quota. Check the Resources panel for current storage usage.
No. Replit does not provide root or sudo access. You install system packages through replit.nix, not through apt-get or yum. This is a security restriction of the platform.
Most popular packages are available in the Nix repository. If a package truly does not exist, you can compile it from source in your project directory using Shell commands, or look for an alternative package that provides similar functionality.
Yes. The RapidDev engineering team can help configure Nix environments for projects with complex system dependencies, native binary requirements, or multi-language stacks that require careful package coordination.
Yes. The same replit.nix packages are available in your deployed environment. The build and run commands in the [deployment] section of .replit use the same Nix-provided tools and packages.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation