Skip to content

Commit

Permalink
Merge pull request #695 from ZeusWPI/feature/flake-nix
Browse files Browse the repository at this point in the history
Add Nix flake for devshell
  • Loading branch information
chvp authored Apr 19, 2023
2 parents 4fa161f + e532e9f commit ca53fff
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
In short, Gandalf is a project that does everything that makes organising and managing an event a lot easier for FK-clubs of the University of Ghent. The application is written specifically for the UGent FakulteitenKonvent. It allows students to register for events and it also interacts with the FK-Enrolment database and allows members of student unions to subscribe to member-only events from their clubs.

# Getting started

If you have NixOS or Nix installed, you can use the `flake.nix` to avoid the hassle of installing the right dependencies. Scroll down for more info.

0. Install the prerequisites: ruby 3.0.6, preferably using [asdf](https://asdf-vm.com/), and some system libraries depending on your OS (e.g. imagemagick)
1. Install the ruby dependencies: `bin/bundle`
2. Start up the database, sidekiq and rails server by running `bin/dev`
Expand All @@ -14,6 +17,14 @@ In short, Gandalf is a project that does everything that makes organising and ma

In case you want to start the webserver in your IDE, just run `docker-compose up -d` and start Sidekiq manually (`bundle exec sidekiq`)

## Development using Nix

- Make sure you have [Nix](https://nixos.org/download.html#download-nix) installed.
- Run `nix develop`
- Done! You have everything installed. You can now:
1. Install Ruby dependencies with `gems:refresh`
2. Start EVERYTHING with `server:start`

# Manually adding users to clubs / making users admin

```
Expand Down
85 changes: 85 additions & 0 deletions flake.lock

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

105 changes: 105 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
description = "Gandalf";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
devshell = {
url = "github:chvp/devshell";
inputs = {
flake-utils.follows = "flake-utils";
nixpkgs.follows = "nixpkgs";
};
};
};

outputs = { self, nixpkgs, devshell, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; overlays = [ devshell.overlays.default ]; };
in
{
devShells = rec {
default = gandalf;
gandalf = pkgs.devshell.mkShell {
name = "Gandalf";
imports = [
"${devshell}/extra/language/ruby.nix"
"${devshell}/extra/git/hooks.nix"
];
git.hooks = {
enable = true;
pre-commit = {
text = "bundle exec rubocop";
};
};
packages = with pkgs; [
docker
nodejs
libyaml
imagemagick
];
language.ruby = {
package = pkgs.ruby_3_0;
nativeDeps = [ pkgs.libmysqlclient pkgs.zlib ];
};
env = [
{
name = "DATABASE_ROOT_PASSWORD";
eval = "gandalf";
}
{
name = "TEST_DATABASE_URL";
eval = "mysql2://root:[email protected]:3306/gandalf_test";
}
{
name = "DATABASE_URL";
eval = "mysql2://root:[email protected]:3306/gandalf";
}
];
serviceGroups.server.services = {
rails = {
name = "server";
command = "rails db:prepare && rails s -p 3000";
};
mysql.command = "mysql";
redis.command = "redis-server --port 6379";
sidekiq.command = "bundle exec sidekiq";
};
commands = [
{
name = "gems:refresh";
category = "general commands";
help = "Install dependencies";
command = ''
bundle install
bundle pristine
'';
}
{
name = "mysql";
category = "database";
help = "Start database docker";
command = ''
trap "systemd-run --user docker stop gandalf-db" 0
docker run --name gandalf-db -p 3306:3306 --rm -v gandalf-db-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=$DATABASE_ROOT_PASSWORD mariadb:latest &
wait
'';
}
{
name = "mysql-console";
category = "database";
help = "Open database console";
command = ''
docker exec -i gandalf-db mysql -uroot -p"$DATABASE_ROOT_PASSWORD"
'';
}
{
name = "redis";
package = pkgs.redis;
}
];
};
};
}
);
}

0 comments on commit ca53fff

Please sign in to comment.