![]() 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 = '' 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. 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)' 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. ![]() 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. ![]() 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. If you encounter problems with libpq-fe.h when bundling, install libpq-dev: sudo install libpq-devĬhange your projects config/database.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 Restart postgres so that the changes are applied: sudo systemctl restart postgresql More info in postgres docs Show snapshot # "local" is for Unix domain socket connections only Open file /etc/postgresql/12/main/pg_hba.conf and change to following lines to trust: Copy # Database administrative login by Unix domain socket This will fix fe_sendauth: no password supplied errors. # defaults to 'localhost' use '*' for allĮdit pg_hba.conf to trust all local connections. Ensure that listen is restricted to localhost: Copy #listen_addresses = 'localhost' # what IP address(es) to listen on Postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | Ĭheck /etc/postgresql/12/main/nf. Postgres=# CREATE USER judith WITH createdb superuser More info in the postgres docs Show snapshotĬheck that the command succeeded by listing the users known to postgres: \duĪll together: Copy ~ >sudo -u postgres psql Start the postgres console as postgres user so you can add a user with your linux' user name: sudo -u postgres psqlĬreate a user with the same username as your linux user and the right to create databases: postgres=# CREATE USER judith WITH createdb superuser ![]() Install Postgres: sudo apt install postgresql
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |