Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nix environment deployment with built-in gems installation #5342

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ GEM
method_source (1.0.0)
mini_magick (4.11.0)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.20.0)
multi_xml (0.6.0)
multipart-post (2.3.0)
Expand All @@ -296,6 +297,9 @@ GEM
net-smtp (0.4.0)
net-protocol
nio4r (2.5.9)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-darwin)
Expand Down Expand Up @@ -516,6 +520,7 @@ PLATFORMS
arm64-darwin-20
arm64-darwin-21
arm64-darwin-22
ruby
x86_64-darwin-18
x86_64-darwin-19
x86_64-darwin-20
Expand Down Expand Up @@ -604,4 +609,4 @@ RUBY VERSION
ruby 3.2.2p53

BUNDLED WITH
2.4.8
2.4.19
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,20 @@ The complete [role description of a CASA volunteer](https://pgcasa.org/volunteer

**Nix**

If you have [Nix](https://nixos.org) installed you can use
the [flake.nix](flake.nix) configuration file located at the root of the
project to build and develop within an environment without needing to install
`rvm`, `nodejs`, `yarn` or other tools separately. All you need is this file
to get the server up and running:
If you have [Nix](https://nixos.org) installed you can use the [flake.nix](flake.nix)
configuration file located at the root of the project to build and develop within an environment
without needing to install `rvm`, `nodejs`, `yarn`, `postgresql` or other tools separately.
The environment also uses the `gemset.nix` file to automatically download and install all the gems
necessary to get the server up and running:

1. Install [Nix](https://zero-to-nix.com/concepts/nix-installer)
1. `cd` into casa
1. `nix develop`
1. `bundix` # to generate a a Gemfile lock that nix can understand
1. `bundle install`
2. Add the following to `~/.config/nix/nix.conf` or `/etc/nix/nix.conf`:
```
experimental-features = nix-command flakes
```
3. `cd` into casa
4. `nix-shell -p bundix --run "bundix -l"` to update the `gemset.nix` file
5. `nix develop` and wait for the packages to be downloaded and the environment to be built

Then you can setup the database and run the server.
This will run on Linux and macOS.
Expand Down
6 changes: 5 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
gemset =
if builtins.pathExists ./gemset.nix then import ./gemset.nix else { };

gemConfig = { };
# See available versions here: https://github.com/bobvanderlinden/nixpkgs-ruby/blob/master/ruby/versions.json
ruby = pkgs."ruby-3.2.2";

Expand All @@ -52,7 +53,7 @@
devShells = rec {
default = dev;
dev = pkgs.mkShell {
BUNDLE_PATH = "~/.gems";
BUNDLE_FORCE_RUBY_PLATFORM = "true";
shellHook = ''
export PS1='\n\[\033[1;34m\][💎:\w]\$\[\033[0m\] '

Expand All @@ -72,10 +73,13 @@
then
pg_ctl start -l $PGLOG -o "--unix_socket_directories='$PGHOST'"
fi

trap 'pg_ctl stop -D "$PGDATA" -s -m fast' EXIT
'';

buildInputs = [
env
bundixcli
pkgs.bundix
pkgs.bundler-audit
pkgs.direnv
Expand Down
Loading