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

Add nix flake #5198

Merged
merged 3 commits into from
Sep 19, 2023
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ The complete [role description of a CASA volunteer](https://pgcasa.org/volunteer
2. You can ask a [maintainer](https://github.com/rubyforgood/casa/wiki/Who's-who%3F) for permission to make a branch on this repo.
3. You can also [create a fork on GitHub](https://docs.github.com/en/get-started/quickstart/fork-a-repo) and make a pull request from the fork.

**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:

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`

Then you can setup the database and run the server.
This will run on Linux and macOS.

**Ruby**
1. Install a ruby version manager: [rvm](https://rvm.io/) or [rbenv](https://github.com/rbenv/rbenv)
1. when you cd into the project directory, let your version manager install the ruby version in `.ruby-version`. Right now that's Ruby 3.2.2
Expand Down
174 changes: 174 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 97 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
description = "A Ruby dev environment for Casa Development";

nixConfig = {
extra-substituters = "https://nixpkgs-ruby.cachix.org";
extra-trusted-public-keys =
"nixpkgs-ruby.cachix.org-1:vrcdi50fTolOxWCZZkw0jakOnUI1T19oYJ+PRYdK4SM=";
};

inputs = {
nixpkgs.url = "nixpkgs";
ruby-nix = {
url = "github:inscapist/ruby-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
bundix = {
url = "github:inscapist/bundix/main";
inputs.nixpkgs.follows = "nixpkgs";
};
fu.url = "github:numtide/flake-utils";
bob-ruby = {
url = "github:bobvanderlinden/nixpkgs-ruby";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, fu, ruby-nix, bundix, bob-ruby }:
with fu.lib;
eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ bob-ruby.overlays.default ];
};
rubyNix = ruby-nix.lib pkgs;

gemset =
if builtins.pathExists ./gemset.nix then import ./gemset.nix else { };

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

bundixcli = bundix.packages.${system}.default;
in rec {
inherit (rubyNix {
inherit gemset ruby;
name = "ruby-env-casa";
gemConfig = pkgs.defaultGemConfig // gemConfig;
})
env;

devShells = rec {
default = dev;
dev = pkgs.mkShell {
BUNDLE_PATH = "~/.gems";
shellHook = ''
export PS1='\n\[\033[1;34m\][💎:\w]\$\[\033[0m\] '

# Setup postgres database
export PGHOST=$HOME/postgres
export PGDATA=$PGHOST/data
export PGDATABASE=postgres
export PGLOG=$PGHOST/postgres.log

mkdir -p $PGHOST

if [ ! -d $PGDATA ]; then
initdb --auth=trust --no-locale --encoding=UTF8
fi

if ! pg_ctl status
then
pg_ctl start -l $PGLOG -o "--unix_socket_directories='$PGHOST'"
fi
'';

buildInputs = [
env
pkgs.bundix
pkgs.bundler-audit
pkgs.direnv
pkgs.git
pkgs.gnumake
pkgs.libpcap
pkgs.libpqxx
pkgs.libxml2
pkgs.libxslt
pkgs.nodejs-18_x
pkgs.pkg-config
pkgs.postgresql
pkgs.sqlite
pkgs.yarn
];
};
};
});
}
Loading