Install nix with
Ensure that you run can run your Rails app with bin/rails
. An example bin/rails has been provided for version 7 Rails.
Place all these files within the root of your Rails app
Open the development workspace with:
nix develop .#devspace -c $SHELL
Build the application:
nix build .#my-rails-app
Run the application:
./result/bin/my-rails-app
Build the Docker image:
docker build -t my-rails-app .
Run the Docker container:
docker run --rm my-rails-app
default.nix
: Defines the build process for your Rails application using Nix. It specifies the build inputs, build commands, and install commands.
flake.nix
: Defines the Nix flake, including inputs (Nixpkgs and flake-utils) and outputs (packages for different systems).
Dockerfile
: Sets up a NixOS environment in a Docker container, installs Nix Flakes, copies your project files, builds your application using the flake, and sets the command to run your application.
By following these steps, you can build and run your Rails application both directly using Nix and within a Docker container.