Open coretemp opened 5 years ago
Did you trying using bundix?
Working on an existing Rails app is quite straightforward (run bundix
, and then make a trivial shell.nix that uses bundlerEnv
as documented in the manual). However, generating a new one presents a bit of a bootstrapping problem, because how do you get the rails
executable in the first place. The trick is to set up a nix-shell environment for a Gemfile containing just Rails, and then use that to generate the application:
$ mkdir rails_app
$ cd rails_app
$ cat > Gemfile
source "https://rubygems.org"
gem "rails"
$ nix-shell -p bundix --run 'bundix -l'
$ cat > shell.nix
with import <nixpkgs> {};
(bundlerEnv {
name = "rails_app";
gemdir = ./.;
}).env
$ nix-shell --run 'bundle exec rails new . --force --skip-bundle'
$ nix-shell -p bundix --run 'bundix -l'
At this point, running nix-shell
should give you a Nix shell with all the dependencies of your Rails application available, and eg bundle exec rails server
should work.
Great, your instructions work.
It could be automated a bit further and then added to the manual as far as I am concerned.
I'd just created a "hello world" Rails app, which uses the buildRailsApp
defined here.
That buildRailsApp
isn't complete and may lack lots of stuff such as Active Record support, but I'm interested in fulfilling those features if someone needs it, or on the next time I've started working on a Rails project.
Just be careful with given rails command:
bundle exec rails new . --force --skip-bundle
It will fail while attempting rails webpacker:install
automatically.
A better workflow is executing:
bundle exec rails new . --force --skip-bundle --skip-webpack-install
Then, after last bundix -l
, run rails webpacker:install
yourself.
Another problem is if you don't have yarn
installed or you execute with nix-shell --pure
. It is safer and more self-contained if you add yarn to your nix.shell
:
with import <nixpkgs> {};
let
env = bundlerEnv {
name = "rails_app";
gemdir = ./.;
};
in
stdenv.mkDerivation {
name = "rails_app";
buildInputs = [env yarn];
}
Thank you for your contributions. This has been automatically marked as stale because it has had no activity for 180 days. If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity. Here are suggestions that might help resolve this more quickly:
Still important to me
I marked this as stale due to inactivity. → More info
Issue description
There are a lot of outdated GitHub projects on getting rails (in particular the executable named
rails
) to work on NixOS.For instance https://github.com/ebzzry/rails-nix.
However, all of these methods seem to have bitrotted. What is a way to get a simple "hello world" Ruby on Rails running on NixOS?
To make this more actionable, the manual should document how to do so.
Steps to reproduce
Google for "nixos ruby on rails", observe results, test results and see they all fail.
Technical details
18.03 or newer