![pg postgres app rails pg postgres app rails](http://cdn-ak.f.st-hatena.com/images/fotolife/y/yuum3/20140806/20140806111148.png)
To make things slightly more interesting, I decided to create the canonical simple Rails "blog" app using the rails generate scaffold command: nix-shell> rails generate scaffold post title:string content:text Rails development environmentīy this stage, the nix-shell Rails development environment was pretty much ready to go. I set the database server up with minimal security to make it easy to access from psql and so the generated database.yml would just work out of the box. Pg_ctl start -l $PGLOG -o "-unix_socket_directories='$PGHOST'" Initdb -auth=trust -no-locale -encoding=UTF8 To this end I added a shellHook to shell.nix to idempotently configure the server and start it when entering the nix-shell: shellHook = ''
![pg postgres app rails pg postgres app rails](https://miro.medium.com/max/552/1*cogHbdu8ZdzWCFNIYNXOjw.png)
I wanted a PostgreSQL database server to be available, but only from within the nix-shell, i.e. the libxml2 OS package was automatically installed just because nokogiri was in the bundled gems! PostgreSQL server Running the "inner" nix-shell for the first time resulted in the bundled gems and their OS dependencies being installed along with runtime dependencies mentioned above.
Pg postgres app rails how to#
I used the Nix multi-user installation instructions to write an inline provisioning script in the Vagrantfile and I even worked out how to make the script idempotent: nix -versionĮcho 'nix is already installed (skipping installation)'
Pg postgres app rails install#
Installing Nixįirst I had to install Nix on the Ubuntu VM. I found this a really productive way to tackle the problem. By doing it this way, I could easily snapshot the VM and restore the snapshot or even destroy the VM and build it again to get back to a clean slate.
![pg postgres app rails pg postgres app rails](https://miro.medium.com/proxy/1*xAakOOVDJobs40zEK819aw.jpeg)
So this time I decided to setup a completely seperate VM running Ubuntu Xenial (with minimal OS packages) using Vagrant to continue with my Nix experiments.įurthermore I decided to try to write a provisioning script for the Vagrant configuration to create a new Rails app from scratch and to complete all the steps necessary for getting both the Rails tests and the Rails server running.
Pg postgres app rails full#
Previously, in order to ensure full isolation, I ended up editing my "dot" files and even modifying environment variables in the current shell, but this was fiddly and error prone. However, in my second attempt where I set up a simple Rails development environment, I wasn't so careful and I didn't do the same checks on the run-time dependencies. In particular, I noticed that unless I specifically added nodejs to the list of buildInputs, middleman ended up using the Node version in the underlying MacOS environment. In my first attempt at setting up a simple Ruby development environment, I was quite careful to make sure the Nix shell environment wasn't accidentally relying on anything available from the underlying environment. Projects Generating and running a Rails app with PostgreSQL using Nix on Ubuntu Isolating a Nix environment by running on an Ubuntu VM provisioned by Vagrant